Try ./splunk cmd python setup.py build from http://answers.splunk.com/questions/8/can-i-add-python-modules-to-the-splunk-environment
Regards,
Rui
The venerable old-skool Splunk forums are now closed. Feel free to search for old content here, but new posts are no longer supported.
Instead, please visit the thriving community at answers.splunk.com to ask and answer questions about your Splunk deployment and how to get the most out of it.
Previous Topic: Help Parsing general message field and counting the result. | Next Topic: can only parse strings error
Hi,
I want to do lookup from mysql database. the python in my linux is python 2.3, and i installed splunk 3.4 and splunk 4.0, so there are 3 pythons in the server -- 2.3, 2.5 and 2.6.
I want to append mysqldb to python 2.6. The following are the steps and console messages.
cd MySQL-python-1.2.3c1
python2.6 setup.py build
ImportError: No module named setuptools
sh setuptools-0.6c11-py2.6.egg
ImportError: No module named command.bdist
Anyone can help? Thanks,
//Note: it goes well when install setuptools and mysqldb to the local python 2.3.
Dianbo
Try ./splunk cmd python setup.py build from http://answers.splunk.com/questions/8/can-i-add-python-modules-to-the-splunk-environment
Regards,
Rui
it is the same.
[root@localhost bin]# ./splunk cmd /local/dl/setuptools-0.6c11-py2.6.egg Traceback (most recent call last): File "", line 1, in File "/local/dl/setuptools-0.6c11-py2.6.egg/setuptools/init.py", line 2, in File "/local/dl/setuptools-0.6c11-py2.6.egg/setuptools/extension.py", line 2, in File "/local/dl/setuptools-0.6c11-py2.6.egg/setuptools/dist.py", line 5, in File "/local/dl/setuptools-0.6c11-py2.6.egg/setuptools/command/init.py", line 13, in ImportError: No module named command.bdist
[root@localhost bin]# ./splunk cmd /local/dl/MySQL_python-1.2.3c1-py2.6-linux-i686.egg couldn't run "/local/dl/MySQL_python-1.2.3c1-py2.6-linux-i686.egg": Exec format error
According to the Splunk Answers thread above, it is not supported to install 3rd party python modules within Splunk. The best practice is to use a wrapper script such as is described in Amrit's post on that thread.
Hi,
I tried the following code but did not see the lookup result.
//dbtestlookupwrapper.py
mycmd_ = ['/usr/bin/python', '/opt/splunk/etc/apps/search/bin/dbtestlookup.py', cityf, countryf]
subprocess.Popen(mycmd_, stdin = None, stdout = None, stderr = None, shell = False).wait()
2 questions:
how to set relative address for the python script?
where is the error information log file when failed to execute lookup script?
Thanks & regards.
Dianbo
Per the answers post, did you unset the required env variables? It does not look like you did based on above.
You will probably need to do something like this:
#!/opt/splunk/bin/python
import os,sys,subprocess
os.unsetenv("PYTHONPATH")
os.unsetenv("PATH")
os.unsetenv("LD_LIBRARY_PATH")
p = subprocess.Popen(['/usr/bin/python', '/opt/splunk/etc/apps/search/bin/dbtestlookup.py', cityf, countryf],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
so = p.communicate("".join(sys.stdin.readlines()))
for o in so:
if o:
print o
thank you very much.
i am a beginner of Python. thank you for your detailed explanation.
How to use relative address in subprocess.Popen. I used the following code but it failed.
p = subprocess.Popen(['/usr/bin/python', './dbtestlookup.py', cityf, countryf], .......
Thanks.