[英]SNMP sysObjectID not translated when using Python3 easysnmp module
When I query SNMP sysObjectID
using easysnmp
module, then returned value is in numerical notation: 当我使用easysnmp
模块查询SNMP sysObjectID
,返回的值是数字表示法:
$ python3
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from easysnmp import Session
>>> session = Session(hostname="r1", community='public', version=2)
>>> session.get('sysObjectID.0')
<SNMPVariable value='.1.3.6.1.4.1.2636.1.1.1.2.21' (oid='sysObjectID', oid_index='0', snmp_type='OBJECTID')>
>>>
However, this does not seem to be because easysnmp
is not able to find the correct MIB file. 但是,这似乎并不是因为easysnmp
无法找到正确的MIB文件。 When I put the commands above into a file and execute it with strace
, then correct MIB is accessed: 当我将上面的命令放入一个文件并使用strace
执行它时,访问正确的MIB:
$ strace 2>&1 -f -e open python3 snmp_test.py | grep mib-jnx-chas-defines.txt
open("/usr/share/snmp/mibs/JuniperMibs_from_Juniper/mib-jnx-chas-defines.txt", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOTDIR (Not a directory)
open("/usr/share/snmp/mibs/JuniperMibs_from_Juniper/mib-jnx-chas-defines.txt", O_RDONLY) = 4
open("/usr/share/snmp/mibs/JuniperMibs_from_Juniper/mib-jnx-chas-defines.txt", O_RDONLY) = 3
$
I can double-check this using snmpget
: 我可以使用snmpget
仔细检查:
$ snmpget -v 2c -c public r1 sysObjectID.0
SNMPv2-MIB::sysObjectID.0 = OID: JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameMX960
$ strace 2>&1 -f -e open snmpget -v 2c -c public r1 sysObjectID.0 | grep mib-jnx-chas-defines.txt
open("/usr/share/snmp/mibs/JuniperMibs_from_Juniper/mib-jnx-chas-defines.txt", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOTDIR (Not a directory)
open("/usr/share/snmp/mibs/JuniperMibs_from_Juniper/mib-jnx-chas-defines.txt", O_RDONLY) = 4
open("/usr/share/snmp/mibs/JuniperMibs_from_Juniper/mib-jnx-chas-defines.txt", O_RDONLY) = 3
$
Still, just to be sure, I set the os.environ['MIBDIRS']
, os.environ['MIBS']
and os.environ['PREFIX']
to same values as I see when I execute the snmpget -Dinit_mib -m ALL -v 2c -c public r1 sysObjectID.0
command, but this does not help either. 不过,为了确定,我将os.environ['MIBDIRS']
, os.environ['MIBS']
和os.environ['PREFIX']
为与执行snmpget -Dinit_mib -m ALL -v 2c -c public r1 sysObjectID.0
时相同的值snmpget -Dinit_mib -m ALL -v 2c -c public r1 sysObjectID.0
命令,但这也无济于事。
What might cause this? 什么可能导致这个?
This is because the value at the OID sysObjectID.0
is just being treated as a value. 这是因为OID sysObjectID.0
值只是被视为一个值。 It looks like the use_sprint_value
option enables the extra formatting on the return value: 看起来use_sprint_value
选项可以在返回值上启用额外的格式:
>>> session = Session(hostname="abc", community='public', version=2, use_long_names=True, use_sprint_value=True)
>>> session.get('sysObjectID.0')
<SNMPVariable value='.iso.org.dod.internet.private.enterprises.2435.2.3.9.1' (oid='.iso.org.dod.internet.mgmt.mib-2.system.sysObjectID', oid_index='0', snmp_type='OBJECTID')>
Clearly the use_long_names
option is also helpful to show the expanded name, though I don't have all the MIBs required to decode this example. 显然, use_long_names
选项也有助于显示扩展名称,但我没有解码此示例所需的所有MIB。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.