简体   繁体   English

尝试使用pysnmp加载自定义MIB文件时出错

[英]Errors trying to load custom MIB file with pysnmp

To interface with a Cordex of Alpha Technologies, I need to use the SNMP protocol. 要与Alpha Technologies的Cordex接口,我需要使用SNMP协议。 I've been going through the documentation and examples from pysnmp in order to get some aspects working, and I have particular issues when using external MIB files from alpha technologies. 我一直在浏览pysnmp的文档和示例,以使某些方面起作用,并且在使用来自alpha技术的外部MIB文件时遇到一些特殊问题。 My first test was the following: 我的第一个测试如下:

from pysnmp.hlapi import *
from pysnmp.smi import builder, view, compiler, rfc1902
from pysnmp import debug
#debug.setLogger(debug.Debug('all'))
debug.setLogger(debug.Debug('msgproc', 'mibbuild'))
mibBuilder = builder.MibBuilder()

mibViewController = view.MibViewController(mibBuilder)
test = ObjectIdentity('SNMPv2-MIB', 'sysDescr').addAsn1MibSource('file:///C:/Users/SLN9000/Repositories/cordex/MIB/@mib@')
test.resolveWithMib(mibViewController)
test.getOid()

when I do this it correctly prints out the correct OID: 当我这样做时,它会正确打印出正确的OID:

>>> ObjectName('1.3.6.1.2.1.1.1')

However, when looking at the debug logs, it seems to be using the compiled MIB files from the pysnmp library instead of the ASN.1 files located in "C:/Users/SLN9000/Repositories/cordex/MIB/@mib@". 但是,当查看调试日志时,似乎正在使用pysnmp库中的已编译MIB文件,而不是位于“ C:/ Users / SLN9000 / Repositories / cordex / MIB / @ mib @”中的ASN.1文件。 When I do something similar for the MIB file from Alpha technologies 当我对Alpha技术的MIB文件执行类似操作时

from pysnmp.hlapi import *
from pysnmp.smi import builder, view, compiler, rfc1902
from pysnmp import debug
#debug.setLogger(debug.Debug('all'))
debug.setLogger(debug.Debug('msgproc', 'mibbuild'))
mibBuilder = builder.MibBuilder()

mibViewController = view.MibViewController(mibBuilder)
test = ObjectIdentity('03409602D__Alpha_System_Controller', 'dcpower', 1).addAsn1MibSource('file:///C:/Users/SLN9000/Repositories/cordex/MIB/')
test.resolveWithMib(mibViewController)
test.getOid()

It fails at the step test.resolveWithMib(mibViewController) with the error 它在步骤test.resolveWithMib(mibViewController)失败,并显示错误

pysnmp.smi.error.MibNotFoundError: 03409602D__Alpha_System_Controller compilation error(s): missing pysnmp.smi.error.MibNotFoundError:03409602D__Alpha_System_Controller编译错误:丢失

It's not completely clear to me what I am doing wrong. 我还不清楚我在做什么错。 The MIB file I am using can be downloaded from here . 我正在使用的MIB文件可以从此处下载。 Any help is appreciated! 任何帮助表示赞赏!

My current workaround is to manually compile all the MIB files with the mibdump.py tool. 我当前的解决方法是使用mibdump.py工具手动编译所有MIB文件。 Not really scalable, but at least it allows me to continue my work. 并不是真正可扩展的,但是至少它允许我继续工作。

It looks like the canonical name of the MIB they ship in 03409602D__Alpha_System_Controller file is AlphaPowerSystem-MIB (from first line of that file). 看起来他们在03409602D__Alpha_System_Controller文件中AlphaPowerSystem-MIB的规范名称是AlphaPowerSystem-MIB (从该文件的第一行开始)。 I think you should better rename this file into the canonical name to simplify matters. 我认为您最好将此文件重命名为规范名称,以简化事务。

Other files in that .zip archive seem to be copies of standard SNMP MIBs. .zip存档中的其他文件似乎是标准SNMP MIB的副本。 It is okay that pysnmp uses these of its own -- these core MIBs are implementation-specific. pysnmp可以自己使用它们-这些核心MIB是特定于实现的。 Therefore you do not need the rest of the MIBs from that .zip. 因此,您不需要该.zip中的其余MIB。

Once you are done with the above, you should be able to perform MIB query like this: 完成上述操作后,您应该可以执行如下的MIB查询:

test = ObjectIdentity('AlphaPowerSystem-MIB', 'dcpower', 1).addAsn1MibSource('file:///C:/Users/SLN9000/Repositories/cordex/MIB/')

It works with the snmptranslate.py tool which is based on pysnmp: 它可以与基于pysnmp的snmptranslate.py工具一起使用:

$ snmptranslate.py -On  AlphaPowerSystem-MIB::dcpower

1.3.6.1.4.1.7309.4 1.3.6.1.4.1.7309.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM