Skip to content

Instantly share code, notes, and snippets.

@ChrisMoney
Last active October 21, 2019 16:46
Show Gist options
  • Save ChrisMoney/ffad51bfb0114b91228379db688e9821 to your computer and use it in GitHub Desktop.
Save ChrisMoney/ffad51bfb0114b91228379db688e9821 to your computer and use it in GitHub Desktop.
Log to Splunk
/// <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