Send event data to Splunk in .NET 5.0

  1. You have already enabled the HTTP input endpoint
  2. You have already obtained the HEC(Http Endpoint Connector) token.
  1. Take care of invalid SSL certificates
HttpClientHandler clientHandler = new()
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true
};
var httpClient = new HttpClient(clientHandler);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(“Splunk”, “HEC Token”);//data should send via ‘event’ object
var data = JsonConvert.SerializeObject(new { @event = myData});
var stringContent = new StringContent(data, Encoding.UTF8, “application/json”);
var response = await httpClient.PostAsync(“{schema}://{url}:{port}/services/collector”, stringContent);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vahid Farahmandian

Vahid Farahmandian

Mainly a .Net #developer, sometimes #SQLServer admin, not yet a husband and specifically not a father. My LinkedIn: https://www.linkedin.com/in/vfarahmandian/