<?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 Splunk Alerting : How to pass arguments/filename to your script? in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/Splunk-Alerting-How-to-pass-arguments-filename-to-your-script/m-p/165190#M3637</link>
    <description>&lt;P&gt;Hi&lt;BR /&gt;
I have savedSearch which should alert every 1 min. The searchname is "myApp_Alert_1m" and the file produced is &lt;CODE&gt;"myApp_Alert_1m.csv"&lt;/CODE&gt;. My Script is kept in $SPLUNK_HOME/bin/scripts/myAlert.py&lt;BR /&gt;
So my SavedSearch outputs this file &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; .. | outputcsv myApp_Alert_1m
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I pass this filename as a parameter into "myAlert.py"?&lt;/P&gt;

&lt;P&gt;( I tried putting into Enable Script where it shows "File name of shell script to run" with &lt;SCRIPTNAME&gt; &lt;FILENAME&gt; option, but not getting any output. ) &lt;/FILENAME&gt;&lt;/SCRIPTNAME&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 16:37:19 GMT</pubDate>
    <dc:creator>koshyk</dc:creator>
    <dc:date>2020-09-28T16:37:19Z</dc:date>
    <item>
      <title>Splunk Alerting : How to pass arguments/filename to your script?</title>
      <link>https://community.splunk.com/t5/Reporting/Splunk-Alerting-How-to-pass-arguments-filename-to-your-script/m-p/165190#M3637</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
I have savedSearch which should alert every 1 min. The searchname is "myApp_Alert_1m" and the file produced is &lt;CODE&gt;"myApp_Alert_1m.csv"&lt;/CODE&gt;. My Script is kept in $SPLUNK_HOME/bin/scripts/myAlert.py&lt;BR /&gt;
So my SavedSearch outputs this file &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; .. | outputcsv myApp_Alert_1m
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I pass this filename as a parameter into "myAlert.py"?&lt;/P&gt;

&lt;P&gt;( I tried putting into Enable Script where it shows "File name of shell script to run" with &lt;SCRIPTNAME&gt; &lt;FILENAME&gt; option, but not getting any output. ) &lt;/FILENAME&gt;&lt;/SCRIPTNAME&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:37:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Splunk-Alerting-How-to-pass-arguments-filename-to-your-script/m-p/165190#M3637</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2020-09-28T16:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Alerting : How to pass arguments/filename to your script?</title>
      <link>https://community.splunk.com/t5/Reporting/Splunk-Alerting-How-to-pass-arguments-filename-to-your-script/m-p/165191#M3638</link>
      <description>&lt;P&gt;Found a way.&lt;BR /&gt;
As per &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.1/Alert/Configuringscriptedalerts" target="_blank"&gt;Documentation&lt;/A&gt; there are 8 arguments and "SPLUNK_ARG_4" is the "Name of report".&lt;BR /&gt;
So the trick is to make &lt;STRONG&gt;outputcsv filename exactly same name as the Report/SavedSearch&lt;/STRONG&gt;  (and append by .csv etc..)&lt;BR /&gt;
Then we can code within the script.&lt;/P&gt;

&lt;P&gt;Within the script it would be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;CSV_FILE_IN                =    sys.argv[4] + '.csv'
COUNT_ALERTS               =    sys.argv[1]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:37:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Splunk-Alerting-How-to-pass-arguments-filename-to-your-script/m-p/165191#M3638</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2020-09-28T16:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Alerting : How to pass arguments/filename to your script?</title>
      <link>https://community.splunk.com/t5/Reporting/Splunk-Alerting-How-to-pass-arguments-filename-to-your-script/m-p/538887#M8743</link>
      <description>&lt;P&gt;How can we use this variable SPLUNK_ARG_4&amp;nbsp; inside bash shell?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to pass this variable as $i with the script?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 18:18:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Splunk-Alerting-How-to-pass-arguments-filename-to-your-script/m-p/538887#M8743</guid>
      <dc:creator>patelmc</dc:creator>
      <dc:date>2021-02-07T18:18:56Z</dc:date>
    </item>
  </channel>
</rss>

