Splunk Search

python custom script example

disha
Contributor

Hi,
I am very new to python. I need a small example of how to collect splunk search output in python variable. Please suggest.
I explain :
On Splunk I run the search
mysearch|fields new,old
I want to run a python script which print the value of new and old(for example only.I can do extra processing later,just want to learn make this work atleast).
I made the entry in commands.conf for script as
[myscript]
filename = mypyscript.py

and I am calling as
mysearch|fields new,old|script python myscript new old
or I need to call as
mysearch|fields new,old|script python myscript

and myscript will automatically take new and old value?
Also can i get the sample python script for this.
Please help.

Tags (1)
0 Karma

martin_mueller
SplunkTrust
SplunkTrust

You could take a look at $SPLUNK_HOME/etc/apps/search/bin/*.py for inspiration.

Get Updates on the Splunk Community!

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...