Skip to content
Snippets Groups Projects
Commit 5bdc26e2 authored by Erik Reid's avatar Erik Reid
Browse files

use a ConnectionError instead of assertion for snmp i/o errors

parent 5f15bf0a
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,10 @@ from pysnmp.smi import builder, compiler
RFC1213_MIB_IFDESC = '1.3.6.1.2.1.2.2.1.2'
class SNMPWalkError(ConnectionError):
pass
def _v6address_oid2str(dotted_decimal):
hex_params = []
for dec in re.split(r'\.', dotted_decimal):
......@@ -61,15 +65,19 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover
# cf. http://snmplabs.com/
# pysnmp/examples/hlapi/asyncore/sync/contents.html
assert not engineErrorIndication, (
f'snmp response engine error indication: '
f'{str(engineErrorIndication)} - {agent_hostname}')
assert not pduErrorIndication, 'snmp response pdu error %r at %r' % (
pduErrorIndication,
errorIndex and varBinds[int(errorIndex) - 1][0] or '?')
assert errorIndex == 0, (
'sanity failure: errorIndex != 0, '
'but no error indication')
if engineErrorIndication:
raise SNMPWalkError(
f'snmp response engine error indication: '
f'{str(engineErrorIndication)} - {agent_hostname}')
if pduErrorIndication:
raise SNMPWalkError(
'snmp response pdu error %r at %r' % (
pduErrorIndication,
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
if errorIndex == 0:
raise SNMPWalkError(
'sanity failure: errorIndex != 0, '
'but no error indication')
# varBinds = [
# rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]),x[1])
......@@ -84,7 +92,7 @@ def walk(agent_hostname, community, base_oid): # pragma: no cover
def get_router_snmp_indexes(hostname, community):
for ifc in walk(hostname, community, RFC1213_MIB_IFDESC):
m = re.match(r'.*\.(\d+)$', ifc['oid'])
assert m, 'sanity failure parsing oid: %r' % ifc['oid']
assert m, f'sanity failure parsing oid: {ifc["oid"]}'
yield {
'name': ifc['value'],
'index': int(m.group(1))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment