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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...