這篇文章主要為大家展示了“Splunk如何通過rest http導(dǎo)入數(shù)據(jù)”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Splunk如何通過rest http導(dǎo)入數(shù)據(jù)”這篇文章吧。
成都創(chuàng)新互聯(lián)網(wǎng)絡(luò)公司擁有10多年的成都網(wǎng)站開發(fā)建設(shè)經(jīng)驗(yàn),1000+客戶的共同信賴。提供成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、網(wǎng)站開發(fā)、網(wǎng)站定制、外鏈、建網(wǎng)站、網(wǎng)站搭建、成都響應(yīng)式網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)師打造企業(yè)風(fēng)格,提供周到的售前咨詢和貼心的售后服務(wù)
通過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)容對大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!