您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“Splunk如何通過rest http導入數據”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“Splunk如何通過rest http導入數據”這篇文章吧。
通過http 接口發送數據,http event collector,需要先在splunk新建一個標記。
設置->數據輸入->HTTP 事件收集器->新建標記
輸入名稱
選擇索引
得到標記值
curl -k https://IP:8088/services/collector/event -H "Authorization: Splunk 9213be6a-2ebc-47bb-9da9-e9c2fa1345f4" -d "{\"host\":\"127.0.0.1\",\"time\":1561144452.611000,\"sourcetype\":\"some_sourcetype\",\"index\":\"sample\",\"event\":{\"eventKey\":\"0\", \"uuid\":\"88b5e9fd-ebe0-4fe1-aeeb-b3d583ec9cfd\",\"message\":\"dnnpfbbwic\"}}{\"time\":1561144552.611000,\"sourcetype\":\"some_sourcetype\",\"index\":\"sample\",\"event\":{\"eventKey\":\"0\", \"uuid\":\"88b5e9fd-ebe0-4fe1-aeeb-b3d583ec9cfd\",\"message\":\"abc\"}}"
發送成功后會顯示
{
"text": "Success",
"code": 0
}
基于Python3的封裝
# coding=utf-8
import urllib
import httplib2
from xml.dom import minidom
import time
import json
import traceback
class SplunkInput(object):
def __init__(self):
self.baseurl = 'https://IP:8088'
self.sessionKey = '標記值'
def submit_job(self, data):
result_response = httplib2.Http(disable_ssl_certificate_validation=True) \
.request(self.baseurl + '/services/collector/event',
'POST',
headers={'Authorization': 'Splunk %s' % self.sessionKey},
body=json.dumps(data))[1]
return result_response
def run(self, data):
start = time.time()
result = self.submit_job(data)
end = time.time()
print("submit time:", end - start)
return result
調用
print(">>>>>>>>>>>>>>SplunkInput>>>>>>>>>>>>>>>>>>>>>>")
hostname = socket.gethostname()
SI = SplunkInput()
s_time = int(time.time())
data = [{
"host": hostname,
"sourcetype": "test",
"index": "sample",
"event": {
"eventKey": "0",
"uuid": "88b5e9fd-ebe0-4fe1-aeeb-b3d583ec9cfd",
"message": "abc"
}
}, {
"host": hostname,
"time": s_time,
"sourcetype": "test",
"index": "sample",
"event": {
"eventKey": "1",
"uuid": "1233444-ebe0-4fe1-aeeb-b3d583ec9cfd",
"message": "def"
}
}]
以上是“Splunk如何通過rest http導入數據”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。