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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...