From d12f48ecb80c76b52e032f791488997efb13bf43 Mon Sep 17 00:00:00 2001 From: elie Date: Fri, 5 Nov 2004 19:29:39 +0000 Subject: initial revision --- examples/smi/agent/custom-managed-object.py | 26 ++++++++++++ examples/smi/manager/mib-tree-inspection.py | 62 +++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 examples/smi/agent/custom-managed-object.py create mode 100644 examples/smi/manager/mib-tree-inspection.py (limited to 'examples/smi') diff --git a/examples/smi/agent/custom-managed-object.py b/examples/smi/agent/custom-managed-object.py new file mode 100644 index 00000000..2d6368d7 --- /dev/null +++ b/examples/smi/agent/custom-managed-object.py @@ -0,0 +1,26 @@ +from pysnmp.smi import builder, instrum, error + +print 'Loading MIB modules...', +mibBuilder = builder.MibBuilder().loadModules( + 'SNMPv2-MIB', 'SNMP-FRAMEWORK-MIB', 'SNMP-COMMUNITY-MIB' + ) +print 'done' + +print 'Building MIB tree...', +mibInstrum = instrum.MibInstrumentationController(mibBuilder) +print 'done' + +print 'Remote manager write/create access to MIB instrumentation: ', +print mibInstrum.writeVars( + ((1,3,6,1,6,3,18,1,1,1,2,109,121,110,109,115), 'mycomm'), + ((1,3,6,1,6,3,18,1,1,1,3,109,121,110,109,115), 'mynmsname') + ) + +print 'Remote manager read access to MIB instrumentation (table walk)' +oid, val = (), None +while 1: + try: + oid, val = mibInstrum.readNextVars((oid, val))[0] + except error.NoSuchInstanceError: + break + print oid, val diff --git a/examples/smi/manager/mib-tree-inspection.py b/examples/smi/manager/mib-tree-inspection.py new file mode 100644 index 00000000..97345e7f --- /dev/null +++ b/examples/smi/manager/mib-tree-inspection.py @@ -0,0 +1,62 @@ +# SNMP manager-side MIB management +from pysnmp.smi import builder, view, error + +print 'Loading MIB modules...', +mibBuilder = builder.MibBuilder().loadModules( + 'SNMPv2-MIB', 'SNMP-FRAMEWORK-MIB', 'SNMP-COMMUNITY-MIB' + ) +print 'done' + +print 'Indexing MIB objects...', +mibView = view.MibViewController(mibBuilder) +print 'done' + +print 'MIB symbol name lookup by OID: ', +oid, label, suffix = mibView.getNodeName((1,3,6,1,2,1,1,1)) +print oid, label, suffix + +print 'MIB symbol name lookup by label: ', +oid, label, suffix = mibView.getNodeName((1,3,6,1,2,'mib-2',1,'sysDescr')) +print oid, label, suffix + +print 'MIB symbol name lookup by symbol description: ', +oid, label, suffix = mibView.getNodeName('sysDescr') +oid, label, suffix = mibView.getNodeName('snmpEngineID', 'SNMP-FRAMEWORK-MIB') +print oid, label, suffix + +print 'MIB object value pretty print: ', +mibNode, = mibBuilder.importSymbols('SNMP-FRAMEWORK-MIB', 'snmpEngineID') +print mibNode.syntax.prettyGet() + +print 'MIB symbol location lookup by name: ', +modName, symName = mibView.getNodeLocation('snmpCommunityEntry') +print symName, modName + +print 'MIB node lookup by location: ', +rowNode, = mibBuilder.importSymbols(modName, symName) +print rowNode + +print 'Conceptual table index value to oid convertion: ', +oid = rowNode.getInstIdFromIndices('router') +print oid +print 'Conceptual table index oid to value convertion: ', +print rowNode.getIndicesFromInstId(oid) + +print 'MIB tree traversal' +oid, label, suffix = mibView.getFirstNodeName() +while 1: + try: + modName, nodeDesc = mibView.getNodeLocation(oid) + print '%s::%s == %s' % (modName, nodeDesc, oid) + oid, label, suffix = mibView.getNextNodeName(oid) + except error.NoSuchInstanceError: + break + +print 'Modules traversal' +modName = mibView.getFirstModuleName() +while 1: + if modName: print modName + try: + modName = mibView.getNextModuleName(modName) + except error.NoSuchModuleError: + break -- cgit v1.2.1