My own Python script cannot import Splunk Python library modules?
[root@localhost bin]# ./qqip.py 8.8.8.8
Traceback (most recent call last):
File "./qqip.py", line 162, in
import splunk.Intersplunk as si
ImportError: No module named splunk.Intersplunk
[root@localhost bin]# vim qqip.py
161 import re
162 import splunk.Intersplunk as si
163 ipre = re.compile("\d+.\d+.\d+.\d+")
164 results = []
165 if name == 'main':
[root@localhost bin]# find / -name Intersplunk
/opt/splunk/lib/python2.7/site-packages/splunk/Intersplunk.pyo
/opt/splunk/lib/python2.7/site-packages/splunk/Intersplunk.pyc
/opt/splunk/lib/python2.7/site-packages/splunk/Intersplunk.py
???
Splunk comes bundled with its own Python environment. You could either set your PYTHONPATH in order to make use of the packages available in it, or better yet you should run Splunk's python completely: /opt/splunk/bin/splunk cmd python <yourfile.py>
.
Hello, I was the same problem with Mysql module that I was install on my Centos server
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
[root@xxxx]#find / -name site-packages
/usr/lib/python2.7/site-packages
/usr/lib64/python2.7/site-packages
/opt/splunk/etc/apps/Splunk_SA_Scientific_Python_linux_x86_64/bin/linux_x86_64/lib/python2.7/site-packages
/opt/splunk/lib/python2.7/site-packages
[root@xxxx]# whereis python
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
include all at begin your script
import sys
sys.path.append('/usr/bin/python2.7')
sys.path.append('/usr/lib/python2.7/site-packages')
sys.path.append('/usr/lib64/python2.7/site-packages')
And that's it , you can run mysql module without any problem and create your alerts with this module.
import mysql.connector
I hope that this fix will help you
Joel Urtubia Ugarte
Splunk comes bundled with its own Python environment. You could either set your PYTHONPATH in order to make use of the packages available in it, or better yet you should run Splunk's python completely: /opt/splunk/bin/splunk cmd python <yourfile.py>
.
is ended up solving a major problem for me using Ansible to setup Splunk and running python scripts inside the Ansible playbook. Thank you so much!
Ayn ,Thank you very much!