Open mathewfer opened 6 years ago
@mathewfer Did you download and install 'snmp_helper.py' such that it is somewhere on your Python Path (the easiest place being your current working directory)?
Kirk
Hi Kirk, Oops, my bad. Thanks a lot and sorry for the trouble and yes got it working as expected.
Hi Kirk,
I progressed but see below and please let me know if you have any idea.
When I run "snmpwalk -v3 -On -u aYYuv3 -l AuthPriv -a SHA -A undxyz1 -X undxyz3 10.1.1.23 1.3.6.1.2.1.1.1.0", router responds well.
mathewfer@Tools-SRV:~$ cat snmpv3.py
#Example usage (SNMPv3):
from snmp_helper import snmp_get_oid_v3,snmp_extract
#The below works
#snmpwalk -v3 -On -u aYYuv3 -l AuthPriv -a SHA -A undxyz1 -X undxyz3 10.1.1.23 1.3.6.1.2.1.1.1.0
snmp_device = ('10.1.1.23', 161)
a_user = 'aYYuv3'
auth_key = 'undxyz1'
encrypt_key = 'undxyz3'
encrypt_proto='des'
auth_proto = 'sha'
snmp_user = (a_user, auth_key, encrypt_key)
sys_descr = '1.3.6.1.2.1.1.1.0'
snmp_data = snmp_get_oid_v3(snmp_device, snmp_user, oid=sys_descr)
output = snmp_extract(snmp_data)
print(output)
#end
mathewfer@Tools-SRV:~$ python3 snmpv3.py
Traceback (most recent call last):
File "<string>", line 1148, in __delegate
File "<string>", line 937, in writeTest
pysnmp.smi.error.RowCreationWanted: RowCreationWanted({})
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "snmpv3.py", line 17, in <module>
snmp_data = snmp_get_oid_v3(snmp_device, snmp_user, oid=sys_descr)
File "/home/mathewfer/snmp_helper.py", line 115, in snmp_get_oid_v3
lookupNames=True, lookupValues=True
File "/usr/local/lib/python3.5/dist-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 183, in getCmd
**kwargs):
File "/usr/local/lib/python3.5/dist-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd
lookupMib=options.get('lookupMib', True)))
File "/usr/local/lib/python3.5/dist-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 124, in getCmd
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
File "/usr/local/lib/python3.5/dist-packages/pysnmp/hlapi/lcd.py", line 60, in configure
securityName=authData.securityName
File "/usr/local/lib/python3.5/dist-packages/pysnmp/entity/config.py", line 142, in addV3User
((usmUserEntry.name + (13,) + tblIdx1, 'destroy'),)
File "/usr/local/lib/python3.5/dist-packages/pysnmp/smi/instrum.py", line 256, in writeVars
return self.flipFlopFsm(self.fsmWriteVar, varBinds, acInfo)
File "/usr/local/lib/python3.5/dist-packages/pysnmp/smi/instrum.py", line 221, in flipFlopFsm
rval = f(tuple(name), val, idx, acInfo)
File "<string>", line 499, in writeTest
File "<string>", line 1177, in writeTest
File "<string>", line 1154, in __delegate
File "<string>", line 1138, in __manageColumns
File "<string>", line 837, in createTest
File "<string>", line 737, in createTest
File "<string>", line 624, in setValue
File "<string>", line 48, in setValue
File "/usr/local/lib/python3.5/dist-packages/pysnmp/proto/rfc1902.py", line 203, in clone
return univ.OctetString.clone(self, *args, **kwargs).setFixedLength(self.getFixedLength())
File "/usr/local/lib/python3.5/dist-packages/pyasn1/type/base.py", line 349, in clone
return self.__class__(value, **initilaizers)
File "/usr/local/lib/python3.5/dist-packages/pyasn1/type/univ.py", line 819, in __init__
base.AbstractSimpleAsn1Item.__init__(self, value, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/pyasn1/type/base.py", line 240, in __init__
value = self.prettyIn(value)
File "<string>", line 364, in prettyIn
File "/usr/local/lib/python3.5/dist-packages/pyasn1/type/univ.py", line 878, in prettyIn
return bytes(value)
TypeError: 'NoneType' object is not iterable
mathewfer@Tools-SRV:~$
@mathewfer One issue is the following (there might be others)...you need to specify the auth_proto and encrypt_proto in your call to snmp_get_oid_v3()
The below is the function definition.
def snmp_get_oid_v3(snmp_device, snmp_user, oid='.1.3.6.1.2.1.1.1.0', auth_proto='sha',
encrypt_proto='aes128', display_errors=True):
So with they way you are currently calling snmp_get_oid_v3() it is going to try to use aes128.
Kirk
Hi Kirk,
I tried to run this script "snmp_helper.py" in https://github.com/ktbyers/pynet/tree/master/snmp But I import error. Your script says "Requires the pysnmp4 library" but I see it is already there.
Do you have any idea what is missing?