【发布时间】:2016-10-03 21:09:25
【问题描述】:
-
我将编译器配置为查找 asn1 MIB 的位置如下:
compiler.addMibCompiler(mibBuilder, sources=['/usr/share/snmp/mibs']) -
然后使用 getCmd() 作为:
errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), CommunityData('private', mpModel=0), UdpTransportTarget(('192.168.56.20', '161')), ContextData(), ObjectType(ObjectIdentity('VLAN-MIB','InterfaceMode',3)))) 我在
$HOME/.pysnmp/mibs中找到了 VLAN-MIB.py,一切正常。
但我想将 asn1 MIB 的位置修改为我的本地文件夹。说:
/home/krish/mibs
我尝试了两种不同的方式:
-
这个:
compiler.addMibCompiler(mibBuilder, sources=['/home/krish/mibs'])` -
这个:
errorIndication, errorStatus, errorIndex, varBinds = next( getCmd(SnmpEngine(), CommunityData('private', mpModel=0), UdpTransportTarget(('192.168.56.20', '161')), ContextData(), ObjectType(ObjectIdentity('VLAN-MIB','InterfaceMode',3).addAsn1MibSource('/home/krish/mibs'))) )
无论哪种方式,我都会收到错误消息,提示找不到 VLAN-MIB。
但是如果我自己离线编译并将VLAN-MIB.py文件放在指定目录下为:
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData('private', mpModel=0),
UdpTransportTarget(('192.168.56.20', '161')),
ContextData(),
ObjectType(ObjectIdentity('VLAN-MIB','InterfaceMode',3).addMibSource('/home/krish/mibs')))
)
效果很好。
所以我的问题是,在 PySMI 自动解析 asn1 MIB 之后,编译的 MIB (.py) 放在哪里?在上述情况下,我没有在默认位置$HOME/.pysnmp/mibs 找到它们。
以及如何告诉 pysnmp/pysmi 将自动生成的 .py 文件保存在哪里。
而且我不想在每个 get/set 调用中使用addMibSource()。 addMibCompiler() 仅适用于 /usr/share/snmp/mibs,不适用于用户目录。
想知道我在这里缺少什么。感谢帮助。
【问题讨论】:
-
请指定您使用的pysnmp版本?
-
pysnmp 版本 4.3.2
标签: pysnmp