Splunk如何通过rest http导入数据

发布时间:2022-01-15 11:00:47 作者:小新
来源:亿速云 阅读:164

这篇文章主要为大家展示了“Splunk如何通过rest http导入数据”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Splunk如何通过rest http导入数据”这篇文章吧。

新建标记

通过http 接口发送数据,http event collector,需要先在splunk新建一个标记。

设置->数据输入->HTTP 事件收集器->新建标记

Splunk如何通过rest http导入数据  

输入名称

Splunk如何通过rest http导入数据  

选择索引

Splunk如何通过rest 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导入数据”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. hbase REST API
  2. 什么是REST ?

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

splunk

上一篇:Spring Boot 2.3.3修复了哪些功能

下一篇:springboot整合quartz定时任务框架的方法是什么

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》