From 002474a06f0383870ca28e73de6727eaa0d91431 Mon Sep 17 00:00:00 2001 From: Lex Li Date: Sat, 11 Feb 2023 18:43:03 -0500 Subject: [PATCH] Added a new example. --- examples/smi/manager/print-oid-description.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/smi/manager/print-oid-description.py diff --git a/examples/smi/manager/print-oid-description.py b/examples/smi/manager/print-oid-description.py new file mode 100644 index 000000000..4893441b2 --- /dev/null +++ b/examples/smi/manager/print-oid-description.py @@ -0,0 +1,36 @@ +from pysnmp.proto.rfc1902 import ObjectIdentifier +from pysnmp.smi import builder, view, compiler + +# Create MIB builder +mibBuilder = builder.MibBuilder() + +# Optionally compile MIBs +compiler.addMibCompiler(mibBuilder, sources=['/usr/share/snmp/mibs']) + +mibBuilder.loadTexts = True + +# Load MIB modules +mibBuilder.loadModules('SNMPv2-MIB') +# mibBuilder.addMibSources(builder.DirMibSource('/Users/lextm/pysnmp.com/pysnmp/mibs')) +# mibBuilder.loadModule('LEXTUDIO-MIB') + +# Create MIB view controller +mibViewController = view.MibViewController(mibBuilder) + +# Create an OID object +oid = ObjectIdentifier('1.3.6.1.2.1.1.3.0') + +# Get the MIB name and symbol name for the OID +modName, symName, suffix = mibViewController.getNodeLocation(oid) + +# Get the MIB node for the OID +mibNode, = mibBuilder.importSymbols(modName, symName) + +# Get the description of the MIB node +description = mibNode.getDescription() + +# Print the results +print('OID: %s' % oid) +print('MIB name: %s' % modName) +print('Symbol name: %s' % symName) +print('Description: %s' % description)