将 pysnmp 数字 oid 输出转换为符号名称
我编写了一个脚本(如下)来测试我在我的一个应用程序中使用 pysnmp 的效果。我需要能够 mib-walk 具有诸如 ifDecr 之类的名称的网络元素,并且我的输出需要引用我查询时使用的相同名称...
from pysnmp.smi import builder, view, error
from pysnmp.entity.rfc3413.oneliner import cmdgen
cmdGen = cmdgen.CommandGenerator()
mibBuilder = builder.MibBuilder()
mibPath = mibBuilder.getMibPath() + ('/opt/python/Models/Network/MIBs',)
mibBuilder.setMibPath(*mibPath)
mibBuilder.loadModules(
'RFC-1213',
)
mibView = view.MibViewController(mibBuilder)
errorIndication, errorStatus, errorIndex, \
varBindTable = cmdGen.nextCmd(
# SNMP v2
cmdgen.CommunityData('test-agent', 'public'),
# Transport
cmdgen.UdpTransportTarget(('192.168.56.131', 161)),
(('', 'ifDescr'),),
)
print varBindTable
问题
当我执行此操作时代码中,pysnmp
正确识别了我的 RFC-1213.py
本地定义中的 ifDecr
;但是,pysnmp
不会将 mib OID 转换为下面输出中的 ifDescr
之类的名称...
问题
我怎样才能pysnmp
将 ObjectName()
实例输出为 ObjectName(ifDescr.1)
而不是对象名称(1.3.6.1.2.1.2.2.1.2.1)
?
[
[(ObjectName(1.3.6.1.2.1.2.2.1.2.1), OctetString('Unit: 1 Slot: 0 Port: 1 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.2), OctetString('Unit: 1 Slot: 0 Port: 2 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.3), OctetString('Unit: 1 Slot: 0 Port: 3 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.4), OctetString('Unit: 1 Slot: 0 Port: 4 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.5), OctetString('Unit: 1 Slot: 0 Port: 5 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.6), OctetString('Unit: 1 Slot: 0 Port: 6 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.7), OctetString('Unit: 1 Slot: 0 Port: 7 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.8), OctetString('Unit: 1 Slot: 0 Port: 8 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.9), OctetString('Unit: 1 Slot: 0 Port: 9 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.10), OctetString('Unit: 1 Slot: 0 Port: 10 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.11), OctetString('Unit: 1 Slot: 0 Port: 11 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.12), OctetString('Unit: 1 Slot: 0 Port: 12 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.13), OctetString('Unit: 1 Slot: 0 Port: 13 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.14), OctetString('Unit: 1 Slot: 0 Port: 14 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.15), OctetString('Unit: 1 Slot: 0 Port: 15 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.16), OctetString('Unit: 1 Slot: 0 Port: 16 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.17), OctetString('Unit: 1 Slot: 0 Port: 17 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.18), OctetString('Unit: 1 Slot: 0 Port: 18 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.19), OctetString('Unit: 1 Slot: 0 Port: 19 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.20), OctetString('Unit: 1 Slot: 0 Port: 20 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.21), OctetString('Unit: 1 Slot: 0 Port: 21 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.22), OctetString('Unit: 1 Slot: 0 Port: 22 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.23), OctetString('Unit: 1 Slot: 0 Port: 23 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.24), OctetString('Unit: 1 Slot: 0 Port: 24 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.25), OctetString(' CPU Interface for Unit: 0 Slot: 5 Port: 1'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.26), OctetString('Link Aggregate 1'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.27), OctetString('Link Aggregate 2'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.28), OctetString('Link Aggregate 3'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.29), OctetString('Link Aggregate 4'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.30), OctetString('Link Aggregate 5'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.31), OctetString('Link Aggregate 6'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.32), OctetString('Link Aggregate 7'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.33), OctetString('Link Aggregate 8'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.38), OctetString('Vl21'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.39), OctetString('Vl22'))]
]
更新
基于 Popper12 答案的明确解决方案是
import string
from pysnmp.smi import builder, view, error
from pysnmp.entity.rfc3413.oneliner import cmdgen
from collections import namedtuple as NT
cmdGen = cmdgen.CommandGenerator()
mibBuilder = builder.MibBuilder()
mibPath = mibBuilder.getMibPath() + ('/opt/python/Models/Network/MIBs',)
mibBuilder.setMibPath(*mibPath)
mibBuilder.loadModules(
'RFC-1213',
)
mibView = view.MibViewController(mibBuilder)
errorIndication, errorStatus, errorIndex, \
varBindTable = cmdGen.nextCmd(
# SNMP v2
cmdgen.CommunityData('test-agent', 'public'),
# Transport
cmdgen.UdpTransportTarget(('192.168.56.131', 161)),
(('', 'ifDescr'),),
)
SNMPObject = NT('SNMPObject', ['modName', 'symName', 'index', 'value'])
if errorIndication:
print errorIndication
else:
if errorStatus:
print '%s at %s\n' % (
errorStatus.prettyPrint(),
varBindTable[-1][int(errorIndex)-1]
)
else:
for varBindTableRow in varBindTable:
for oid, val in varBindTableRow:
(symName, modName), indices = cmdgen.mibvar.oidToMibName(
cmdGen.mibViewController, oid
)
val = cmdgen.mibvar.cloneFromMibValue(
cmdGen.mibViewController, modName, symName, val
)
index = int(string.join(map(lambda v: v.prettyPrint(), indices), '.'))
value = val.prettyPrint()
print SNMPObject._make([modName, symName, index, value])
当我运行它时,我现在得到...
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=1, value="'Unit: 1 Slot: 0 Port: 1 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=2, value="'Unit: 1 Slot: 0 Port: 2 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=3, value="'Unit: 1 Slot: 0 Port: 3 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=4, value="'Unit: 1 Slot: 0 Port: 4 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=5, value="'Unit: 1 Slot: 0 Port: 5 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=6, value="'Unit: 1 Slot: 0 Port: 6 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=7, value="'Unit: 1 Slot: 0 Port: 7 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=8, value="'Unit: 1 Slot: 0 Port: 8 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=9, value="'Unit: 1 Slot: 0 Port: 9 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=10, value="'Unit: 1 Slot: 0 Port: 10 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=11, value="'Unit: 1 Slot: 0 Port: 11 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=12, value="'Unit: 1 Slot: 0 Port: 12 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=13, value="'Unit: 1 Slot: 0 Port: 13 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=14, value="'Unit: 1 Slot: 0 Port: 14 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=15, value="'Unit: 1 Slot: 0 Port: 15 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=16, value="'Unit: 1 Slot: 0 Port: 16 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=17, value="'Unit: 1 Slot: 0 Port: 17 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=18, value="'Unit: 1 Slot: 0 Port: 18 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=19, value="'Unit: 1 Slot: 0 Port: 19 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=20, value="'Unit: 1 Slot: 0 Port: 20 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=21, value="'Unit: 1 Slot: 0 Port: 21 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=22, value="'Unit: 1 Slot: 0 Port: 22 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=23, value="'Unit: 1 Slot: 0 Port: 23 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=24, value="'Unit: 1 Slot: 0 Port: 24 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=25, value="' CPU Interface for Unit: 0 Slot: 5 Port: 1'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=26, value="'Link Aggregate 1'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=27, value="'Link Aggregate 2'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=28, value="'Link Aggregate 3'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=29, value="'Link Aggregate 4'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=30, value="'Link Aggregate 5'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=31, value="'Link Aggregate 6'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=32, value="'Link Aggregate 7'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=33, value="'Link Aggregate 8'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=34, value="'Link Aggregate 9'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=35, value="'Link Aggregate 10'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=36, value="'Link Aggregate 11'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=37, value="'Link Aggregate 12'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=38, value="'Vl21'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=39, value="'Vl22'")
这并不能回答我关于具有符号名称的 ObjectName 实例的确切问题;不过,这确实已经足够好了。
I wrote a script (below) to test how well I could use pysnmp
in one of my applications. I need to be able to mib-walk network elements with names like ifDescr
, and my output needs to reference the same name I queried with...
from pysnmp.smi import builder, view, error
from pysnmp.entity.rfc3413.oneliner import cmdgen
cmdGen = cmdgen.CommandGenerator()
mibBuilder = builder.MibBuilder()
mibPath = mibBuilder.getMibPath() + ('/opt/python/Models/Network/MIBs',)
mibBuilder.setMibPath(*mibPath)
mibBuilder.loadModules(
'RFC-1213',
)
mibView = view.MibViewController(mibBuilder)
errorIndication, errorStatus, errorIndex, \
varBindTable = cmdGen.nextCmd(
# SNMP v2
cmdgen.CommunityData('test-agent', 'public'),
# Transport
cmdgen.UdpTransportTarget(('192.168.56.131', 161)),
(('', 'ifDescr'),),
)
print varBindTable
Problem
When I execute this code, pysnmp
correctly recognizes ifDescr
from my local definition of RFC-1213.py
; however, pysnmp
isn't translating the mib OIDs into names like ifDescr
in the output below...
Question
How can I make pysnmp
output the ObjectName()
instances as ObjectName(ifDescr.1)
instead of ObjectName(1.3.6.1.2.1.2.2.1.2.1)
?
[
[(ObjectName(1.3.6.1.2.1.2.2.1.2.1), OctetString('Unit: 1 Slot: 0 Port: 1 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.2), OctetString('Unit: 1 Slot: 0 Port: 2 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.3), OctetString('Unit: 1 Slot: 0 Port: 3 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.4), OctetString('Unit: 1 Slot: 0 Port: 4 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.5), OctetString('Unit: 1 Slot: 0 Port: 5 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.6), OctetString('Unit: 1 Slot: 0 Port: 6 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.7), OctetString('Unit: 1 Slot: 0 Port: 7 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.8), OctetString('Unit: 1 Slot: 0 Port: 8 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.9), OctetString('Unit: 1 Slot: 0 Port: 9 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.10), OctetString('Unit: 1 Slot: 0 Port: 10 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.11), OctetString('Unit: 1 Slot: 0 Port: 11 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.12), OctetString('Unit: 1 Slot: 0 Port: 12 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.13), OctetString('Unit: 1 Slot: 0 Port: 13 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.14), OctetString('Unit: 1 Slot: 0 Port: 14 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.15), OctetString('Unit: 1 Slot: 0 Port: 15 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.16), OctetString('Unit: 1 Slot: 0 Port: 16 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.17), OctetString('Unit: 1 Slot: 0 Port: 17 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.18), OctetString('Unit: 1 Slot: 0 Port: 18 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.19), OctetString('Unit: 1 Slot: 0 Port: 19 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.20), OctetString('Unit: 1 Slot: 0 Port: 20 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.21), OctetString('Unit: 1 Slot: 0 Port: 21 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.22), OctetString('Unit: 1 Slot: 0 Port: 22 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.23), OctetString('Unit: 1 Slot: 0 Port: 23 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.24), OctetString('Unit: 1 Slot: 0 Port: 24 10G - Level'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.25), OctetString(' CPU Interface for Unit: 0 Slot: 5 Port: 1'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.26), OctetString('Link Aggregate 1'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.27), OctetString('Link Aggregate 2'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.28), OctetString('Link Aggregate 3'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.29), OctetString('Link Aggregate 4'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.30), OctetString('Link Aggregate 5'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.31), OctetString('Link Aggregate 6'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.32), OctetString('Link Aggregate 7'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.33), OctetString('Link Aggregate 8'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.38), OctetString('Vl21'))],
[(ObjectName(1.3.6.1.2.1.2.2.1.2.39), OctetString('Vl22'))]
]
UPDATE
The explicit solution based on Popper12's answer is
import string
from pysnmp.smi import builder, view, error
from pysnmp.entity.rfc3413.oneliner import cmdgen
from collections import namedtuple as NT
cmdGen = cmdgen.CommandGenerator()
mibBuilder = builder.MibBuilder()
mibPath = mibBuilder.getMibPath() + ('/opt/python/Models/Network/MIBs',)
mibBuilder.setMibPath(*mibPath)
mibBuilder.loadModules(
'RFC-1213',
)
mibView = view.MibViewController(mibBuilder)
errorIndication, errorStatus, errorIndex, \
varBindTable = cmdGen.nextCmd(
# SNMP v2
cmdgen.CommunityData('test-agent', 'public'),
# Transport
cmdgen.UdpTransportTarget(('192.168.56.131', 161)),
(('', 'ifDescr'),),
)
SNMPObject = NT('SNMPObject', ['modName', 'symName', 'index', 'value'])
if errorIndication:
print errorIndication
else:
if errorStatus:
print '%s at %s\n' % (
errorStatus.prettyPrint(),
varBindTable[-1][int(errorIndex)-1]
)
else:
for varBindTableRow in varBindTable:
for oid, val in varBindTableRow:
(symName, modName), indices = cmdgen.mibvar.oidToMibName(
cmdGen.mibViewController, oid
)
val = cmdgen.mibvar.cloneFromMibValue(
cmdGen.mibViewController, modName, symName, val
)
index = int(string.join(map(lambda v: v.prettyPrint(), indices), '.'))
value = val.prettyPrint()
print SNMPObject._make([modName, symName, index, value])
When I run that, I now get...
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=1, value="'Unit: 1 Slot: 0 Port: 1 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=2, value="'Unit: 1 Slot: 0 Port: 2 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=3, value="'Unit: 1 Slot: 0 Port: 3 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=4, value="'Unit: 1 Slot: 0 Port: 4 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=5, value="'Unit: 1 Slot: 0 Port: 5 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=6, value="'Unit: 1 Slot: 0 Port: 6 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=7, value="'Unit: 1 Slot: 0 Port: 7 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=8, value="'Unit: 1 Slot: 0 Port: 8 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=9, value="'Unit: 1 Slot: 0 Port: 9 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=10, value="'Unit: 1 Slot: 0 Port: 10 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=11, value="'Unit: 1 Slot: 0 Port: 11 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=12, value="'Unit: 1 Slot: 0 Port: 12 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=13, value="'Unit: 1 Slot: 0 Port: 13 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=14, value="'Unit: 1 Slot: 0 Port: 14 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=15, value="'Unit: 1 Slot: 0 Port: 15 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=16, value="'Unit: 1 Slot: 0 Port: 16 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=17, value="'Unit: 1 Slot: 0 Port: 17 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=18, value="'Unit: 1 Slot: 0 Port: 18 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=19, value="'Unit: 1 Slot: 0 Port: 19 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=20, value="'Unit: 1 Slot: 0 Port: 20 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=21, value="'Unit: 1 Slot: 0 Port: 21 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=22, value="'Unit: 1 Slot: 0 Port: 22 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=23, value="'Unit: 1 Slot: 0 Port: 23 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=24, value="'Unit: 1 Slot: 0 Port: 24 10G - Level'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=25, value="' CPU Interface for Unit: 0 Slot: 5 Port: 1'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=26, value="'Link Aggregate 1'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=27, value="'Link Aggregate 2'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=28, value="'Link Aggregate 3'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=29, value="'Link Aggregate 4'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=30, value="'Link Aggregate 5'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=31, value="'Link Aggregate 6'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=32, value="'Link Aggregate 7'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=33, value="'Link Aggregate 8'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=34, value="'Link Aggregate 9'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=35, value="'Link Aggregate 10'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=36, value="'Link Aggregate 11'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=37, value="'Link Aggregate 12'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=38, value="'Vl21'")
SNMPObject(modName='RFC1213-MIB', symName='ifDescr', index=39, value="'Vl22'")
This doesn't answer my exact question about ObjectName instances with symbolic names; however, it's certainly good enough.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,要在 OID 和符号名称之间进行转换,您需要使用 MIB 查看器组件。
当您使用 pysnmp“oneliner”API 时,会为您的输入 OID/符号隐式调用此转换。但是,需要针对输出 OID(也可能针对值)显式执行此操作。
请参阅以下配方示例:
https://docs.lextudio.com/pysnmp/
Generally speaking, to convert between OIDs and symbolic names you are to use a MIB viewer component.
When you use pysnmp "oneliner" API, this conversion is invoked implicitly for your input OIDs/symbols. However it needs to be performed explicitly for your output OIDs (and possibly for values as well).
See the following example for a recipe:
https://docs.lextudio.com/pysnmp/
符号名称是 OID 的别名,与 OID 不同,它们不会出现在协议操作中。 OID 别名映射由称为 MIB 的独立专用数据库单独维护。
因此,OID 的符号表示不随 ObjectName 一起携带,但是您可以在 MIB 中通过 OID 查找符号名称。
希望我的解释有意义。
Symbolic names are aliases to OIDs, unlike OIDs they do not appear in protocol operations. The OID-alias mapping is maintained separately by a stand-alone, dedicated database known as MIB.
Therefore the symbolic representation of an OID is not carried with the ObjectName, you can however look up symbolic name by OID at a MIB.
Hope my explanation makes sense.