<?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 script won't execute after setting in alerts in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180475#M2404</link>
    <description>&lt;P&gt;When I had this problem, it was because one of the Python modules for my script failed to import.&lt;/P&gt;

&lt;P&gt;The Splunk version of Python has its site-packages location in $SPLUNK_HOME/lib/python2.7/site-packages, but I'd installed my various modules into the regular Python.  Try from a shell,&lt;BR /&gt;
&lt;CODE&gt;python -c 'import site; print(site.getsitepackages()[0])'&lt;/CODE&gt;&lt;BR /&gt;
versus&lt;BR /&gt;
&lt;CODE&gt;$SPLUNK_HOME/bin/splunk cmd python -c 'import site; print(site.getsitepackages()[0])'&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;One solution is to use &lt;CODE&gt;easy_install --install-dir /path/to/splunk/site-packages .&lt;/CODE&gt; to specifically install each module that failed.&lt;/P&gt;

&lt;P&gt;To debug this sort of thing, it's helpful to edit $SPLUNK_HOME/etc/apps/search/bin/runshellscript.py, and replace the line 'p.communicate(input=stdin_data)' with two lines,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;           pipe = p.communicate(input=stdin_data)
           logger.info("result: %s", pipe)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which will log any output (error messages, etc) from your script into the Splunk 'python.log' file.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 20:17:44 GMT</pubDate>
    <dc:creator>hughpyle</dc:creator>
    <dc:date>2020-09-28T20:17:44Z</dc:date>
    <item>
      <title>Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180467#M2396</link>
      <description>&lt;P&gt;Hi Good day,&lt;/P&gt;

&lt;P&gt;I was trying to run a python script after a saved search has been executed. I have set it up on alerts settings in the search and reports but the script won't run. I have properly include my python script to $SPLUNK_HOME$/bin/scripts folder and make it executable using chmod. There was no logging in splunkd.log that the alert was executed or any errors that occur. &lt;/P&gt;

&lt;P&gt;Thanks  &lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2014 05:50:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180467#M2396</guid>
      <dc:creator>crt89</dc:creator>
      <dc:date>2014-05-28T05:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180468#M2397</link>
      <description>&lt;P&gt;Update: I did also create a .sh file that will call my python script. My script was fine running in command line but won't execute while using Splunk alerts. I'm using Centos as my os and Splunk 6.0.3 as base. Anyone would like to help?&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2014 06:05:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180468#M2397</guid>
      <dc:creator>crt89</dc:creator>
      <dc:date>2014-05-29T06:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180469#M2398</link>
      <description>&lt;P&gt;any errors in python.log? if you 'replace' your script in the alert action with sending email, do you get this - speaking so does your search hit any events?&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2014 07:14:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180469#M2398</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-05-29T07:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180470#M2399</link>
      <description>&lt;P&gt;Thanks for the reply MuS, there was no error in python.log it just log as normal, and yes my search hit events. I did also try to run a simple script that outputs text into a file and it was successful so I'm kinda stuck here does my python script was the problem or Splunk. Btw what I was trying to do was my saved search outputs results to csv file while my python script parsed this file and output it to another file that later be indexed by Splunk. So I was thinking that run my script as the saved search also run. Also thinking that my script will run after my saved search has completed.&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2014 08:04:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180470#M2399</guid>
      <dc:creator>crt89</dc:creator>
      <dc:date>2014-05-29T08:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180471#M2400</link>
      <description>&lt;P&gt;pyhton.log will actually show you if the script is triggered or not. If not it will show you the error why! moreover if you are using arguments to take the csv file path for the search double check if it is the right argument. enable logging for your python script to see if it even going inside it or not&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2014 09:03:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180471#M2400</guid>
      <dc:creator>linu1988</dc:creator>
      <dc:date>2014-05-29T09:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180472#M2401</link>
      <description>&lt;P&gt;here's the a sample entry in my python.log&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;2014-05-29 17:17:09,608 +0800 INFO    runshellscript:188 - runshellscript: ['/bin/bash', '/opt/splunk/bin/scripts/run.sh', '1710', 'my search here', 'test_1', 'Saved Search [test_1] number of events(1710)', '&lt;A href="http://localhost:8000/app/smsgt/@go?sid=scheduler__admin__smsgt__RMD53c4ac00ac374c29b_at_1401355020_103" target="_blank"&gt;http://localhost:8000/app/smsgt/@go?sid=scheduler__admin__smsgt__RMD53c4ac00ac374c29b_at_1401355020_103&lt;/A&gt;', '', '/opt/splunk/var/run/splunk/dispatch/scheduler_&lt;EM&gt;admin&lt;/EM&gt;&lt;EM&gt;smsgt&lt;/EM&gt;_RMD53c4ac00ac374c29b_at_1401355020_103/results.csv.gz']&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 16:45:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180472#M2401</guid>
      <dc:creator>crt89</dc:creator>
      <dc:date>2020-09-28T16:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180473#M2402</link>
      <description>&lt;P&gt;here's what in my run.sh code&lt;BR /&gt;
&lt;CODE&gt;#!/bin/bash&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;SCRIPT_PATH="/opt/splunk/bin/scripts/print.py"&lt;BR /&gt;
PYTHON="/usr/bin/python"&lt;/P&gt;

&lt;P&gt;$PYTHON $SCRIPT_PATH&lt;BR /&gt;
&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2014 09:23:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180473#M2402</guid>
      <dc:creator>crt89</dc:creator>
      <dc:date>2014-05-29T09:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180474#M2403</link>
      <description>&lt;P&gt;try changing your hash bang path to the one for splunk. Like:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;#!/opt/splunk/bin/python&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 08 Aug 2014 20:38:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180474#M2403</guid>
      <dc:creator>starcher</dc:creator>
      <dc:date>2014-08-08T20:38:16Z</dc:date>
    </item>
    <item>
      <title>Re: Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180475#M2404</link>
      <description>&lt;P&gt;When I had this problem, it was because one of the Python modules for my script failed to import.&lt;/P&gt;

&lt;P&gt;The Splunk version of Python has its site-packages location in $SPLUNK_HOME/lib/python2.7/site-packages, but I'd installed my various modules into the regular Python.  Try from a shell,&lt;BR /&gt;
&lt;CODE&gt;python -c 'import site; print(site.getsitepackages()[0])'&lt;/CODE&gt;&lt;BR /&gt;
versus&lt;BR /&gt;
&lt;CODE&gt;$SPLUNK_HOME/bin/splunk cmd python -c 'import site; print(site.getsitepackages()[0])'&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;One solution is to use &lt;CODE&gt;easy_install --install-dir /path/to/splunk/site-packages .&lt;/CODE&gt; to specifically install each module that failed.&lt;/P&gt;

&lt;P&gt;To debug this sort of thing, it's helpful to edit $SPLUNK_HOME/etc/apps/search/bin/runshellscript.py, and replace the line 'p.communicate(input=stdin_data)' with two lines,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;           pipe = p.communicate(input=stdin_data)
           logger.info("result: %s", pipe)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which will log any output (error messages, etc) from your script into the Splunk 'python.log' file.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:17:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180475#M2404</guid>
      <dc:creator>hughpyle</dc:creator>
      <dc:date>2020-09-28T20:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python script won't execute after setting in alerts</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180476#M2405</link>
      <description>&lt;P&gt;I was experiencing the same issue as crt89. I worked through all the same steps, as well, and finally found the issue was a relative path reference in my .py script, needed to be an absolute path.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myConfig = ET.parse( 'foo.xml' ).getroot()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Needed to be updated to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myConfig = ET.parse( '$SPLUNK_HOME/bin/scripts/foo.xml' ).getroot()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was also running the python script via an .sh script to allow me to use python modules not included by splunk. Again, just as crt89 had outlined.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2016 19:31:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Python-script-won-t-execute-after-setting-in-alerts/m-p/180476#M2405</guid>
      <dc:creator>richard_wilhite</dc:creator>
      <dc:date>2016-09-21T19:31:38Z</dc:date>
    </item>
  </channel>
</rss>

