PySNMP Short OID Error Trying To Translate OIDs using MIB Textual Conventions

此生再无相见时 提交于 2020-01-05 14:03:24

问题


I am using the method described in the issue Translate OID value pairs from MIB textual convention using pysnmp to translate OID and OID values according to MIB Textual Conventions.

Using a test OID and test OID value my code is as follows:

from pysnmp.smi import builder, view
from pysnmp.entity.rfc3413.oneliner import mibvar
from pysnmp.proto import rfc1902
from pyasn1.type import univ

mibBuilder = builder.MibBuilder()
mibPath = mibBuilder.getMibSources() + (builder.DirMibSource('/home/rong/NOP_Dev/test'),)
mibBuilder.setMibSources(*mibPath)
mibBuilder.loadModules('NORTEL-ALARM-EXT-MIB')
mibViewController = view.MibViewController(mibBuilder)

varName = mibvar.MibVariable(univ.ObjectIdentifier('1.3.6.1.4.1.562.29.6.1.1.1.1')).resolveWithMib(mibViewController)
print(varName.getMibNode().getSyntax().clone(1).prettyPrint())

When I run my code I get the follow error:

Traceback (most recent call last):
  File "./pysnmp_test.py", line 82, in <module>
    varName = mibvar.MibVariable(univ.ObjectIdentifier('1.3.6.1.4.1.562.29.6.1.1.1.1')).resolveWithMib(mibViewController)
  File "/home/rong/NOP_Dev/lib/python3.4/site-packages/pysnmp/entity/rfc3413/oneliner/mibvar.py", line 169, in resolveWithMib
    self.__indices = rowNode.getIndicesFromInstId(suffix)
  File "<string>", line 1076, in getIndicesFromInstId
  File "<string>", line 899, in setFromName
pysnmp.smi.error.SmiError: Short OID for index NnExtAlarmEventType()

The Textual-Convention is as follows:

NnExtAlarmEventType ::= TEXTUAL-CONVENTION
    STATUS       current
    DESCRIPTION
         "Nortel version of IANA Event Type"
    SYNTAX       INTEGER
          {
          other  (1),
          communicationsAlarm  (2),
          qualityOfServiceAlarm  (3),
          processingErrorAlarm  (4),
          equipmentAlarm  (5),
          environmentalAlarm  (6),
          integrityViolation  (7),
          operationalViolation  (8),
          physicalViolation  (9),
          securityServiceOrMechanismViolation  (10),
          timeDomainViolation (11)
          }

Help with this error would be much appreciated!


回答1:


I could not locate the NORTEL-ALARM-EXT-MIB therefore I can't reproduce your problem.

In general that error means that the OID you referred to (1.3.6.1.4.1.562.29.6.1.1.1.1) belongs to some SNMP table. That table has index/indices (INDEX clause), one of those indices has a syntax of NnExtAlarmEventType (e.g. INTEGER). But the OID you given is incomplete in the sense that it does not contain all sub-OIDs that encode that index. The solution is to either remove some trailing sub-OIDs or add some more.

Probably pysnmp should be hardened in that regard as well to ignore such situations and returning unparsed part of the OID as-is.

BTW, you may consider trying the latest pysnmp to simplify your code.



来源:https://stackoverflow.com/questions/27224002/pysnmp-short-oid-error-trying-to-translate-oids-using-mib-textual-conventions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!