splunk 通过rest http导入数据

使用 HTTP Event Collector

go to Settings > Data inputs > HTTP Event Collector. Then click the Global Settings button in the upper-right corner. 然后enable设置下!

Event Collector Global settings page

然后去add data添加http EC。

Event Collector New token page

在设置里source type选择json。

Event Collector New token input settings page

完成后会给你生成一个token!

使用如下命令导入数据:

curl -k https://<host>:8088/services/collector -H 'Authorization: Splunk <token>' -d '{"sourcetype": "mysourcetype", "event":"Hello, World!"}' 

在上面的配置下,其中xxtest是我建立的HEC名(URL不带event也是可以的!):
curl -k  https://localhost:8088/services/collector/event  -H "Authorization: Splunk E35F7010-B2DC-4061-B2EA-2870FC8EA546" -d '{"event": "hello world bone this is a temp test", "sourcetype": "xxtest"}'

 

You should now see the following response:

{"text":"Success","code":0}

然后去splunk的搜索界面,https://localhost:8000,输入:source=xxtest,可以看到上述数据。

 

补充:

(1)批量导入:

curl -k  https://localhost:8088/services/collector/event -H "Authorization: Splunk B5094A4D-315D-4AE1-B41D-5F9907DCC350" -d '{"event": "ec 12 17:45:01 PEK1000074003 CRON222[22196]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)", "sourcetype": "hec_test"}{"event": "ec 12 17:45:01 PEK1000074003 CRON333[22196]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)", "sourcetype": "hec_test"}'

可以搜到cron222和cron333

 (2)事件为json多字段:

curl -k  https://localhost:8088/services/collector/event -H "Authorization: Splunk B5094A4D-315D-4AE1-B41D-5F9907DCC350" -d '{"event": {"ctime": "2014-11-24 21:13:26.991", "content": " EventText EventText EventText EventText EventText EventText EventText"}, "sourcetype": "hec_test"}' 

 

其他注意事项:我在splunk web里setting里设置了ssl 为true,就是说必须使用ssl才可以访问。可能会对上述操作由影响。

 

参考:

http://dev.splunk.com/view/event-collector/SP-CAAAE7F

https://docs.splunk.com/Documentation/Splunk/6.5.1/Data/UsetheHTTPEventCollector

http://docs.splunk.com/images/7/76/Splunk-6.4.0-zh_CN-Data.pdf 搜索curl可找到相关说明

 

posted @   bonelee  阅读(2872)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示