如何修复“此OID当前不存在此类实例”

2024-07-04 17:08:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新来的,对pysnmp也不熟悉,我很难通过snmp从一些cisco mib中获取值。我怀疑问题出在将mib加载到pysnmp中。如何告诉pysnmp将其查询定向到特定的MIB?在

我遵循了pysnmp站点上的示例,并可以检索所提供示例中使用的oid。在

我在Windows2012服务器上使用python3。在

这是pysnmp网站上SNMPv2 MIB的示例。在

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

它在运行时返回以下信息:

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

我尝试使用CISCO-WAN-3G-MIB来检索一堆oid,其中一个是针对c3gGsmLac的,它是.1.3.6.1.4.1.9.9.661.1.3.2.1.1

当我用这个OID替换ObjectIdentity时,我得到以下错误:

SNMPv2-SMI::enterprises.9.9.661.1.3.2.1.1 = No Such Instance currently exists at this OID.

这就是我迷失的地方,因为我知道实例的存在。 我可以通过net-snmp为同一个OID手动snmpwalk设备:

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

pysnmp脚本错误表明它正在尝试在SNMPv2 SMI下找到该oid,但它不在该osi下,而是在CISCO-WAN-3G-MIB下。在

如何告诉pysnmp在不同的MIB下查找?在

我试着根据我在文档中找到的一些代码指定:

^{pr2}$

这同样有效,返回以下输出:

CISCO-WAN-3G-MIB::c3gGsmLac.13 = 12374

但这并不是一个真正的解决方案,因为数字13并不总是13。它可能因设备而异,我不会事先知道它的编号。在

我尝试过将mib编译成.py文件,并将它们存储在我的C:\Program files\Python37\Lib\site packages\pysnmp_MIBs\目录中,但没有做任何事情。我也尝试过将它们复制到MIBDIRS环境变量path中,但是也没有改变,我仍然得到错误。在

有人能告诉我如何让pysnmp在CISCO-WAN-3G-MIB中查找c3gGsmLac?或者如何让它只响应'.1.3.6.1.4.1.9.9.661.1.3.2.1.1'表示?在

谢谢你

编辑:以下似乎有用:

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

Tags: incommunityipforciscosnmpmibprint
1条回答
网友
1楼 · 发布于 2024-07-04 17:08:33

回答您的问题:

SNMPv2-SMI::enterprises.9.9.661.1.3.2.1.1 = No Such Instance currently exists at this OID.

这个错误应该是你的经纪人造成的。可能是您缺少标识托管对象实例的OID的尾部。在

How do I tell pysnmp to look under a different MIB?

您需要pre-load包含代理将响应的对象的MIB。在

I've tried specifying that as per some code I found in the documentation:

有效地加载了那个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.

好吧,看起来你在获取MIB表对象。根据该表的性质,指数(例如13)可能来去匆匆,也可能有所不同。确切的行为通常在MIB本身(DESCRIPTION子句)中描述。在

我认为SNMP本身没有任何东西可以让您可靠地枚举这些对象。问题是它们只是对底层系统资源的视图。例如,它可以是磁盘驱动器或网络接口。他们的存在和他们的名字会随着时间的推移变得非常不稳定。在

为了缓解这种情况,SNMP有GETNEXT/GETBULK命令,可以让您发现当前实际存在的内容。在

我建议阅读MIB以获得更多的提示,如果它们可用的话,并在应用程序代码中反映这一点。在

相关问题 更多 >

    热门问题