简体   繁体   English

如何在splunk中显示python输出?

[英]How to display python output in splunk?

I am writing a code in python which will run sql select query and return the result. 我在python中编写一个代码,它将运行sql select查询并返回结果。 How do I display the output from python script in Splunk? 如何在Splunk中显示python脚本的输出?

Currently I just have a python script running sql query and have tried importing import splunklib.client as client which fails as [pylint] E0401:Unable to import 'splunklib.client' 目前我只有一个运行sql查询的python脚本,并尝试导入import splunklib.client as client失败,因为[pylint] E0401:Unable to import 'splunklib.client'

Tried this: 试过这个:

import mysql.connector
import splunklib.client as client

#splunk credentials
HOST = "localhost"
PORT = 8089
USERNAME = "admin"
PASSWORD = "yourpassword"

# Connect to splunk and log in 
service = client.connect(
    host=HOST,
    port=PORT,
    username=USERNAME,
    password=PASSWORD)

But it gives an error while importing library 但是在导入库时会出错

I expect the output of python script which will be something like : 我希望python脚本的输出类似于:

   STAGED = 1
   FAILED = 2
   VALIDATED =1

to be displayed in SPLUNK using python script itself. 使用python脚本本身在SPLUNK中显示。

You have to pass this command in commands.conf file. 您必须在commands.conf文件中传递此命令。 In stanza give command name and key value pair pass filename = python filename 在stanza中给出命令名和键值对传递filename = python filename

[commandname] filename = python.py [commandname] filename = python.py

You can more knowledge on docs.splunk about commands.conf file 您可以在docs.splunk上了解有关commands.conf文件的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM