Skip to Content
ManagerMIB Support

MIB Support

Query a device by name instead of by number.

Give the Manager a MibTree and every method that takes an OID will also take a MIB name. Numeric OIDs are also possible.

from snmpkit.manager import Manager from snmpkit.mib import MibTree tree = MibTree() tree.load_dir("/usr/share/snmp/mibs") async with Manager("192.0.2.1", community="public", mib=tree) as m: print(await m.get("sysDescr.0")) print(await m.get("IF-MIB::ifNumber.0")) async for oid, value in m.walk("ifDescr"): print(m.translate(oid), "=", value) # IF-MIB::ifDescr.1 = lo # IF-MIB::ifDescr.2 = eth0

Load the tree once at startup and keep it.

What accepts a name

Every OID argument: get, get_many, get_next, get_bulk, set, set_many, walk, bulk_walk, get_table, send_trap and send_inform. Names may be bare (ifDescr), module-qualified (IF-MIB::ifDescr), or carry an instance suffix (sysUpTime.0).

A name that is not in the loaded MIBs raises ValueError.

Three helpers are available directly on the Manager:

MethodPurpose
resolve(oid)Name to numeric OID. Numeric input passes through.
translate(oid)Numeric OID to MODULE::name.instance.
format(oid, value)Render a value per its enumeration or DISPLAY-HINT.

SyncManager takes the same mib= argument and has the same three helpers.

Formatting what comes back

format() applies the object’s enumeration or DISPLAY-HINT.

async with Manager("192.0.2.1", community="public", mib=tree) as m: status = await m.get("ifAdminStatus.1") print(m.format("ifAdminStatus.1", status)) # 'up' mac = await m.get("ifPhysAddress.1") print(m.format("ifPhysAddress.1", mac)) # '00:1a:2b:3c:4d:5e'

Naming what a walk returns

translate() names an OID and keeps its instance suffix.

async with Manager("192.0.2.1", community="public") as m: async for oid, value in m.walk(tree["ifDescr"].oid): print(tree.translate(oid), "=", value) # IF-MIB::ifDescr.1 = lo # IF-MIB::ifDescr.2 = eth0

Naming a table’s columns

get_table() takes the row OID and keys each row by column number. The MIB tree maps those numbers back to names.

entry = tree["ifEntry"] columns = {c.numeric_oid[-1]: c for c in entry.columns} async with Manager("192.0.2.1", community="public") as m: rows = await m.get_table(entry.oid) for index, row in sorted(rows.items()): for number, value in sorted(row.items()): column = columns.get(number) if column is not None: print(index, column.name, column.format(value)) # (1,) ifDescr lo # (1,) ifAdminStatus up # (2,) ifDescr eth0

Common OIDs

If you would rather not load MIBs at all, these are the ones you are most likely to want.

System (SNMPv2-MIB)

NameOID
sysDescr1.3.6.1.2.1.1.1.0
sysObjectID1.3.6.1.2.1.1.2.0
sysUpTime1.3.6.1.2.1.1.3.0
sysContact1.3.6.1.2.1.1.4.0
sysName1.3.6.1.2.1.1.5.0
sysLocation1.3.6.1.2.1.1.6.0

Interfaces (IF-MIB::ifTable)

NameOID (table entry)
ifIndex1.3.6.1.2.1.2.2.1.1
ifDescr1.3.6.1.2.1.2.2.1.2
ifType1.3.6.1.2.1.2.2.1.3
ifMtu1.3.6.1.2.1.2.2.1.4
ifSpeed1.3.6.1.2.1.2.2.1.5
ifPhysAddress1.3.6.1.2.1.2.2.1.6
ifAdminStatus1.3.6.1.2.1.2.2.1.7
ifOperStatus1.3.6.1.2.1.2.2.1.8
ifInOctets1.3.6.1.2.1.2.2.1.10
ifOutOctets1.3.6.1.2.1.2.2.1.16

64-bit counters (IF-MIB::ifXTable)

NameOID (table entry)
ifName1.3.6.1.2.1.31.1.1.1.1
ifHCInOctets1.3.6.1.2.1.31.1.1.1.6
ifHCOutOctets1.3.6.1.2.1.31.1.1.1.10
ifHighSpeed1.3.6.1.2.1.31.1.1.1.15
ifAlias1.3.6.1.2.1.31.1.1.1.18

Next Steps

Last updated on