如何将JSON数据发送到Splunk HEC或Splunk Enterprise。

huangapple 未分类评论50阅读模式
英文:

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(&quot;https://&lt;SERVER&gt;:8088/services/collector/event&quot;);
 httppost.addHeader(&quot;Authorization&quot;, &quot; Splunk &lt;token id&gt;&quot;);
 String eventStr = &quot;{sourcetype=_json, index=main, event={ &lt;JSON&gt; }}&quot;
 httppost.setEntity(new StringEntity(eventStr);
 HttpResponse response = httpclient.execute(httppost);
 HttpEntity entity = response.getEntity();
 System.out.println(&quot;response: &quot; + entity);

答案1

得分: 0

我要打赌你的错误信息大致会说“在<行号>行的<字符计数>位置有意外记号”。

你在第5行缺少一些闭括号(在分号之前),而且第2行和第4行似乎需要一些分号。

英文:

I'm gonna wager your error message says something like "unexpected token at &lt;character count&gt; on &lt;line number&gt;"

You are missing some close parenthesis (before the semicolon) on line 5, and seem to need some semicolons on lines 2 & 4

huangapple
  • 本文由 发表于 2020年5月4日 23:54:28
  • 转载请务必保留本文链接:https://java.coder-hub.com/61596340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定