From ceab600d265bf8d541f7fe0a99d998f63eb62da5 Mon Sep 17 00:00:00 2001 From: elie Date: Fri, 24 Jan 2014 12:33:42 +0000 Subject: MIB instrumentation example improved to cover table index building facility --- examples/smi/backend.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/smi/backend.py b/examples/smi/backend.py index 91a0eba..13d3149 100644 --- a/examples/smi/backend.py +++ b/examples/smi/backend.py @@ -11,20 +11,31 @@ print('Building MIB tree...'), mibInstrum = instrum.MibInstrumController(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'), - ((1,3,6,1,6,3,18,1,1,1,7,109,121,110,109,115), 'volatile')) ) +print('Building table entry index from human-friendly representation...'), +snmpCommunityEntry, = mibBuilder.importSymbols( + 'SNMP-COMMUNITY-MIB', 'snmpCommunityEntry' ) +instanceId = snmpCommunityEntry.getInstIdFromIndices('my-router') +print('done') -print('Remote manager read access to MIB instrumentation (table walk)') +print('Create/update SNMP-COMMUNITY-MIB::snmpCommunityEntry table row: ') +varBinds = mibInstrum.writeVars( + ( (snmpCommunityEntry.name+(2,)+instanceId, 'mycomm'), + (snmpCommunityEntry.name+(3,)+instanceId, 'mynmsname'), + (snmpCommunityEntry.name+(7,)+instanceId, 'volatile') ) +) +for oid, val in varBinds: + print('%s = %s' % ('.'.join([str(x) for x in oid]), val.prettyPrint())) +print('done') + +print('Read whole MIB (table walk)') oid, val = (), None while 1: oid, val = mibInstrum.readNextVars(((oid, val),))[0] if exval.endOfMib.isSameTypeWith(val): break - print(oid, val.prettyPrint()) + print('%s = %s' % ('.'.join([str(x) for x in oid]), val.prettyPrint())) +print('done') print('Unloading MIB modules...'), mibBuilder.unloadModules() -- cgit v1.2.1