如何将 JSON 文件从 JAVA 发送到 Splunk Enterprise?
How do I send JSON files to Splunk Enterprise from JAVA?
首先我要说我是初学者。
我正在建立一个系统,我在其中收集一些 JSON 文件,我在 JAVA(Spring 批次)中解析它们,而我卡住的部分是将这些文件发送到 Splunk 企业中的 HTTP 事件收集器 (HEC)。我尝试在网上搜索一些对初学者友好的指南,但我找不到任何东西。我想将 POST 连同上述文件一起发送到 Splunk 企业,以便在发送后可以为它们编制索引。
到目前为止,我只能像这样连接到 localhost:8089:
HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
ServiceArgs connectionArgs = new ServiceArgs();
connectionArgs.setHost("localhost");
connectionArgs.setUsername("AdrianAlter");
connectionArgs.setPassword("mypassword");
connectionArgs.setPort(8089);
connectionArgs.put("scheme","https");
// will login and save the session key which gets put in the HTTP Authorization header
Service splunkService = Service.connect(connectionArgs);
System.out.println("Auth Token : " + splunkService.getToken());
Job info = splunkService.getJobs().create("search index=main");
System.out.println("Info: ");
有点不清楚您要做什么。在文本中,您说您正在尝试使用 HTTP 事件收集器 (HEC) 发送数据。但是,示例代码看起来是在尝试执行搜索。
要将数据发送到 Java 中的 HEC 端点,以下代码片段可能是一个合适的起点。
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);
首先我要说我是初学者。 我正在建立一个系统,我在其中收集一些 JSON 文件,我在 JAVA(Spring 批次)中解析它们,而我卡住的部分是将这些文件发送到 Splunk 企业中的 HTTP 事件收集器 (HEC)。我尝试在网上搜索一些对初学者友好的指南,但我找不到任何东西。我想将 POST 连同上述文件一起发送到 Splunk 企业,以便在发送后可以为它们编制索引。 到目前为止,我只能像这样连接到 localhost:8089:
HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
ServiceArgs connectionArgs = new ServiceArgs();
connectionArgs.setHost("localhost");
connectionArgs.setUsername("AdrianAlter");
connectionArgs.setPassword("mypassword");
connectionArgs.setPort(8089);
connectionArgs.put("scheme","https");
// will login and save the session key which gets put in the HTTP Authorization header
Service splunkService = Service.connect(connectionArgs);
System.out.println("Auth Token : " + splunkService.getToken());
Job info = splunkService.getJobs().create("search index=main");
System.out.println("Info: ");
有点不清楚您要做什么。在文本中,您说您正在尝试使用 HTTP 事件收集器 (HEC) 发送数据。但是,示例代码看起来是在尝试执行搜索。
要将数据发送到 Java 中的 HEC 端点,以下代码片段可能是一个合适的起点。
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);