Getting Data In

Using alternate Python for script data inputs

EricLloyd79
Builder

We are trying to do some snmp queries using Python and input the output key-value pairs into Splunk.
We want to use pysnmp to do this.
Pysnmp (or its dependencies) do not come standard with the Splunk python libraries.

I have attempted putting "#!/root/anaconda2/python" in the first line of our script. But it does not read from the Anaconda Python version we want it to. I am concerned if it does, even, are there specific Splunk-related libraries that Splunk needs to handle the output of these scripts that won't be located in the Anaconda python version.

From another similar question, I tried using:

import sys
sys.path.append('root/anaconda2/bin/python')
sys.path.append('/root/anaconda2/lib/python2.7/site-packages')

This sorta seems to work but now I'm getting an issue seen below:
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/opt/splunk/lib/python2.7/hashlib.py", line 147, in
globals()[func_name] = __get_hash(func_name)
File "/opt/splunk/lib/python2.7/hashlib.py", line 97, in get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
File "/opt/splunk/lib/python2.7/hashlib.py", line 147, in
globals()[
func_name] = get_hash(func_name)
File "/opt/splunk/lib/python2.7/hashlib.py", line 97, in get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
Traceback (most recent call last):
File "get_aqx_intersite_bw.py", line 40, in
from pysnmp.entity.rfc3413.oneliner import cmdgen
File "/root/anaconda2/lib/python2.7/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 10, in
from pysnmp.hlapi.asyncore import *
File "/root/anaconda2/lib/python2.7/site-packages/pysnmp/hlapi/
init_.py", line 3, in
from pysnmp.hlapi.auth import *
File "/root/anaconda2/lib/python2.7/site-packages/pysnmp/hlapi/auth.py", line 7, in
from pysnmp.entity import config
File "/root/anaconda2/lib/python2.7/site-packages/pysnmp/entity/config.py", line 9, in
from pysnmp.proto.secmod.rfc3414.auth import hmacmd5, hmacsha, noauth
File "/root/anaconda2/lib/python2.7/site-packages/pysnmp/proto/secmod/rfc3414/
init_.py", line 1, in
from pysnmp.proto.secmod.rfc3414 import service
File "/root/anaconda2/lib/python2.7/site-packages/pysnmp/proto/secmod/rfc3414/service.py", line 9, in
from pysnmp.proto.secmod.rfc3414.auth import hmacmd5, hmacsha, noauth
File "/root/anaconda2/lib/python2.7/site-packages/pysnmp/proto/secmod/rfc3414/auth/hmacmd5.py", line 10, in
import md5
File "/opt/splunk/lib/python2.7/md5.py", line 10, in
from hashlib import md5
ImportError: cannot import name md5

Please, can someone help me figure out how to use the pysnmp (and its dependencies) with a python script in Splunk? Thank you.

0 Karma

Damien_Dallimor
Ultra Champion

Any reason you would not use https://splunkbase.splunk.com/app/1537/
Uses pysnmp and has been downloaded something like 15K+ times

EricLloyd79
Builder

Well that looks nice. Im doing what I was told to do and how it was done previously in PHP now in Python.
A deterministic factor is that we have to retrieve the SNMP MIBs based on their ifDesc rather than their index. I don't know if this has that capability. I will have to confirm I have permission to download this app to our indexers and see if its capable.
In the meantime, if there was a solution to use an alternate Python library for Python scripts in Splunk that'd be nice since I've got the scripts created and ready to ingest.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...