亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從 JAVA 將 JSON 文件發送到 Splunk Enterprise?

如何從 JAVA 將 JSON 文件發送到 Splunk Enterprise?

長風秋雁 2023-12-30 16:14:42
我首先說我是初學者。我正在設置一個收集一些 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);


查看完整回答
反對 回復 2023-12-30
  • 1 回答
  • 0 關注
  • 174 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號