您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“Splunk如何通過rest http導(dǎo)入數(shù)據(jù)”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Splunk如何通過rest http導(dǎo)入數(shù)據(jù)”這篇文章吧。
通過http 接口發(fā)送數(shù)據(jù),http event collector,需要先在splunk新建一個(gè)標(biāo)記。
設(shè)置->數(shù)據(jù)輸入->HTTP 事件收集器->新建標(biāo)記
輸入名稱
選擇索引
得到標(biāo)記值
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\"}}"
發(fā)送成功后會(huì)顯示
{
"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 = '標(biāo)記值'
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
調(diào)用
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導(dǎo)入數(shù)據(jù)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。