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!

Prove Your Splunk Prowess at .conf25—No Prereqs Required!

Your Next Big Security Credential: No Prerequisites Needed We know you’ve got the skills, and now, earning the ...

Splunk Observability Cloud's AI Assistant in Action Series: Observability as Code

This is the sixth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Answers Content Calendar, July Edition I

Hello Community! Welcome to another month of Community Content Calendar series! For the month of July, we will ...