Is it possible to catch errors (for instance due to timeout) with net-snmp in python?
I am using this code:
import netsnmp
import pprint
session = netsnmp.Session(Version = 2, DestHost='192.168.0.1',
Community='public', Timeout=10000, Retries=1, UseNumeric=1)
oid_obj = netsnmp.VarList(netsnmp.Varbind('.1.3.6.1.2.1.2.2.1.1'))
value_obj = session.walk(oid_obj)
# print the result and the error codes:
pprint.pprint(value_obj)
print("Error status: ", session.ErrorStr, session.ErrorNum, session.ErrorInd)
Due to short timeout I get incomplete results - which is fine (note that timeout is in microseconds). What is not fine is that I get no error indication:
('1001', '1002', '1003')
('Error status: ', '', 0, 0)
Am I looking in the wrong place?
This is what I am using: (installed as Debian package)
Package: libsnmp-python
Version: 5.4.3~dfsg-2
Homepage: http://net-snmp.sourceforge.net/
I would appreciate some help, or even advice on which SNMP library to take (if Net-SNMP doesn't handle errors properly).
Prior to 5.4.4 there was a bug in Net-SNMP python bindings (didn't return error codes) - upgrade solved the issue. Hope it helps someone.