<?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: Scripted Alert Question in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Alert-Question/m-p/14351#M1459</link>
    <description>&lt;P&gt;No the arguments do not contain the results.&lt;/P&gt;

&lt;P&gt;I wanted this too when I first start using splunk, but think about it this way:  The results from your search could contain thousands of events, which is way too much info to pass around on the command line.  So it's necessary for the results to be saved to a file first.  Then splunk passes your script the name of that file as &lt;CODE&gt;$8&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Here is something you could get started with:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;my_custom_script.py&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import gzip
import csv
from subprocess import call

def openany(p):
    if p.endswith(".gz"):
        return gzip.open(p)
    else:
        return open(p)

event_count = int(sys.argv[1])  # number of events returned.
results_file = sys.argv[8]      # file with search results

for row in csv.DictReader(openany(results_file)):
    # Build a command line to call based on fields from splunk output
    my_command = [ "ssh", row["shost"], "-l", row["suser"], .... ]
    call(my_command)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 May 2010 06:15:51 GMT</pubDate>
    <dc:creator>Lowell</dc:creator>
    <dc:date>2010-05-27T06:15:51Z</dc:date>
    <item>
      <title>Scripted Alert Question</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Alert-Question/m-p/14350#M1458</link>
      <description>&lt;P&gt;Is there a way to pass the &lt;EM&gt;result&lt;/EM&gt; of a savedsearch to a script? For example, if the search returns:&lt;/P&gt;

&lt;P&gt;suser   duser   shost   dhost
me  you mine    yours
you me  yours   mine&lt;/P&gt;

&lt;P&gt;I’d like the script to the “shost” column and perform certain function based on the content of shost.&lt;/P&gt;

&lt;P&gt;These are the arguments Splunk passes to the script. But I’m not sure they contain the results.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* $0 = script name.
* $1 = number of events returned.
* $2 = search terms.
* $3 = fully qualified query string.
* $4 = name of saved splunk.
* $5 = trigger reason (i.e. "The number of events was greater than 1").
* $6 = Browser URL to view the saved search.
* $7 = This option has been deprecated and is no longer used
* $8 = file where the results for this search are stored (contains raw results). 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 May 2010 05:46:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Scripted-Alert-Question/m-p/14350#M1458</guid>
      <dc:creator>ubko</dc:creator>
      <dc:date>2010-05-27T05:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted Alert Question</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Alert-Question/m-p/14351#M1459</link>
      <description>&lt;P&gt;No the arguments do not contain the results.&lt;/P&gt;

&lt;P&gt;I wanted this too when I first start using splunk, but think about it this way:  The results from your search could contain thousands of events, which is way too much info to pass around on the command line.  So it's necessary for the results to be saved to a file first.  Then splunk passes your script the name of that file as &lt;CODE&gt;$8&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Here is something you could get started with:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;my_custom_script.py&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import gzip
import csv
from subprocess import call

def openany(p):
    if p.endswith(".gz"):
        return gzip.open(p)
    else:
        return open(p)

event_count = int(sys.argv[1])  # number of events returned.
results_file = sys.argv[8]      # file with search results

for row in csv.DictReader(openany(results_file)):
    # Build a command line to call based on fields from splunk output
    my_command = [ "ssh", row["shost"], "-l", row["suser"], .... ]
    call(my_command)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 May 2010 06:15:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Scripted-Alert-Question/m-p/14351#M1459</guid>
      <dc:creator>Lowell</dc:creator>
      <dc:date>2010-05-27T06:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Scripted Alert Question</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Scripted-Alert-Question/m-p/14352#M1460</link>
      <description>&lt;P&gt;Since my result set is only a few lines, I was looking for a direct solution. Thank you for your suggestion and I think it'll definitely solve my immediate problem.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2010 22:41:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Scripted-Alert-Question/m-p/14352#M1460</guid>
      <dc:creator>ubko</dc:creator>
      <dc:date>2010-05-27T22:41:57Z</dc:date>
    </item>
  </channel>
</rss>

