<?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 How do I find scheduled saved searches where external python commands failed? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-find-scheduled-saved-searches-where-external-python/m-p/234235#M2980</link>
    <description>&lt;P&gt;I have a scheduled saved search which runs every 15mins. This search calls a custom python external command that does some HTTP calls. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main | head 100 | mypythoncommand | collect index=mysummaryindex
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sometimes the the external command fails (say because the service it's calling is down and I get an exception doing the request), in which case I log the error and exit with a failure code.&lt;/P&gt;

&lt;P&gt;Imagine the python external command looks something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"""
   mypythoncommand.py does an http call which sometimes fails
"""
import sys
import splunk.Intersplunk
import requests



def main():
    (isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
    if isgetinfo:
        splunk.Intersplunk.outputInfo(False, False, True, False, None, False)
        return

    results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()

    try:
        response = requests.get("https://www.example.com",
                                timeout=30, verify=false)
    except:
        splunk.Intersplunk.parseError(sys.exc_info())
        exit(-1)

    splunk.Intersplunk.outputResults(results)


if __name__ == "__main__":
    main()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you run this search from Splunk Web, the search fails with a descriptive error, and the search.log has the details. I see an error like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;command="mypythoncommand", (&amp;lt;type 'exceptions.Exception'&amp;gt;, Exception(u'Non-OK response from external mypythoncommand service: {"message":"Something bad"}',), &amp;lt;traceback object at 0x7faa83763200&amp;gt;)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, I can't find any log entries in _internal or _audit that show that the search failed. In fact, _internal shows that the search completed with status success ( &lt;CODE&gt;source = /opt/splunk/var/log/splunk/scheduler.log sourcetype=scheduler&lt;/CODE&gt; )&lt;/P&gt;

&lt;P&gt;So far I've tried the _audit and _internal indexes, but no luck. Is there any other way to determine which scheduled saved search runs failed with an error?&lt;/P&gt;</description>
    <pubDate>Wed, 23 Sep 2015 15:32:02 GMT</pubDate>
    <dc:creator>thorbenlouw</dc:creator>
    <dc:date>2015-09-23T15:32:02Z</dc:date>
    <item>
      <title>How do I find scheduled saved searches where external python commands failed?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-find-scheduled-saved-searches-where-external-python/m-p/234235#M2980</link>
      <description>&lt;P&gt;I have a scheduled saved search which runs every 15mins. This search calls a custom python external command that does some HTTP calls. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main | head 100 | mypythoncommand | collect index=mysummaryindex
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sometimes the the external command fails (say because the service it's calling is down and I get an exception doing the request), in which case I log the error and exit with a failure code.&lt;/P&gt;

&lt;P&gt;Imagine the python external command looks something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"""
   mypythoncommand.py does an http call which sometimes fails
"""
import sys
import splunk.Intersplunk
import requests



def main():
    (isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
    if isgetinfo:
        splunk.Intersplunk.outputInfo(False, False, True, False, None, False)
        return

    results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()

    try:
        response = requests.get("https://www.example.com",
                                timeout=30, verify=false)
    except:
        splunk.Intersplunk.parseError(sys.exc_info())
        exit(-1)

    splunk.Intersplunk.outputResults(results)


if __name__ == "__main__":
    main()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When you run this search from Splunk Web, the search fails with a descriptive error, and the search.log has the details. I see an error like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;command="mypythoncommand", (&amp;lt;type 'exceptions.Exception'&amp;gt;, Exception(u'Non-OK response from external mypythoncommand service: {"message":"Something bad"}',), &amp;lt;traceback object at 0x7faa83763200&amp;gt;)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, I can't find any log entries in _internal or _audit that show that the search failed. In fact, _internal shows that the search completed with status success ( &lt;CODE&gt;source = /opt/splunk/var/log/splunk/scheduler.log sourcetype=scheduler&lt;/CODE&gt; )&lt;/P&gt;

&lt;P&gt;So far I've tried the _audit and _internal indexes, but no luck. Is there any other way to determine which scheduled saved search runs failed with an error?&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2015 15:32:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-find-scheduled-saved-searches-where-external-python/m-p/234235#M2980</guid>
      <dc:creator>thorbenlouw</dc:creator>
      <dc:date>2015-09-23T15:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I find scheduled saved searches where external python commands failed?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-do-I-find-scheduled-saved-searches-where-external-python/m-p/234236#M2981</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal  sourcetype=splunk_python OR sourcetype=scheduler | rex "(Saved Search \[|savedsearch_name=\")(?&amp;lt;SavedSearchName&amp;gt;[^\"\]]+)" | transaction SavedSearchName startswith=sourcetype=splunk_python endswith=sourcetype=scheduler
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Sep 2015 20:44:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-do-I-find-scheduled-saved-searches-where-external-python/m-p/234236#M2981</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2015-09-23T20:44:20Z</dc:date>
    </item>
  </channel>
</rss>

