<?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: Unable to execute python script - could be splunk lib path issue in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259503#M3227</link>
    <description>&lt;P&gt;Hey. PFB the code. I just want to pass the two arguments received from Search bar to my python script.&lt;/P&gt;

&lt;H1&gt;!/opt/splunk/bin/python2.7&lt;/H1&gt;

&lt;P&gt;import sys, time&lt;/P&gt;

&lt;H1&gt;import splunk.Intersplunk&lt;/H1&gt;

&lt;P&gt;import getopt&lt;BR /&gt;
from splunklib.searchcommands import \&lt;BR /&gt;
    dispatch, GeneratingCommand, Configuration, Option, validators&lt;BR /&gt;
def main(argv):&lt;/P&gt;

&lt;P&gt;print("hello")&lt;BR /&gt;
  opts, args = getopt.getopt(argv,["ifile=","ofile="])&lt;BR /&gt;
  for arg in args :&lt;BR /&gt;
     print (arg)&lt;BR /&gt;
main(sys.argv[1:])&lt;/P&gt;

&lt;P&gt;And in my commands.conf. i have &lt;BR /&gt;
[generatehello]&lt;BR /&gt;
filename = command_test&lt;BR /&gt;
supports_getinfo = true&lt;BR /&gt;
supports_rawargs = true&lt;BR /&gt;
outputheader = true&lt;/P&gt;

&lt;P&gt;Command line Output : &lt;BR /&gt;
splunk~/bin]$ /opt/splunk/bin/splunk cmd python command_test file1 file2&lt;BR /&gt;
hello&lt;BR /&gt;
file1&lt;BR /&gt;
file2&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 09:21:43 GMT</pubDate>
    <dc:creator>kamal_jagga</dc:creator>
    <dc:date>2020-09-29T09:21:43Z</dc:date>
    <item>
      <title>Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259498#M3222</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to run a python script. The script works fine in lower environment and i am trying to move it to higher. I am able to execute other python scripts normally in both env.&lt;/P&gt;

&lt;P&gt;I was able to run the script in lower env by specifying the splunk path in front of it.&lt;/P&gt;

&lt;P&gt;/opt/splunk/bin/splunk cmd python command_test.py &lt;/P&gt;

&lt;P&gt;So, while i am trying to execute it in higher using the same way. Its giving error. &lt;/P&gt;

&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;
  File "command_test.py", line 4, in &lt;BR /&gt;
    from splunklib.searchcommands import \&lt;BR /&gt;
ImportError: No module named splunklib.searchcommands&lt;/P&gt;

&lt;P&gt;Now someone in my team has told me that splunk lib path might have been set in lower environment. &lt;/P&gt;

&lt;P&gt;Would anyone be able to advise on where and what to set the path. Or any other way to fix the issue.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 20:31:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259498#M3222</guid>
      <dc:creator>kamal_jagga</dc:creator>
      <dc:date>2016-03-22T20:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259499#M3223</link>
      <description>&lt;P&gt;Take a look at this answer &lt;A href="https://answers.splunk.com/answers/243498/getinfo-probe-failed-for-external-search-command-a.html"&gt;https://answers.splunk.com/answers/243498/getinfo-probe-failed-for-external-search-command-a.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 02:30:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259499#M3223</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-03-23T02:30:02Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259500#M3224</link>
      <description>&lt;P&gt;I checked the answer, for higher environment we don't have the required files. So, i think that's why we are not able to run it. But in lower env, we have the required files  (&lt;STRONG&gt;init&lt;/STRONG&gt;.py &amp;amp; &lt;STRONG&gt;init&lt;/STRONG&gt;.pyc) in the splunklib/searchcommands&lt;/P&gt;

&lt;P&gt;Interestingly splunk is also not able to run the script in lower environment.&lt;/P&gt;

&lt;P&gt;I am able to run the command as:&lt;BR /&gt;
/opt/splunk_1/bin/splunk cmd python command_test &lt;/P&gt;

&lt;P&gt;But not as &lt;BR /&gt;
python command_test &lt;/P&gt;

&lt;P&gt;So, I need a way to splunk execute the script as "/opt/splunk_1/bin/splunk cmd python command_test " rather than "python command_test ".&lt;/P&gt;

&lt;P&gt;Kindly advise.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:12:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259500#M3224</guid>
      <dc:creator>kamal_jagga</dc:creator>
      <dc:date>2020-09-29T09:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259501#M3225</link>
      <description>&lt;P&gt;Can you provide the script code, if it doesn't contain anything sensitive?&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 17:16:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259501#M3225</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-03-25T17:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259502#M3226</link>
      <description>&lt;P&gt;I wonder if you are missing the PYTHONPATH environment variable in your higher environment.  This is what it is set to for me:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;PYTHONPATH=C:\Program Files\Splunk\bin;C:\Program Files\Splunk\Python-2.7\Lib\site-packages\win32;C:\Program Files\Splunk\Python-2.7\Lib\site-packages;C:\Program Files\Splunk\Python-2.7\Lib;C:\Program Files\Splunk\etc\apps\framework\contrib\splunk-sdk-python
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2016 17:38:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259502#M3226</guid>
      <dc:creator>kbarker302</dc:creator>
      <dc:date>2016-03-29T17:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259503#M3227</link>
      <description>&lt;P&gt;Hey. PFB the code. I just want to pass the two arguments received from Search bar to my python script.&lt;/P&gt;

&lt;H1&gt;!/opt/splunk/bin/python2.7&lt;/H1&gt;

&lt;P&gt;import sys, time&lt;/P&gt;

&lt;H1&gt;import splunk.Intersplunk&lt;/H1&gt;

&lt;P&gt;import getopt&lt;BR /&gt;
from splunklib.searchcommands import \&lt;BR /&gt;
    dispatch, GeneratingCommand, Configuration, Option, validators&lt;BR /&gt;
def main(argv):&lt;/P&gt;

&lt;P&gt;print("hello")&lt;BR /&gt;
  opts, args = getopt.getopt(argv,["ifile=","ofile="])&lt;BR /&gt;
  for arg in args :&lt;BR /&gt;
     print (arg)&lt;BR /&gt;
main(sys.argv[1:])&lt;/P&gt;

&lt;P&gt;And in my commands.conf. i have &lt;BR /&gt;
[generatehello]&lt;BR /&gt;
filename = command_test&lt;BR /&gt;
supports_getinfo = true&lt;BR /&gt;
supports_rawargs = true&lt;BR /&gt;
outputheader = true&lt;/P&gt;

&lt;P&gt;Command line Output : &lt;BR /&gt;
splunk~/bin]$ /opt/splunk/bin/splunk cmd python command_test file1 file2&lt;BR /&gt;
hello&lt;BR /&gt;
file1&lt;BR /&gt;
file2&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:21:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259503#M3227</guid>
      <dc:creator>kamal_jagga</dc:creator>
      <dc:date>2020-09-29T09:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259504#M3228</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;

&lt;P&gt;command_test.py&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys, splunk.Intersplunk, csv, urllib2, base64

keywords, argvals = splunk.Intersplunk.getKeywordsAndOptions()
file1 = argvals.get("file1", None)
file2 = argvals.get("file2", "csv")

if not file1:
   splunk.Intersplunk.parseError("'file1' argument not provided.")
if not file2:
   splunk.Intersplunk.parseError("'file2' argument not provided.")

results = []    
try:
    results.append('Hello ')
    results.append('File1 passed is %s ' % ( file1 ))
    results.append('File2 passed is %s ' % ( file2 ))
except Exception, e:
   splunk.Intersplunk.parseError(e)

results = [{'search' : disjuncts}]
splunk.Intersplunk.outputResults(results)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;commands.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[generatehello]
filename = command_test.py
generating = true
local = true
supports_rawargs = false
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Usage&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;splunk~/bin]$ /opt/splunk/bin/splunk cmd python command_test file1=file1 file2=file2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| generatehello file1=file1 file2=file2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Apr 2016 17:39:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259504#M3228</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-04-05T17:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259505#M3229</link>
      <description>&lt;P&gt;I had a same problem.First Check your Splunk and Python Path .secondly check on which port python is running .Or some other application is running on the same port.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2016 17:47:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259505#M3229</guid>
      <dc:creator>kartik13</dc:creator>
      <dc:date>2016-04-05T17:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259506#M3230</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;

&lt;P&gt;Thanks a lot for replying and apologies for the late reply.&lt;/P&gt;

&lt;P&gt;I am getting an error and wasn't able to research much on the below issue.&lt;BR /&gt;
Error:&lt;BR /&gt;
Traceback (most recent call last):&lt;BR /&gt;
  File "command_test1.py", line 20, in &lt;BR /&gt;
    results = [{'search' : disjuncts}]&lt;BR /&gt;
NameError: name 'disjuncts' is not defined&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2016 18:31:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259506#M3230</guid>
      <dc:creator>kamal_jagga</dc:creator>
      <dc:date>2016-04-20T18:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259507#M3231</link>
      <description>&lt;P&gt;@somesoni2 : Kindly advise.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 21:53:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259507#M3231</guid>
      <dc:creator>kamal_jagga</dc:creator>
      <dc:date>2016-04-26T21:53:25Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259508#M3232</link>
      <description>&lt;P&gt;Same issue this isn't working&lt;/P&gt;</description>
      <pubDate>Sun, 02 Oct 2016 13:25:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259508#M3232</guid>
      <dc:creator>ryanoconnor</dc:creator>
      <dc:date>2016-10-02T13:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to execute python script - could be splunk lib path issue</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259509#M3233</link>
      <description>&lt;P&gt;Hello, I was the same problem with Mysql module that I was install on my Centos server&lt;/P&gt;

&lt;P&gt;Splunk didn't work with this library, because splunk has they own python library...then you can fix it only added on the begin your script all libraries of python and also you must to add the python Centos library too... as this way&lt;/P&gt;

&lt;H3&gt;Find python packages&lt;/H3&gt;

&lt;P&gt;[root@xxxx]#find / -name site-packages&lt;BR /&gt;
/usr/lib/python2.7/site-packages&lt;BR /&gt;
/usr/lib64/python2.7/site-packages&lt;BR /&gt;
/opt/splunk/etc/apps/Splunk_SA_Scientific_Python_linux_x86_64/bin/linux_x86_64/lib/python2.7/site-packages&lt;BR /&gt;
/opt/splunk/lib/python2.7/site-packages&lt;/P&gt;

&lt;H3&gt;Find python binary&lt;/H3&gt;

&lt;P&gt;[root@xxxx]# whereis python&lt;BR /&gt;
python: /usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /opt/splunk/bin/python /opt/splunk/bin/python2.7 /usr/share/man/man1/python.1.gz&lt;/P&gt;

&lt;P&gt;include all at begin your script&lt;/P&gt;

&lt;P&gt;import sys&lt;BR /&gt;
sys.path.append('/usr/bin/python2.7')&lt;BR /&gt;
sys.path.append('/usr/lib/python2.7/site-packages')&lt;BR /&gt;
sys.path.append('/usr/lib64/python2.7/site-packages')&lt;/P&gt;

&lt;P&gt;And that's it , you can run mysql module without any problem and create your alerts with this module.&lt;/P&gt;

&lt;H3&gt;Mysql Connection&lt;/H3&gt;

&lt;P&gt;import mysql.connector&lt;/P&gt;

&lt;P&gt;I hope that this fix will help you&lt;BR /&gt;
Joel Urtubia Ugarte&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:36:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Unable-to-execute-python-script-could-be-splunk-lib-path-issue/m-p/259509#M3233</guid>
      <dc:creator>joelurtubia</dc:creator>
      <dc:date>2020-09-29T16:36:44Z</dc:date>
    </item>
  </channel>
</rss>

