<?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 fails and I can't see errors in the logs. How can I tell why? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/Python-alert-script-fails-and-I-can-t-see-errors-in-the-logs-How/m-p/208174#M3680</link>
    <description>&lt;P&gt;Use the second form, &lt;CODE&gt;splunk cmd python ...&lt;/CODE&gt;, to run your scripts manually.  It makes sure the environment is correct.&lt;BR /&gt;
Standard output from the script is indexed by Splunk.  Search &lt;CODE&gt;source="*/trigger_fsremediate.py"&lt;/CODE&gt; to find the output.  Find errors by searching &lt;CODE&gt;index=_internal source="*/splunkd*" component=ExecProcessor&lt;/CODE&gt;.&lt;BR /&gt;
Troubleshooting more of a problem.  AFAIK, the python log no longer exists.  I haven't yet discovered a reliable way to determine why scripts fail to run or fail while running.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Feb 2016 18:01:43 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2016-02-18T18:01:43Z</dc:date>
    <item>
      <title>Python alert script fails and I can't see errors in the logs. How can I tell why?</title>
      <link>https://community.splunk.com/t5/Alerting/Python-alert-script-fails-and-I-can-t-see-errors-in-the-logs-How/m-p/208173#M3679</link>
      <description>&lt;P&gt;I have a set of python alert scripts that do basically the same thing, but I don't see them run successfully (the WEB service post that they do doesn't happen). &lt;STRONG&gt;I do see them in the triggered alerts though.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;So I looked for the "runshellscript" lines in the python.log.&lt;/P&gt;

&lt;P&gt;First I made sure that the script does what I want. When I run the command as it appears there, it fails:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[root@rama-splunk splunk]# "/opt/splunk/bin/python" "/opt/splunk/etc/apps/SplunkforCounterACT/bin/scripts/trigger_fsremediate.py" "3" "index=fsctcenter ctupdate=notif pleaseAlertMe2" "index=fsctcenter ctupdate=notif pleaseAlertMe2" "trigger_remediate_action" "Saved Search [trigger_remediate_action] number of events(3)" "http://rama-splunk.networking.lab.forescout.com:8000/app/SplunkforCounterACT/search?q=%7Cloadjob%20scheduler__nobody__SplunkforCounterACT__RMD58498d9b24b108e27_at_1455814800_9726%20%7C%20head%201%20%7C%20tail%201\&amp;amp;earliest=0\&amp;amp;latest=now" "" "/opt/splunk/var/run/splunk/dispatch/scheduler__nobody__SplunkforCounterACT__RMD58498d9b24b108e27_at_1455814800_9726/per_result_alert/tmp_0.csv.gz"
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
  File "/opt/splunk/lib/python2.7/hashlib.py", line 147, in &amp;lt;module&amp;gt;
    globals()[__func_name] = __get_hash(__func_name)
  File "/opt/splunk/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
  File "/opt/splunk/lib/python2.7/hashlib.py", line 147, in &amp;lt;module&amp;gt;
    globals()[__func_name] = __get_hash(__func_name)
  File "/opt/splunk/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
    raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
Traceback (most recent call last):
  File "/opt/splunk/etc/apps/SplunkforCounterACT/bin/scripts/trigger_fsremediate.py", line 2, in &amp;lt;module&amp;gt;
    import fsutil
  File "/opt/splunk/etc/apps/SplunkforCounterACT/bin/scripts/fsutil.py", line 10, in &amp;lt;module&amp;gt;
    from splunk.clilib import cli_common as cli
  File "/opt/splunk/lib/python2.7/site-packages/splunk/clilib/cli_common.py", line 6, in &amp;lt;module&amp;gt;
    import lxml.etree as etree
ImportError: /usr/lib64/libxml2.so.2: version `LIBXML2_2.9.0' not found (required by /opt/splunk/lib/python2.7/site-packages/lxml/etree.so)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But when I run it this way it succeeds:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$SPLUNK_HOME/bin/splunk cmd python "/opt/splunk/etc/apps/SplunkforCounterACT/bin/scripts/trigger_fsremediate.py" "3" "index=fsctcenter ctupdate=notif pleaseAlertMe2" "index=fsctcenter ctupdate=notif pleaseAlertMe2" "trigger_remediate_action" "Saved Search [trigger_remediate_action] number of events(3)" "http://rama-splunk.networking.lab.forescout.com:8000/app/SplunkforCounterACT/search?q=%7Cloadjob%20scheduler__nobody__SplunkforCounterACT__RMD58498d9b24b108e27_at_1455814800_9726%20%7C%20head%201%20%7C%20tail%201\&amp;amp;earliest=0\&amp;amp;latest=now" "" "/opt/splunk/var/run/splunk/dispatch/scheduler__nobody__SplunkforCounterACT__RMD58498d9b24b108e27_at_1455814800_9726/per_result_alert/tmp_0.csv.gz"
Response:  200 OK
Headers:  Date: Thu, 18 Feb 2016 17:31:18 GMT
Server: Apache
X-FRAME-OPTIONS: SAMEORIGIN
X-XSS-PROTECTION: 1;MODE=BLOCK
X-CONTENT-TYPE-OPTIONS: NOSNIFF
Set-Cookie: JSESSIONID=A8338C09AA175FF33A08FE4986C137AF; Path=/; HttpOnly
Content-Length: 194
Connection: close

Content:  &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;SPLUNK_ALERTS TYPE="response"&amp;gt;
&amp;lt;STATUS&amp;gt;
    &amp;lt;CODE&amp;gt;200&amp;lt;/CODE&amp;gt;
    &amp;lt;MESSAGE&amp;gt;Set Disposition [2] to host [10.41.2.103]&amp;lt;/MESSAGE&amp;gt;
&amp;lt;/STATUS&amp;gt;
&amp;lt;/SPLUNK_ALERTS&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How does splunk start the script? Is it one of the above?&lt;BR /&gt;
Where if at all do I see the script's standard output?&lt;BR /&gt;
How can I troubleshoot this?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2016 17:37:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Python-alert-script-fails-and-I-can-t-see-errors-in-the-logs-How/m-p/208173#M3679</guid>
      <dc:creator>ramabu</dc:creator>
      <dc:date>2016-02-18T17:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Python alert script fails and I can't see errors in the logs. How can I tell why?</title>
      <link>https://community.splunk.com/t5/Alerting/Python-alert-script-fails-and-I-can-t-see-errors-in-the-logs-How/m-p/208174#M3680</link>
      <description>&lt;P&gt;Use the second form, &lt;CODE&gt;splunk cmd python ...&lt;/CODE&gt;, to run your scripts manually.  It makes sure the environment is correct.&lt;BR /&gt;
Standard output from the script is indexed by Splunk.  Search &lt;CODE&gt;source="*/trigger_fsremediate.py"&lt;/CODE&gt; to find the output.  Find errors by searching &lt;CODE&gt;index=_internal source="*/splunkd*" component=ExecProcessor&lt;/CODE&gt;.&lt;BR /&gt;
Troubleshooting more of a problem.  AFAIK, the python log no longer exists.  I haven't yet discovered a reliable way to determine why scripts fail to run or fail while running.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2016 18:01:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Python-alert-script-fails-and-I-can-t-see-errors-in-the-logs-How/m-p/208174#M3680</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-02-18T18:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python alert script fails and I can't see errors in the logs. How can I tell why?</title>
      <link>https://community.splunk.com/t5/Alerting/Python-alert-script-fails-and-I-can-t-see-errors-in-the-logs-How/m-p/208175#M3681</link>
      <description>&lt;P&gt;I found dcutils getLogger() to be a pretty swift solution (stolen from other splunk python code):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunk.mining.dcutils as dcu
logger = dcu.getLogger()
logger.info("this string will be found in python.log")
logger.warn()
logger.error()
logger.exception()
logger.debug
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It works so long as you execute it as mentioned by Rich.  Inputs will look like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Windows:
$SPLUNK_HOME\bin\splunk.exe cmd python ..\etc\apps\SplunkforCounterACT\bin\scripts\trigger_fsremediate.py  

Linux:
$SPLUNK_HOME/bin/splunk cmd python ../etc/apps/SplunkforCounterACT/bin/scripts/trigger_fsremediate.py 

Or as a scripted input via inputs.conf examples below:

#Example Inputs.conf# 

#windows input, will be auto-disabled by splunk if application is installed on linux env
[script://$SPLUNK_HOME\etc\apps\SplunkforCounterACT\bin\scripts\trigger_fsremediate.py ]
index = _internal
interval = */30 * * * *
source = trigger_fsremediate.py
sourcetype = sourcetypeName

#linux input, will be auto-disabled by splunk if found on windows env
[script://$SPLUNK_HOME/etc/apps/SplunkforCounterACT/bin/scripts/trigger_fsremediate.py ]
index = _internal
interval = */30 * * * *
source = trigger_fsremediate.py
sourcetype = sourcetypeName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Feb 2016 18:08:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/Python-alert-script-fails-and-I-can-t-see-errors-in-the-logs-How/m-p/208175#M3681</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-02-18T18:08:12Z</dc:date>
    </item>
  </channel>
</rss>

