Handling non-standard row identifier in SNMP reponses

40 Views Asked by At

I'm querying data from a wide variety of routers, including several Draytek ones.

The Draytek routers give output below when querying IF-MIB::ifTable with numeric OID in snmp-walk.

$ snmpwalk -On -v 2c -c <COMMUNITY> <HOST> .1.3.6.1.2.1.2.2.1
.1.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
.1.3.6.1.2.1.2.2.1.1.4 = INTEGER: 4
.1.3.6.1.2.1.2.2.1.1.5 = INTEGER: 5
.1.3.6.1.2.1.2.2.1.1.6 = INTEGER: 6
.1.3.6.1.2.1.2.2.1.1.7 = INTEGER: 7
.1.3.6.1.2.1.2.2.1.1.8 = INTEGER: 8
.1.3.6.1.2.1.2.2.1.1.20.101.1 = INTEGER: 20
.1.3.6.1.2.1.2.2.1.1.21.101.1 = INTEGER: 21
.1.3.6.1.2.1.2.2.1.1.22.101.1 = INTEGER: 22
.1.3.6.1.2.1.2.2.1.2.1 = STRING: LAN
.1.3.6.1.2.1.2.2.1.2.4 = STRING: VDSL
.1.3.6.1.2.1.2.2.1.2.5 = STRING: Resrved
.1.3.6.1.2.1.2.2.1.2.6 = STRING:
.1.3.6.1.2.1.2.2.1.2.7 = STRING:
.1.3.6.1.2.1.2.2.1.2.8 = STRING:
.1.3.6.1.2.1.2.2.1.2.20.101.1 = STRING: WAN1
.1.3.6.1.2.1.2.2.1.2.21.101.1 = STRING: WAN2
.1.3.6.1.2.1.2.2.1.2.22.101.1 = STRING: LAN_PORT1
(...)

Notice how the row identifier on last 3 interfaces is in the <...>.x.101.1 format, instead of just <...>.x. Also notice how ifIndex value for those interfaces does not have the 101.1 suffix.

I am extending an existing tool that uses PySNMP (the pysnmplib fork, to be precise). PySNMP is not happy at all with the <...>.x.101.1 format when using lookupMib=True.

pysnmp.smi.error.SmiError: Excessive instance identifier sub-OIDs left at MibTableRow((1, 3, 6, 1, 2, 1, 2, 2, 1), None): 101.1

What is the best way to make this work?

The only way I found so far is to use lookupMib=False and do MIB resolution on individual rows after the fact, on a truncated ObjectName[:11]. It does feel extremely dirty though.

0

There are 0 best solutions below