简体   繁体   中英

erroneous net-snmp error handling

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.

Still m getting empty string in ErrorStr in

Working on OEL linux: Installed the following version :

net-snmp-5.5-41.el6_3.1.x86_64

net-snmp-python-5.5-41.el6_3.1.x86_64

net-snmp-utils-5.5-41.el6_3.1.x86_64

net-snmp-libs-5.5-41.el6_3.1.x86_64

Not able to get the ErrorStr for Timeout.

Could some help.

thanks sapamja

在版本5.7.3(从源RPM构建:net-snmp-5.7.3-4.5.src.rpm)中,ErrorNum始终为零,但ErrorStr将具有一个值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM