<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do you pass saved search parameters to a Python script? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-do-you-pass-saved-search-parameters-to-a-Python-script/m-p/314843#M4327</link>
    <description>&lt;P&gt;As you might be aware , there will be 9 fields Splunk arguments you can get for alerting purposes&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Alert/Configuringscriptedalerts"&gt;https://docs.splunk.com/Documentation/Splunk/latest/Alert/Configuringscriptedalerts&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For debugging, you could print all these 9 fields out into an output and see if it is useful.  There is a quite old &lt;A href="https://github.com/getkub/DataAlerter/blob/master/bin/splunk_to_tivoli.py"&gt;Splunk to Tivoli script&lt;/A&gt;, you can see if useful.  The &lt;CODE&gt;SPLUNK_ARG_8&lt;/CODE&gt; will give you the file in which the results for the search are stored, which you can stream out using your python script.&lt;/P&gt;

&lt;P&gt;Also are you using Splunk's python to trigger your python script? &lt;/P&gt;</description>
    <pubDate>Sun, 26 May 2019 08:11:33 GMT</pubDate>
    <dc:creator>koshyk</dc:creator>
    <dc:date>2019-05-26T08:11:33Z</dc:date>
    <item>
      <title>How do you pass saved search parameters to a Python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-you-pass-saved-search-parameters-to-a-Python-script/m-p/314841#M4325</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to pass arguments from a savedsearch result to a python script, and it does not work. Code below.&lt;/P&gt;
&lt;P&gt;savedsearches.conf&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;[test_search]
action.log_message = 1
action.log_message.param.name = $name$
action.log_message.param.condition = $result.condition$
action.log_message.param.host = $result.host$
action.log_message.param.source = $result.source$
alert.digest_mode = 0
alert.suppress = 0
alert.track = 1
counttype = number of events
cron_schedule = */1 * * * *
disabled = 1
dispatch.earliest_time = -5m
dispatch.latest_time = now
enableSched = 1
quantity = 0
relation = greater than
request.ui_dispatch_app = search
request.ui_dispatch_view = search
search = index=main host=test_host source=test_source status=* earliest=-2m latest=now | eval condition=if(status!="OK","CRITICAL","OK") | stats last(condition) as condition by host,source
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;alert_actions.conf&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;[log_message]
is_custom = 1
label = test
description = test
icon_path = appIcon.png
alert.execute.cmd = test.py
payload_format = json
disabled = 0
param.name = 
param.condition = 
param.host = 
param.source = 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;test.py&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;#!/bin/python
import json
import sys
import os
import datetime

timestamp = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")

name = config['name']
condition = config['condition']
host = config['host']
source = config['source']

f = open('temp.txt', 'w')
sys.stdout = f
sys.stderr = f
print(host, source, name, condition, timestamp)
f.close()
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And I get no output. If hard code some values in the script directly, then the file will be written every time the script is triggered.&lt;/P&gt;
&lt;P&gt;Expected output&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;('test_host', 'test_source', 'test_search', 'condition' , 'timestamp')
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jun 2020 21:21:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-you-pass-saved-search-parameters-to-a-Python-script/m-p/314841#M4325</guid>
      <dc:creator>andrei1bc</dc:creator>
      <dc:date>2020-06-18T21:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do you pass saved search parameters to a Python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-you-pass-saved-search-parameters-to-a-Python-script/m-p/314842#M4326</link>
      <description>&lt;P&gt;were you able to resolve this? I have similar requirement, need some help.&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2019 06:15:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-you-pass-saved-search-parameters-to-a-Python-script/m-p/314842#M4326</guid>
      <dc:creator>vasanthi77</dc:creator>
      <dc:date>2019-05-26T06:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do you pass saved search parameters to a Python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-you-pass-saved-search-parameters-to-a-Python-script/m-p/314843#M4327</link>
      <description>&lt;P&gt;As you might be aware , there will be 9 fields Splunk arguments you can get for alerting purposes&lt;BR /&gt;
&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/Alert/Configuringscriptedalerts"&gt;https://docs.splunk.com/Documentation/Splunk/latest/Alert/Configuringscriptedalerts&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For debugging, you could print all these 9 fields out into an output and see if it is useful.  There is a quite old &lt;A href="https://github.com/getkub/DataAlerter/blob/master/bin/splunk_to_tivoli.py"&gt;Splunk to Tivoli script&lt;/A&gt;, you can see if useful.  The &lt;CODE&gt;SPLUNK_ARG_8&lt;/CODE&gt; will give you the file in which the results for the search are stored, which you can stream out using your python script.&lt;/P&gt;

&lt;P&gt;Also are you using Splunk's python to trigger your python script? &lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2019 08:11:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-you-pass-saved-search-parameters-to-a-Python-script/m-p/314843#M4327</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2019-05-26T08:11:33Z</dc:date>
    </item>
  </channel>
</rss>

