I am writing a code in python which will run sql select query and return the result. How do I display the output from python script in Splunk?
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'
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 :
STAGED = 1
FAILED = 2
VALIDATED =1
to be displayed in SPLUNK using python script itself.
You have to pass this command in commands.conf file. In stanza give command name and key value pair pass filename = python filename
[commandname] filename = python.py
You can more knowledge on docs.splunk about commands.conf file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.