Last active
October 21, 2019 16:46
-
-
Save ChrisMoney/ffad51bfb0114b91228379db688e9821 to your computer and use it in GitHub Desktop.
Log to Splunk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Send a single event to Splunk | |
/// </summary> | |
bool SubmitSingleEventToSplunk(string message, string host, string sourcetype) | |
{ | |
var client = new RestClient(); | |
client.BaseUrl = BuildUrl(); | |
client.Authenticator = new HttpBasicAuthenticator(_username, _password); | |
string getParameters = string.Format("?source={0}&sourcetype={1}&host={2}&index={3}", HttpUtility.UrlEncode(_source), HttpUtility.UrlEncode(sourcetype), | |
HttpUtility.UrlEncode(host), HttpUtility.UrlEncode(_index)); | |
var request = new RestRequest("/services/receivers/simple" + getParameters, Method.POST); | |
byte[] data = Encoding.UTF8.GetBytes(message); | |
request.AddParameter("application/x-www-form-urlencoded", data, ParameterType.RequestBody); | |
client.ExecuteAsync(request, response => { AsyncResponseHandler(response); }); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment