如何为任何给定的(内置)SPLUNK REST API端点创建持久性(或与此相关的任何一种)REST HANDLER?如何使用PersistentServerConnectionApplication类?
我经历过[[https://gist.github.com/LukeMurphey/238004c8976804a8e79570d22721fd99,但无法弄清楚从哪里开始以及如何制造它。
可以从https://github.com/jrervin/splunk-rest-examples获得样品代码
詹姆斯的回声示例非常简单。确保您还注意web.conf
和restmap.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
}
建议您仅获取他的应用程序的副本并进行部署,确认其全部正常工作,然后针对您的特定用例进行修改。