All Apps and Add-ons

Refine the output of splunk search result in python

ygkr
New Member

I worked on splunk sdk and got the events for the given search query but I want to display only Priority with their corresponding count value in the console... someone help me in how to do that???

output screenshot has attached.][1]

Here is my python script to print this output:

service = client.connect(
host=HOST,
port=PORT,
username=USERNAME,
password=PASSWORD)

for app in service.apps:
print (app.name)
kwargs_export = {"search_mode": "normal"}
searchquery_export = "search sourcetype=db| stats count by Priority"
exportsearch_results = service.jobs.export(searchquery_export, **kwargs_export)
# Get the results and display them using the ResultsReader
print (exportsearch_results.read())

Tags (1)
0 Karma

sideview
SplunkTrust
SplunkTrust

What is the reason you're using python for this? Maybe you're trying to learn with an extremely simple example of a python script, but in such a simple case you should simply run it in the console with splunk itself.

You can read more about how to use Splunk to run searches on the command line here - http://docs.splunk.com/Documentation/Splunk/6.4.3/SearchReference/CLIsearchsyntax

0 Karma
Get Updates on the Splunk Community!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...