Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save weeksdev/e66f4bf44a98db078681b87644e5d87b to your computer and use it in GitHub Desktop.
Save weeksdev/e66f4bf44a98db078681b87644e5d87b to your computer and use it in GitHub Desktop.
Manual http request to splunk event collector
WebRequest request = WebRequest.Create("https://splunkserver/services/collector");
request.Method = "POST";
request.Headers.Add("Authorization", "Splunk YOUR_GUID");
ASCIIEncoding encoding = new ASCIIEncoding();
var requestBody = JsonConvert.SerializeObject(new
{
@event = new
{
FirstName = "Foo",
LastName = "Bar"
},
host = Environment.MachineName,
source = "YOUR_DIRECTORY"
});
byte[] bytes = encoding.GetBytes(requestBody);
request.ContentLength = bytes.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
var contents = new StreamReader(stream).ReadToEnd();
Console.WriteLine(contents);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment