Python easysnmp module returns the SNMP OID in two parts: oid
and oid_index
. For example, if I walk the ipAddressIfIndex.ipv4
(.1.3.6.1.2.1.4.34.1.3.1
in numerical form) OID:
>>> from easysnmp import Session
>>> session = Session(hostname="r1", community='public', version=2, use_long_names=True, use_sprint_value=True)
>>> session.bulkwalk("ipAddressIfIndex.1")
[<SNMPVariable value='9' (oid='.iso.org.dod.internet.mgmt.mib-2.ip.ipAddressTable.ipAddressEntry.ipAddressIfIndex', oid_index='1.4.192.0.2.1', snmp_type='INTEGER')>,
/* rest of the output is removed for brevity */
>>>
.. then the oid
is .iso.org.dod.internet.mgmt.mib-2.ip.ipAddressTable.ipAddressEntry.ipAddressIfIndex
(or .1.3.6.1.2.1.4.34.1.3
numerically) and oid_id
is 1.4.192.0.2.1
. I would like to shift the returned oid
to right by two so that the oid_id
would be 192.0.2.1
. Is this possible? I have tried with session.bulkwalk("ipAddressIfIndex.1.4")
, session.bulkwalk(("ipAddressIfIndex", "1.4"))
, session.bulkwalk(".1.3.6.1.2.1.4.34.1.3.1.4")
and used various session parameters like use_long_names
or use_enums
, but I'm not able to modify this behavior.
This is obviously not a big issue as I can read the last four fields(for example something like oid_index.split('.')[-4:]
), but maybe there is a trick to shift the "line" between the oid
and oid_index
returned by easysnmp.
question from:
https://stackoverflow.com/questions/65930043/modify-the-part-of-the-oid-returned-in-oid-and-oid-index-by-python-easysnmp 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…