<?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: Alerts and scripts with parameters in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17997#M118</link>
    <description>&lt;P&gt;I think the question here is, how to pass our own values (dynamically derived from event) to Script (phython/perl/shell) as command line arguments?&lt;/P&gt;</description>
    <pubDate>Fri, 05 Apr 2013 12:29:05 GMT</pubDate>
    <dc:creator>jayannah</dc:creator>
    <dc:date>2013-04-05T12:29:05Z</dc:date>
    <item>
      <title>Alerts and scripts with parameters</title>
      <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17994#M115</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I am trying to get alerts to call a script with some parameters. I am aware splunk adds 8 or 9 parameters but I would also like to add my own as well which I will change from alert to alert. All alerts will use a common script and it's behaviour will be slightly different depending on the parameters passed.&lt;/P&gt;

&lt;P&gt;The script lives in $SPLUNK_HOME/bin/scripts/ looks like this&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;#!/opt/splunk/bin/python&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;webPath = "/tmp/"&lt;BR /&gt;
fileBasename = "-signal.txt"&lt;/P&gt;

&lt;P&gt;propsalData = "proposal=" + sys.argv[2]&lt;BR /&gt;
outputFilename = webPath + sys.argv[1] + fileBasename&lt;BR /&gt;
output = open(outputFilename,'wb')&lt;BR /&gt;
output.write(propsalData)&lt;BR /&gt;
output.close()&lt;BR /&gt;
&lt;/P&gt;

&lt;P&gt;As you can see the first parameter is prepended to the name of the file to create. The second parameter is put inside the text file.&lt;/P&gt;

&lt;P&gt;For the life of me I can't seem to add these parameters in both the GUI and from a conf file.&lt;/P&gt;

&lt;P&gt;In the GUI I have tried each of these in the script textfield&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;BR /&gt;
create-station-signal-file.py paramTest 34&lt;BR /&gt;
'create-station-signal-file.py paramTest 34'&lt;BR /&gt;
"create-station-signal-file.py paramTest 34"&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;All give an error like below in splunkd.log&lt;BR /&gt;
&lt;PRE&gt;05-27-2011 14:12:24.105 +1000 ERROR script - command="runshellscript", Cannot find script at /opt/splunk/bin/scripts/create-station-signal-file.py paramTest 34&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;When editting in the savedsearches.conf file directly I made them look like this&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE&gt;&lt;BR /&gt;
action.script.filename = create-station-signal-file.py paramTest 34&lt;BR /&gt;
action.script.filename = "create-station-signal-file.py paramTest 34"&lt;BR /&gt;
action.script.filename = 'create-station-signal-file.py paramTest 34'&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;same errors as above.&lt;/P&gt;

&lt;P&gt;Does anyone know if this is possible to pass some parameters in?&lt;/P&gt;

&lt;P&gt;If not thats a real pain as I have to take this one simple script and replicate it 20+ times for each alert. Which is even worse if I decide to modify the script slightly in the future.&lt;/P&gt;

&lt;P&gt;Thoughts?&lt;/P&gt;

&lt;P&gt;Also I did test a simplified no parameters required script and it worked so incase you are thinking python scripts wont work they do &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2011 04:24:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17994#M115</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2011-05-27T04:24:42Z</dc:date>
    </item>
    <item>
      <title>Re: Alerts and scripts with parameters</title>
      <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17995#M116</link>
      <description>&lt;P&gt;I would imagine that Splunk is handling the script as a single quoted name, possibly so that you can have a script with spaces in the name.  I imagine that your desire is to keep the script logic common to everything, and located in a single script -- that could be handled differently: make a small script for each case which simply passes the proper parameters to the main script, and use that script instead e.g.:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;alert1.sh

#!/bin/sh
create-station-signal-file.py paramTest 34
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or you could have the main script contain logic to determine the proper parameters based on the search name or some other value.  Or you could do something in between those: make soft links to the script with different names, and then within the script do something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if sys.argv[0] is 'alert1.py':
  params = ('paramTest', '34')
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 May 2011 12:54:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17995#M116</guid>
      <dc:creator>mw</dc:creator>
      <dc:date>2011-05-29T12:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Alerts and scripts with parameters</title>
      <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17996#M117</link>
      <description>&lt;P&gt;Thanks for the response I was worried you would say that. &lt;/P&gt;

&lt;P&gt;I had thought of the softlink option which would work but would not be ideal&lt;/P&gt;

&lt;P&gt;It's a shame because the scripted inputs behave in this manner. Would be nice if they were consistent &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2011 08:30:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17996#M117</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2011-05-31T08:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Alerts and scripts with parameters</title>
      <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17997#M118</link>
      <description>&lt;P&gt;I think the question here is, how to pass our own values (dynamically derived from event) to Script (phython/perl/shell) as command line arguments?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2013 12:29:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17997#M118</guid>
      <dc:creator>jayannah</dc:creator>
      <dc:date>2013-04-05T12:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Alerts and scripts with parameters</title>
      <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17998#M119</link>
      <description>&lt;P&gt;I was trying to pass in fixed values. Which also seems to be difficult as well&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2013 05:39:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17998#M119</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-05-08T05:39:27Z</dc:date>
    </item>
    <item>
      <title>Re: Alerts and scripts with parameters</title>
      <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17999#M120</link>
      <description>&lt;P&gt;Is there any way where I can send the parameter from the search result?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 07:03:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/17999#M120</guid>
      <dc:creator>SantoshBansode</dc:creator>
      <dc:date>2016-04-25T07:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Alerts and scripts with parameters</title>
      <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/18000#M121</link>
      <description>&lt;P&gt;It's limitation of the Splunk, there is no way to send the parameters.&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 05:27:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/18000#M121</guid>
      <dc:creator>SantoshBansode</dc:creator>
      <dc:date>2016-05-27T05:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Alerts and scripts with parameters</title>
      <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/18001#M122</link>
      <description>&lt;P&gt;Not really.&lt;/P&gt;

&lt;P&gt;Back in the days of this question, the alert script was passed the path of a results .csv.gz, the script could pull anything it wanted from there.&lt;/P&gt;

&lt;P&gt;Nowadays, custom alert actions can receive any parameter you like: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.1/AdvancedDev/ModAlertsIntro"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.1/AdvancedDev/ModAlertsIntro&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2016 09:38:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/18001#M122</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-05-27T09:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Alerts and scripts with parameters</title>
      <link>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/18002#M123</link>
      <description>&lt;P&gt;do you have any practical example? Maybe I am getting old but I do not understand the procedure how to achieve to run final script/batch with something line myscript.bat $result.field1 $result.field2&lt;/P&gt;</description>
      <pubDate>Wed, 10 May 2017 00:31:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Alerts-and-scripts-with-parameters/m-p/18002#M123</guid>
      <dc:creator>rapmancz</dc:creator>
      <dc:date>2017-05-10T00:31:24Z</dc:date>
    </item>
  </channel>
</rss>

