我配置編譯器在哪裏尋找ASN1的MIB如下的默認位置:PySNMP - 編譯的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')))
)
它工作得很好。
所以我的問題是編譯後的MIB(.py)放在PySMI自動解析asn1 MIB之後?在上述情況下,我沒有在默認位置$HOME/.pysnmp/mibs
找到它們。
以及如何告訴pysnmp/pysmi在哪裏保留自動生成的.py文件。
我不想在每個get/set調用中使用addMibSource()
。 addMibCompiler()
只適用於/ usr/share/snmp/mibs,不適用於用戶目錄。
想知道我在這裏失蹤。感謝幫助。
請註明您使用的是pysnmp版本? –
pysnmp 4.3.2版本 – krish