내 장치 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')