<?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: Python alert script to show the search result values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246617#M73520</link>
    <description>&lt;P&gt;i need to print (to a file) the search results when the alert is triggered, lets say i have 3 columns in the search results, i need to send the result values of these 3 columns to another file .&lt;/P&gt;

&lt;P&gt;I am now trying in 6.3 version (trial version), but i will be implementing in 6.2 version. Is there any changes in scripts or functionalities when we use latest version of splunk??&lt;/P&gt;</description>
    <pubDate>Thu, 26 Nov 2015 17:31:51 GMT</pubDate>
    <dc:creator>harish_ka</dc:creator>
    <dc:date>2015-11-26T17:31:51Z</dc:date>
    <item>
      <title>Python alert script to show the search result values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246615#M73518</link>
      <description>&lt;P&gt;Can someone please help me with a python script to display the values of search results.&lt;BR /&gt;
i have been trying but not able to write a script for this.&lt;BR /&gt;
Do we need to do any other settings??&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 17:13:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246615#M73518</guid>
      <dc:creator>harish_ka</dc:creator>
      <dc:date>2015-11-26T17:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python alert script to show the search result values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246616#M73519</link>
      <description>&lt;P&gt;Can you elaborate on what your final goal is here? Are you using Splunk 6.3 or an earlier release?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 17:21:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246616#M73519</guid>
      <dc:creator>dart</dc:creator>
      <dc:date>2015-11-26T17:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python alert script to show the search result values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246617#M73520</link>
      <description>&lt;P&gt;i need to print (to a file) the search results when the alert is triggered, lets say i have 3 columns in the search results, i need to send the result values of these 3 columns to another file .&lt;/P&gt;

&lt;P&gt;I am now trying in 6.3 version (trial version), but i will be implementing in 6.2 version. Is there any changes in scripts or functionalities when we use latest version of splunk??&lt;/P&gt;</description>
      <pubDate>Thu, 26 Nov 2015 17:31:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246617#M73520</guid>
      <dc:creator>harish_ka</dc:creator>
      <dc:date>2015-11-26T17:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python alert script to show the search result values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246618#M73521</link>
      <description>&lt;P&gt;If you want to run a script from a saved search, check out: &lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.1/alert/ConfiguringScriptedAlerts"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.1/alert/ConfiguringScriptedAlerts&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You'll need to parse out the results from a file, the filename is provided as the 9th argument to the script.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2015 12:14:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246618#M73521</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2015-11-27T12:14:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python alert script to show the search result values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246619#M73522</link>
      <description>&lt;P&gt;Yes i am trying with the following script:&lt;/P&gt;

&lt;H1&gt;!C:/Program Files/Splunk/bin/python&lt;/H1&gt;

&lt;P&gt;import sys, csv&lt;/P&gt;

&lt;P&gt;def openany(p):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if  p.endswith(".gz"):
    import gzip
    return gzip.open(p)

else:
    return open(p)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;results_file = sys.argv[9]&lt;BR /&gt;
for result in csv.DictReader(openany(results_file)):&lt;/P&gt;

&lt;H1&gt;Do whatever action with your results ...&lt;/H1&gt;

&lt;PRE&gt;&lt;CODE&gt;print results["_raw"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But its not working &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Can you help me with this??&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:00:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246619#M73522</guid>
      <dc:creator>harish_ka</dc:creator>
      <dc:date>2020-09-29T08:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python alert script to show the search result values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246620#M73523</link>
      <description>&lt;P&gt;Test your script first. &lt;/P&gt;

&lt;P&gt;Run your script manually against any results.csv.gz file (you can find them in $SPLUNK_HOME/var/run/splunk/dispatch/ )&lt;/P&gt;

&lt;P&gt;eg &lt;BR /&gt;
&lt;CODE&gt;python pyalert.py 0 1 2 3 4 5 6 7 ./results.csv.gz&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;You should get a stacktrace from python telling you whats going wrong. I can't tell you 100% from looking at your code but I'm guessing you're missing an indent in the final for loop, and 'results' is not defined anywhere&lt;/P&gt;

&lt;P&gt;This might work better:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;for result in csv.DictReader(openany(results_file)):
           print result
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Nov 2015 13:42:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246620#M73523</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2015-11-27T13:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Python alert script to show the search result values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246621#M73524</link>
      <description>&lt;P&gt;@jplumsdaine22, you can format your text almost any way you like when you use the code mode:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;leave one line blank and indent by four spaces
  and then
                             you can indent as much as you like
                             and have monospaced font
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Nov 2015 14:22:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246621#M73524</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-11-30T14:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python alert script to show the search result values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246622#M73525</link>
      <description>&lt;P&gt;Yes it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
Thanks a lot    @jplumsdaine22 &amp;amp;  @jeffland&lt;/P&gt;</description>
      <pubDate>Fri, 04 Dec 2015 06:08:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Python-alert-script-to-show-the-search-result-values/m-p/246622#M73525</guid>
      <dc:creator>harish_ka</dc:creator>
      <dc:date>2015-12-04T06:08:48Z</dc:date>
    </item>
  </channel>
</rss>

