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 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...