为Splunk的任何REST端点创建REST处理程序

问题描述 投票:0回答:1

如何为任何给定的(内置)SPLUNK REST API端点创建持久性(或与此相关的任何一种)REST HANDLER?如何使用PersistentServerConnectionApplication类?

我经历过[[https://gist.github.com/LukeMurphey/238004c8976804a8e79570d22721fd99,但无法弄清楚从哪里开始以及如何制造它。

splunk splunk-sdk
1个回答
0
投票
几年前,James Ervin发表了关于REST处理程序的.conf精彩演讲,https://conf.splunk.com/files/2016/slides/extending-splunks-rest-api-for-fun-and-profit.pdf

可以从https://github.com/jrervin/splunk-rest-examples获得样品代码

詹姆斯的回声示例非常简单。确保您还注意web.confrestmap.conf中必需的附加内容。

import os import sys if sys.platform == "win32": import msvcrt # Binary mode is required for persistent mode on Windows. msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) from splunk.persistconn.application import PersistentServerConnectionApplication class EchoHandler(PersistentServerConnectionApplication): def __init__(self, command_line, command_arg): PersistentServerConnectionApplication.__init__(self) def handle(self, in_string): return {'payload': in_string, # Payload of the request. 'status': 200 # HTTP status code }

建议您仅获取他的应用程序的副本并进行部署,确认其全部正常工作,然后针对您的特定用例进行修改。
© www.soinside.com 2019 - 2024. All rights reserved.