I'm writing a python script for an SNMP walk and want to print out the variable names along with their associated values. The code I'm currently using gives the numerical OIDs and their values. I have the MIB file - is there a way to output the variable names?
This is the code I'm using:
def walk_mib(ipaddress, oid):
for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget((ipaddress, 161)),
ContextData(),
ObjectType(ObjectIdentity(oid)),
):
if not errorIndication and not errorStatus:
for varBind in varBinds:
result=' = '.join([x.prettyPrint() for x in varBind])
print(result)
walk_mib('<ip address>', start_oid)
It gives output like this: SNMPV2-SMI::[OID] = [value] What I want is something like this: SNMPV2-SMI::[variableName] = [value]
People do need to know which OID you are now WALKing by, so as to answer this question better.
In case the OID is under a private enterprise (for example Cisco related), you need to explicitly load the MIB document,
You can then pass such an
snmpEngineobject tonextCmd.