'How to fix 'No such instance currently exists at this OID'
I'm just new here and new to pysnmp and am having trouble getting values from some cisco mibs via snmp. I suspect the issue is in loading the MIBs into pysnmp. How do I tell pysnmp to direct its queries to a particular MIB?
I've followed the examples on pysnmp's site and can retrieve the OIDs used in the examples supplied.
I'm using python3 on a windows 2012 server.
This is the example on the pysnmp website for SNMPv2-MIB and works.
def snmp_get(ip, community):
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData(community),
UdpTransportTarget((ip, 161), timeout=1.0, retries=0),
ContextData(),
ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))
)
)
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]))
return
It returns the following when run:
SNMPv2-MIB::sysDescr.0 = Cisco IOS Software, C800 Software (C800-UNIVERSALK9-M), Version 15.4(3)M3, RELEASE SOFTWARE (fc2) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2015 by Cisco Systems, Inc. Compiled Fri 05-Jun-15 16:04 by prod_rel_team
I'm trying to use the CISCO-WAN-3G-MIB to retrieve a bunch of OIDs, one being for c3gGsmLac which is .1.3.6.1.4.1.9.9.661.1.3.2.1.1
When I replace the ObjectIdentity with this OID, I get the following error:
SNMPv2-SMI::enterprises.9.9.661.1.3.2.1.1 = No Such Instance currently exists at this OID.
This is where I am lost because I know that instance exists. I can manually snmpwalk the device for that same OID through net-snmp:
c:\sanitised>snmpwalk -v 2c -c snmpcommunity 1.1.1.1 .1.3.6.1.4.1.9.9.661 .1.3.2.1.1 CISCO-WAN-3G-MIB::c3gGsmLac.13 = Gauge32: 12374
the pysnmp script error suggests it's trying to find that oid under SNMPv2-SMI but it's not under that one, it's under CISCO-WAN-3G-MIB.
How do I tell pysnmp to look under a different MIB?
I've tried specifying that as per some code I found in the documentation:
ObjectType(ObjectIdentity('CISCO-WAN-3G-MIB', 'c3gGsmLac', 13))
and this also works, returning the following output:
CISCO-WAN-3G-MIB::c3gGsmLac.13 = 12374
But this isn't really a solution as that number 13 isn't always number 13. It could vary from device to device and I won't know in advance what it's number is.
I've tried compiling the MIBs into .py files and am storing them in my C:\Program Files\Python37\Lib\site-packages\pysnmp_mibs\ directory but that hasn't done anything. I've also tried copying them into my MIBDIRS environment variable path but that shows no change either, I still get the error.
Can anyone tell me how I go about telling pysnmp to look in CISCO-WAN-3G-MIB for c3gGsmLac? Or how to get it to respond to just the '.1.3.6.1.4.1.9.9.661.1.3.2.1.1' representation?
Thank you
Edit: The below seems to work:
def snmp_get(ip, community):
for (errorIndication,
errorStatus,
errorIndex,
varBinds) in bulkCmd(SnmpEngine(),
CommunityData(community),
UdpTransportTarget((ip, 161)),
ContextData(),
0, 50,
ObjectType(ObjectIdentity('CISCO-WAN-3G-MIB', 'c3gGsmLac')),
ObjectType(ObjectIdentity('CISCO-WAN-3G-MIB', 'c3gGsmCurrentCellId')),
lexicographicMode=False):
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]))
return
Solution 1:[1]
To answer your questions:
SNMPv2-SMI::enterprises.9.9.661.1.3.2.1.1 = No Such Instance currently exists at this OID.
This error should have come from your agent. May be you are missing the tail piece of the OID which identifies managed object instance.
How do I tell pysnmp to look under a different MIB?
You need to pre-load the MIB(s) that contain the objects your agent will respond with.
I've tried specifying that as per some code I found in the documentation:
That effectively loads that MIB.
But this isn't really a solution as that number 13 isn't always number 13. It could vary from device to device and I won't know in advance what it's number is.
Well, it seems you are fetching MIB table objects. Depending on the nature of that table, the indices (e.g. 13) may come and go and may differ. The exact behavior is usually described in the MIB itself (DESCRIPTION clause).
I do not think there is anything in SNMP itself that would let you reliably enumerate these objects. The thing is that they are just the views on the underlying system resources. For example, it could be disk drives or network interfaces. Their presence and their names can be highly unstable over time.
To mitigate this, SNMP has GETNEXT/GETBULK commands which lets you discover what's actually present at this moment.
I'd advise to read the MIB for more hints if they are at all available, and reflect that in your application code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ilya Etingof |
