<?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 Why am I getting Error code 1 for my python script? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125810#M1830</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;
I wrote a python script to read the external IP from event logs and pass that as the parameter to the command(script)  which is designed to do a CURL lookup . I made sure to include all the splunk libraries within to stream the data, and meet the environment dependencies for CURL on windows. &lt;/P&gt;

&lt;P&gt;Just to make sure I tested the python script with an IP passed as an argument  out of Splunk framework&amp;amp;  it works fine.&lt;BR /&gt;
But returns Error code 1, when integrated with splunk as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys, getopt
import os
import urllib
import urllib2
import csv
import sys,splunk.Intersplunk
(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
 results = []
results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()
for arg in sys.argv:
    print arg
url='https:///%s?' %arg
maxm = os.system('curl -u  "username:password" %s' %url)
result = splunk.Intersplunk.generateErrorResults(None, None, True)
splunk.Intersplunk.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;"External search command 'asd' returned error code 1."&lt;/P&gt;

&lt;P&gt;Please let me know what I am missing on and the likely solution for this.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Sun, 16 Nov 2014 18:26:33 GMT</pubDate>
    <dc:creator>RichaSingh</dc:creator>
    <dc:date>2014-11-16T18:26:33Z</dc:date>
    <item>
      <title>Why am I getting Error code 1 for my python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125810#M1830</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I wrote a python script to read the external IP from event logs and pass that as the parameter to the command(script)  which is designed to do a CURL lookup . I made sure to include all the splunk libraries within to stream the data, and meet the environment dependencies for CURL on windows. &lt;/P&gt;

&lt;P&gt;Just to make sure I tested the python script with an IP passed as an argument  out of Splunk framework&amp;amp;  it works fine.&lt;BR /&gt;
But returns Error code 1, when integrated with splunk as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys, getopt
import os
import urllib
import urllib2
import csv
import sys,splunk.Intersplunk
(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)
 results = []
results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()
for arg in sys.argv:
    print arg
url='https:///%s?' %arg
maxm = os.system('curl -u  "username:password" %s' %url)
result = splunk.Intersplunk.generateErrorResults(None, None, True)
splunk.Intersplunk.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;"External search command 'asd' returned error code 1."&lt;/P&gt;

&lt;P&gt;Please let me know what I am missing on and the likely solution for this.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 16 Nov 2014 18:26:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125810#M1830</guid>
      <dc:creator>RichaSingh</dc:creator>
      <dc:date>2014-11-16T18:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting Error code 1 for my python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125811#M1831</link>
      <description>&lt;P&gt;You're calling &lt;CODE&gt;generateErrorResults()&lt;/CODE&gt; in line 14, that's usually not good if done outside of a conditional statement. Also, I think that takes a single string rather than three arguments.&lt;/P&gt;

&lt;P&gt;Check out &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/AdvancedDev/SearchScripts"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.0/AdvancedDev/SearchScripts&lt;/A&gt; for some docs and an example at the bottom.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Nov 2014 23:08:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125811#M1831</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-11-16T23:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting Error code 1 for my python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125812#M1832</link>
      <description>&lt;P&gt;Here is my edited script. But I still get the same error.&lt;/P&gt;

&lt;P&gt;import sys, getopt&lt;BR /&gt;
import os&lt;BR /&gt;
import urllib&lt;BR /&gt;
import urllib2&lt;BR /&gt;
import csv&lt;BR /&gt;
import splunk.Intersplunk&lt;BR /&gt;
(isgetinfo, sys.argv) = splunk.Intersplunk.isGetInfo(sys.argv)&lt;BR /&gt;
results = []&lt;BR /&gt;
results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()&lt;BR /&gt;
for arg in sys.argv:&lt;BR /&gt;
    print arg&lt;BR /&gt;
url='https://%s' %arg&lt;BR /&gt;
results = os.system('curl -u  "username:password" %s' %url)&lt;BR /&gt;
results = splunk.Intersplunk.readResults(None, None, True)&lt;BR /&gt;
splunk.Intersplunk.outputResults(results)&lt;/P&gt;</description>
      <pubDate>Mon, 17 Nov 2014 08:16:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125812#M1832</guid>
      <dc:creator>RichaSingh</dc:creator>
      <dc:date>2014-11-17T08:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting Error code 1 for my python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125813#M1833</link>
      <description>&lt;P&gt;it says &lt;/P&gt;

&lt;P&gt;The external search command 'asd' did not return events in descending time order, as expected.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Nov 2014 08:22:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125813#M1833</guid>
      <dc:creator>RichaSingh</dc:creator>
      <dc:date>2014-11-17T08:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting Error code 1 for my python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125814#M1834</link>
      <description>&lt;P&gt;use the logger function to display what your script is doing; first add a logger function:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;def setup_logging(n):
    logger = logging.getLogger(n) # Root-level logger
    if myDebug == "yes":
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.ERROR)
    LOGGING_DEFAULT_CONFIG_FILE = os.path.join(SPLUNK_HOME, 'etc', 'log.cfg')
    LOGGING_LOCAL_CONFIG_FILE = os.path.join(SPLUNK_HOME, 'etc', 'log-local.cfg')
    LOGGING_STANZA_NAME = 'python'
    LOGGING_FILE_NAME = "%s.log" % myScript
    BASE_LOG_PATH = os.path.join('var', 'log', 'splunk')
    LOGGING_FORMAT = "%(asctime)s %(levelname)-s\t%(module)s:%(lineno)d - %(message)s"
    splunk_log_handler = logging.handlers.RotatingFileHandler(os.path.join(SPLUNK_HOME, BASE_LOG_PATH, LOGGING_FILE_NAME), mode='a') 
    splunk_log_handler.setFormatter(logging.Formatter(LOGGING_FORMAT))
    logger.addHandler(splunk_log_handler)
    splunk.setupSplunkLogger(logger, LOGGING_DEFAULT_CONFIG_FILE, LOGGING_LOCAL_CONFIG_FILE, LOGGING_STANZA_NAME)
    return logger
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;then add for each step in your script a line like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if myDebug == "yes": logger.info( "Starting the main task ..." )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;your log file will be in $SPLUNK_HOME/var/log/splunk/&lt;/P&gt;</description>
      <pubDate>Mon, 17 Nov 2014 08:25:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125814#M1834</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2014-11-17T08:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why am I getting Error code 1 for my python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125815#M1835</link>
      <description>&lt;P&gt;That's not the same error. Previously the search command didn't run, now it's running but isn't returning events in descending time order, as expected.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Nov 2014 18:06:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-am-I-getting-Error-code-1-for-my-python-script/m-p/125815#M1835</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-11-17T18:06:01Z</dc:date>
    </item>
  </channel>
</rss>

