我首先說我是初學者。我正在設置一個收集一些 JSON 文件的系統,我在 JAVA (Spring 批處理)中解析它們,而我遇到的問題是將這些文件發送到Splunk enterprise 中的HTTP EVENT COLLECTOR (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: ");
1 回答

慕尼黑的夜晚無繁華
TA貢獻1864條經驗 獲得超6個贊
有點不清楚你想做什么。在文中,您說您正在嘗試使用 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);
添加回答
舉報
0/150
提交
取消