I'm new to both pysnmp and snmp, and I'm trying to get a simple script to dump stats from two routers on my network (an Airport Extreme, and Tomato Firmware router).
This code is (from online examples) works, but without friendly names:
from pysnmp.entity.rfc3413.oneliner import cmdgen
cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('router', 161)),
cmdgen.MibVariable('IF-MIB', '').loadMibs(),
lexicographicMode=True, maxRows=100,
ignoreNonIncreasingOid=True
)
if errorIndication:
print(errorIndication)
else:
if errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
)
)
else:
for varBindTableRow in varBindTable:
for name, val in varBindTableRow:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
Produces this output:
python foo.py
1.3.6.1.2.1.2.1.0 = 8
1.3.6.1.2.1.2.2.1.1.1 = 1
1.3.6.1.2.1.2.2.1.1.2 = 2
....
I'm hoping to produce output like snmpwalk:
snmpwalk router -c public -v2c
SNMPv2-MIB::sysDescr.0 = STRING: Linux router 2.6.22.19 #20 Tue Apr 2 13:54:22 ICT 2013 mips
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (55888889) 6 days, 11:14:48.89
....
I believe this is just a question of making the MIBs properly available. I have pysnmp-mibs installed, but I haven't yet figured out how to make use of it.