2016-08-03 5 views
0

내 장치 MIBS를로드하고 모든 OIDS를 처리하는 코드를 구현하려고했습니다. 이 한 경우에는 snmp 1.3.6.1.2.1.11의 OID를로드하려고 시도 할 때 특정 OID를로드하려고 시도 할 때 smi가 예외를 throw합니다. '.1.3.6.1.2.1.11.29.0'그러나 이것은 오류 메시지를 생성합니다 '.1.3.6.1.2.1.11.30.0'특정 쿼리에서 pysnmp 오류가 발생했습니다.

는 예외입니다 : 이전 OID가 성공적으로 작동

File "/opt/anaconda/lib/python2.7/site-packages/pysnmp/smi/rfc1902.py", line 859, in resolveWithMib raise SmiError('MIB object %r having type %r failed to cast value %r: %s' % (self.args[0].prettyPrint(), self.__args[0].getMibNode().getSyntax().__class.name, self.__args[1], sys.exc_info()[1])) ;SmiError: MIB object 'SNMPv2-MIB::snmpEnableAuthenTraps.0' having type 'Integer32' failed to cast value Integer32(808466736): ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(), ValueRangeConstraint(-2147483648, 2147483647)), SingleValueConstraint(1, 2)) failed at: "SingleValueConstraint(1, 2) failed at: "808466736"" at Integer32

다음은 오류를 보여주는 샘플 코드입니다. DEVICE_IP를 수정해야합니다. SNMP v1을 실행 중이며 커뮤니티의 공개 대상인 것으로 가정합니다. 그것은 pysnmp 버전을 실행 4.3.2

from pysnmp.entity.rfc3413.oneliner import cmdgen 
from pysnmp.smi.rfc1902 import ObjectIdentity 

DEVICE_IP = 'localhost' 


def get_oid(oid): 
    """ 
    Requires a valid oid as input and retrieves the given OID 
    """ 
    snmp_target = (DEVICE_IP, 161) 
    cmdGen = cmdgen.CommandGenerator() 
    result = None 

    errorIndication, errorStatus, errorIndex, varBindTable =   cmdGen.nextCmd(
     cmdgen.CommunityData('public', mpModel=0), 
     cmdgen.UdpTransportTarget(snmp_target), 
     ObjectIdentity(oid, last=True), 
     lexicographicMode=False 
     ) 

    if errorIndication: 
     print(errorIndication) 
    else: 
     for varBindTableRow in varBindTable: 
      for name, val in varBindTableRow: 
       try: 
        result = str(val) 
       except: 
        raise 
    return result 

# Does not Throw Error 
print get_oid('.1.3.6.1.2.1.11.29.0') 

# Throws Error 
print get_oid('.1.3.6.1.2.1.11.30.0') 

답변

0

귀하의 SNMP 에이전트는 1.3.6.1.2.1.11.30.0 = 808,466,736 OID 1.3.6.1.2.1.11.30.0은 MIB 객체를 식별하는 동안 snmpEnableAuthenTraps으로 대응 두 값 유형 INTEGER의 허용 : 1, 여기

2.은 SNMPv2-MIB에서 공식적인 정의입니다 :

snmpEnableAuthenTraps OBJECT-TYPE 
    SYNTAX  INTEGER { enabled(1), disabled(2) } 
    ... 

그래서이 시간 pysnmp가 옳은 일을하는 것 - 그것은 당신을 보호한다 의미가없는 값에서. 이 문제의 근본 원인은 MIB 개체에 잘못된 값을 보내는 SNMP 에이전트입니다.

관련 문제