I am trying to get IF-MIB values via pysnmp, and am getting a No Such Object currently exists at this OID. I'm using code very similar to the example code, however, so I'm not sure what's going wrong. Can anyone see the issue? 1.3.6.1.2.1.2.2.1.6 is supposed to get the IF address (http://oid-info.com/get/1.3.6.1.2.1.2.2.1.6)
from pysnmp.hlapi import *
from pysnmp.smi import builder, view
# snmp.live.gambitcommunications.com
# demo.snmplabs.com
# snmpsim.try.thola.io
# localhost
MIB_VIEW_CONTROLLER = view.MibViewController(builder.MibBuilder())
g = getCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(('127.0.0.1', 161)),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.6')),
lookupNames=True, lookupValues=True)
errorIndication, errorStatus, errorIndex, varBinds = next(g)
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
print("hello")
for varBind in varBinds:
print(type(varBind))
print(' = '.join([x.prettyPrint() for x in varBind]))
You are wrong asking for a getCmd
( Get query ) when the OID
points to an object-type
definition. Choose between getCmd
or nextCmd
( walk operation).
In this case, if you don't know the leaf
of the table of this object, you need to do a walk operation, like that:
from pysnmp.hlapi import *
iterator = nextCmd(
SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(('127.0.0.1', 161)),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.6')),
lookupMib=True, lookupValues=True
)
for response in iterator:
errorIndication, errorStatus, errorIndex, varBinds = response
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
python py37/main.py
SNMPv2-SMI::mib-2.2.2.1.6.1 =
SNMPv2-SMI::mib-2.2.2.1.6.2 = 0x1c697a6253c4
SNMPv2-SMI::mib-2.2.2.1.6.3 = 0x98af6511203d
SNMPv2-SMI::mib-2.2.2.1.6.4 = 0xa0cec8334d92
SNMPv2-SMI::mib-2.2.2.1.6.5 = 0x024247d306f5
SNMPv2-SMI::mib-2.2.2.1.6.6 = 0x02429213f7c0
SNMPv2-SMI::mib-2.2.2.1.6.7 = 0x02427d420a25
SNMPv2-SMI::mib-2.2.2.1.6.8 = 0x0242f5cb5e09
SNMPv2-SMI::mib-2.2.2.1.6.9 = 0x0242c6fba2ad
SNMPv2-SMI::mib-2.2.2.1.6.10 = 0x0242051d57ea
[...]
If you know the leaf to query, put it...in your code ( with getCmd
) like:
ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.6.1')),
For testing and learning porpuses you can help yourself with bash command :snmpwalk -v 1 -c public 127.0.0.1
or
snmpget -v 1 -c public 127.0.0.1 1.3.6.1.2.1.2.2.1.6.1
It will give you tracks