2016-07-04 8 views
0

Ich habe eine benutzerdefinierte MIB-Datei syzf-alarms.mib. Als ich mibdump.py verwenden pysnmp unterstützt Python-Modul mit mibdump.py ~/syzf-ALARMS zu erzeugen, erhalte ich:PYSNMP 4.3.2 Problem mit mibdump.py Ausgabe

Source MIB repo 
sitories: file:///home/sbhattac, file:///usr/share/snmp/mibs, http://mibs.snmplabs.com/asn1/@[email protected] 
Borrow missing/failed MIBs from: http://mibs.snmplabs.com/pysnmp/notexts/@[email protected] 
Existing/compiled MIB locations: pysnmp.smi.mibs, pysnmp_mibs 
Compiled MIBs destination directory: /home/sbhattac/.pysnmp/mibs 
MIBs excluded from code generation: RFC-1212, RFC-1215, RFC1065-SMI, RFC1155-SMI, RFC1158-MIB, RFC1213-MIB, SNMP-FRAMEWORK-MIB, SNMP-TARGET-MIB, SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC, SNMPv2-TM, TRANSPORT-ADDRESS-MIB 
MIBs to compile: syzf-ALARMS 
Destination format: pysnmp 
Parser grammar cache directory: not used 
Also compile all relevant MIBs: yes 
Rebuild MIBs regardless of age: no 
Do not create/update MIBs: no 
Byte-compile Python modules: yes (optimization level 0) 
Ignore compilation errors: no 
Generate OID->MIB index: no 
Generate texts in MIBs: no 
Try various filenames while searching for MIB module: yes 
Created/updated MIBs: syzf-ALARMS 
Pre-compiled MIBs borrowed: 
Up to date MIBs: SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC 
Missing source MIBs: 
Ignored MIBs: 
Failed MIBs: 

Nun erzeugt er eine syzf-alarms.py/pyc Datei auf home/sbhattac/.pysnmp/mibs.

Jetzt versuche ich, dieses Modul in meinem Code zu verwenden:

errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(cmdgen.CommunityData('public'),cmdgen.UdpTransportTarget(('localhost', 161)), cmdgen.ObjectIdentity('1, 3, 6, 1, 4, 1, 211, 1, 24, 11, 2, 1, 1, 7, 1, 3, 3, 1').addMibSource('/home/sbhattac/.pysnmp/mibs', 'syzf-ALARMS')) 

ich einen Fehler wie diesen bin immer:

File "/usr/local/lib/python2.7/site-packages/pysnmp/smi/builder.py", line 130, in _init 
    p = __import__(self._srcName, globals(), locals(), ['__init__']) 
File "syzf-ALARMS.py", line 8, in <module> 
    (Integer, ObjectIdentifier, OctetString,) = mibBuilder.importSymbols("ASN1", "Integer", "ObjectIdentifier", "OctetString") 
NameError: name 'mibBuilder' is not defined 

Was ist der Grund sein könnte? Sind die obigen Schritte in Ordnung?

Antwort

0

Wenn Sie die neueste pysnmp verwenden, sollten Sie den Code wie folgt aussehen:

from pysnmp.hlapi import * 

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(), 
      CommunityData('public'), 
      UdpTransportTarget(('localhost', 161)), 
      ContextData(), 
      ObjectType(ObjectIdentity('syzf-ALARMS', 'someObject', 0))) 
) 

Wo Someobject bezieht sich auf einen skalaren MIB-Objekt (OBJECT-TYPE) Ihrer Wahl in Ihrem MIB definiert.

Sie müssen den Pfad zu Ihrem MIB-Modul nicht angeben, wenn es sich in ~/.pysnmp/mibs/ befindet - dieser Pfad ist in pysnmp fest verdrahtet.

Sie können auch explizite mibdump.py Kompilierungsphase weglassen, da das neueste Pysnmp MIB-Kompilierungsmodul (Pysmi) automatisch für Ihre ASN.1-MIB-Quelle aufruft. Möglicherweise müssen Sie den Pfad zu ASN.1-MIBs über addAsn1MibSource() angeben, wie erläutert here.

+0

Danke für die Antwort. Könnten Sie mir bitte mitteilen, welche Version von mibvariable oder ObjectType (ObjectIdentity()) sinnvoll ist? – sbhatta

+0

Es ist ratsam, ObjectType (ObjectIdentity) zu verwenden. Der MibVariable-Ansatz ist veraltet und wird nur aus Gründen der Abwärtskompatibilität unterstützt. –