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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...