Splunk Search

Can Customer Command use import a local python module?

shenjunwei
New Member

I'm now use splunk-sdk-python-1.5.0 to create a search command.
How can I add a python module that is not included in the Splunk python bundle? Specifically, I would like to use the ctypes module from within Splunk to run a scripted input.
I added local python environment path just like below:

 from sys import modules, path as python_path
 python_path.insert(2, r'/usr/lib/python2.7/') 

But got the below error:

Error in 'script': Getinfo probe failed for external search command 'sum'
from _ctypes import Union, Structure, Array
import ctypes
File "/opt/splunk/etc/apps/ericApp/bin/sum.py", line 23, in <module>
File "/usr/lib/python2.7/ctypes/__init__.py", line 10, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 29, in <module>
ImportError: No module named _ctypes
Traceback (most recent call last):
pydev debugger: warning: trying to add breakpoint to file that does not exist: /opt/splunk/etc/apps/ericApp/bin/C:/Users/shene/workspace/beginningPython/chapter01.py (will have no effect)
pydev debugger: warning: trying to add breakpoint to file that does not exist: /opt/splunk/etc/apps/ericApp/bin/C:/Users/shene/workspace/customerCommand/test.py (will have no effect)
The search job has failed due to an error. You may be able view the job in the Job Inspector.
0 Karma

dominiquevocat
SplunkTrust
SplunkTrust

Just place the class under /bin of your app

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...