英文:
how to send json data to splunk HEC or splunk enterprise
问题
我需要从Jenkins流水线发送JSON数据到Splunk。我已经能够生成JSON数据。我在参考这个链接:https://stackoverflow.com/questions/58555219/how-do-i-send-json-files-to-splunk-enterprise-from-java 。
当第5行调用了httppost.setEntity(new StringEntity(eventStr);时,我遇到了一个错误。
请帮忙...
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);
英文:
I need to send JSON data from Jenkins pipeline to Splunk. I am able to make JSON data. I am referring
https://stackoverflow.com/questions/58555219/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);
答案1
得分: 0
我要打赌你的错误信息大致会说“在<行号>行的<字符计数>位置有意外记号”。
你在第5行缺少一些闭括号(在分号之前),而且第2行和第4行似乎需要一些分号。
英文:
I'm gonna wager your error message says something like "unexpected token at <character count> on <line number>
"
You are missing some close parenthesis (before the semicolon) on line 5, and seem to need some semicolons on lines 2 & 4
专注分享java语言的经验与见解,让所有开发者获益!
评论