2013-08-20 42 views
0

嘗試加載CISCO-RTTMON-MIB時,我在PySNMP構建器中不斷收到此錯誤。下面的代碼適用於迄今爲止我嘗試過的所有其他mib,但是這個代碼陷入了困境。這也是我第一次嘗試走完整個表格(rttMonStats),所以我可能只是做錯了。下面是我做了什麼:PySNMP Builder無法加載CISCO-RTTMON-MIB

我下載的所有文件的版本2列here下:http://tools.cisco.com/Support/SNMP/do/BrowseMIB.do?local=en&mibName=CISCO-RTTMON-MIB

標記爲「非Cisco MIB」的那些,我在別處找到了在網上與「下載搜索。MIB_NAME我跑的這些每一個通過集結pysnmp-MIB喜歡:

build-pysnmp-mib MIB_NAME.my > MIB_NAME.py. 

我再複製所有* .py文件到/ opt /應用程序的名字/ MIB中/

這裏是snmpcommands相關DEF .py:

def walk(community, ipaddress, mib, oid, index): 
    cmdGen = cmdgen.CommandGenerator() 
    mibBuilder = cmdGen.snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder 
    mibSources = mibBuilder.getMibSources() + (
      builder.DirMibSource('/opt/appname/mibs'), 
      ) 
    mibBuilder.setMibSources(*mibSources) 
    mibBuilder.loadModules() 
    errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
      cmdgen.CommunityData(community, mpModel=0), 
      cmdgen.UdpTransportTarget((ipaddress, 161)), 
      cmdgen.MibVariable(mib, oid, index), 
      lookupValues=True, lookupNames=True 
    ) 

    if errorIndication: 
      print(errorIndication) 
    else: 
      if errorStatus: 
        print('%s at %s' % (
          errorStatus.prettyPrint(), 
          errorIndex and varBinds[int(errorIndex)-1] or '?' 
          ) 
        ) 
      else: 
        result = {} 
        for tableRow in varBindTable: 
          for oid, val in tableRow: 
            result[oid.prettyPrint()] = val.prettyPrint() 

        return json.dumps(result) 

,我稱它像:

>>>import snmpcommands 
>>>snmpcommands.walk('community', 'ip.add.ress', 'CISCO-RTTMON-MIB', 'rttMonStats', '0.0.0.0') 

不過,我得到這個:

>>> snmpcommands.walk('community', 'ip.add.ress', 'CISCO-RTTMON-MIB', 'rttMonStats', '0.0.0.0') 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "snmpcommands.py", line 57, in walk 
    mibBuilder.loadModules() 
    File "/usr/lib/python2.6/site-packages/pysnmp-4.2.4-py2.6.egg/pysnmp/smi/builder.py", line 251, in loadModules 
    'MIB module \"%s\" load error: %s' % (modPath, sys.exc_info()[1]) 
pysnmp.smi.error.SmiError: MIB module "/opt/appname/mibs/CISCO-RTTMON-MIB.py" load  error:  ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(), ValueSizeConstraint(0, 65535)), ValueSizeConstraint(0, 255)), ValueSizeConstraint(1, 64)) failed at: "ValueSizeConstraint(1, 64) failed at: """ at SnmpAdminString 

我很新的PySNMP所以我猜這個問題是它希望從SNMP-FRAMEWORK-MIB中獲取SnmpAdminString中的值,並且該值爲空。我只是不知道如何解決它。

回答

1

它看起來像一個空字符串作爲SnmpAdminString(「」)初始化程序在CISCO-RTTMON-MIB.py。這似乎違反了SnmpAdminString約束,最終導致了一個異常。所以我想grep CISCO- RTTMON- MIB.py爲空的SnmpAdminString初始值設定項,並用合適的值(1-64八位字節)替換它們,或者只刪除空的初始值設定項(例如使其看起來像SnmpAdminString())。

+0

感謝您的回答!我的問題是,他們重新配置我查詢的設備,並停止響應。空串是由於缺乏反應。 –

+0

事實證明你是對的。我發現了幾個SnmpAdminString.clone('')的實例,並在問題重新引入我的項目時將它們替換爲SnmpAdminString.clone('true')。 –