Splunk Dev

Access arguments to python script

trungnt
New Member

Hi all,

I wrote a small python script to run "a script alert action", I access arguments by this follow guide,
http://docs.splunk.com/Documentation/Splunk/6.2.2/Alert/Configuringscriptedalerts#Access_arguments_t...

My python script is:

#!/usr/bin/python
#
import sys
import serial
import time

tn = sys.argv[4]

print tn

The script is running.

The arguments to scripts have SPLUNK_ARG_0 -> SPLUNK_ARG_8, but I want access other information,
for example: I want to tranfer arguments which is the same tokens $result.fieldname$ in email notifications.

Please help me,

Thank you!

Tags (2)
0 Karma
1 Solution

somesoni2
Revered Legend

The search results are not directly accessible in the alert script but SPLUNK_ARG_8 argument provides the compressed file that contains the search result. Look at this post for a sample wrapper script on how to use 8th argument to pass search results to your script.

https://answers.splunk.com/answers/149836/how-to-run-an-alert-script-on-field-values-generated-in-sp...

View solution in original post

0 Karma

trungnt
New Member

Hi, Somesoni2

Thank you so much for your speedy reply!
It 's working.

0 Karma

somesoni2
Revered Legend

The search results are not directly accessible in the alert script but SPLUNK_ARG_8 argument provides the compressed file that contains the search result. Look at this post for a sample wrapper script on how to use 8th argument to pass search results to your script.

https://answers.splunk.com/answers/149836/how-to-run-an-alert-script-on-field-values-generated-in-sp...

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...