How to send json data to splunk HEC or splunk enterprise?

I need to send JSON data from Jenkins pipeline to Splunk. I am able to make JSON data. I am referring How do I send JSON files to Splunk Enterprise from JAVA? this link. I am getting an error when line no. 5 : httppost.setEntity(new StringEntity(eventStr); has been called . please help…

DefaultHttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("https://<SERVER>:8088/services/collector/event");

httppost.addHeader("Authorization", " Splunk <token id>");

String eventStr = "{sourcetype=_json, index=main, event={ <JSON> }}"

httppost.setEntity(new StringEntity(eventStr);

HttpResponse response = httpclient.execute(httppost);

HttpEntity entity = response.getEntity();

System.out.println("response: " + entity);

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.