2016-08-03 16 views
0

デバイスMIBSをロードしてすべてのOIDSを処理するコードを実装しようとしています。この1つのケースでは、snmp 1.3.6.1.2.1.11のOIDをロードしようとすると、特定のOIDをロードしようとしたときにsmiが例外をスローします。 「.1.3.6.1.2.1.11.29.0' は、この1はエラーメッセージを生成し」.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 = 808466736 OID 1.3.6.1.2.1.11.30.0は、MIBオブジェクトを識別しながらsnmpEnableAuthenTrapsと答えここでは1と2

はSNMPv2の-MIBからの正式な定義である: - それはあなたをシールド

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

ので、この時間pysnmpは正しいことを行うように思わ許可のみ二つの値を持つタイプINTEGERの意味をなさない値から。この問題の根本原因は、MIBオブジェクトの不正な値を送信するSNMPエージェントです。

関連する問題