summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/smi/agent/custom-managed-object.py28
-rw-r--r--examples/smi/agent/operations-on-managed-objects.py38
-rw-r--r--examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py4
3 files changed, 49 insertions, 21 deletions
diff --git a/examples/smi/agent/custom-managed-object.py b/examples/smi/agent/custom-managed-object.py
index 73bfa836..f1af0ae3 100644
--- a/examples/smi/agent/custom-managed-object.py
+++ b/examples/smi/agent/custom-managed-object.py
@@ -51,13 +51,23 @@ if __name__ == '__main__':
mibInstrum = instrum.MibInstrumController(mibBuilder)
- print('Remote manager read access to MIB instrumentation (table walk)')
-
- varBinds = [((), None)]
+ def cbFun(varBinds, **context):
+ for oid, val in varBinds:
+ if exval.endOfMib.isSameTypeWith(val):
+ context['state']['stop'] = True
+ print('%s = %s' % ('.'.join([str(x) for x in oid]), not val.isValue and 'N/A' or val.prettyPrint()))
+
+ context['state']['varBinds'] = varBinds
+
+ context = {
+ 'cbFun': cbFun,
+ 'state': {
+ 'varBinds': [((1, 3, 6), None)],
+ 'stop': False
+ }
+ }
- while True:
- varBinds = mibInstrum.readNextVars(*varBinds)
- oid, val = varBinds[0]
- if exval.endOfMib.isSameTypeWith(val):
- break
- print(oid, val.prettyPrint())
+ print('Remote manager read access to MIB instrumentation (table walk)')
+ while not context['state']['stop']:
+ mibInstrum.readNextVars(*context['state']['varBinds'], **context)
+ print('done')
diff --git a/examples/smi/agent/operations-on-managed-objects.py b/examples/smi/agent/operations-on-managed-objects.py
index e1eb52d6..bfcd021e 100644
--- a/examples/smi/agent/operations-on-managed-objects.py
+++ b/examples/smi/agent/operations-on-managed-objects.py
@@ -26,24 +26,40 @@ snmpCommunityEntry, = mibBuilder.importSymbols(
instanceId = snmpCommunityEntry.getInstIdFromIndices('my-router')
print('done')
+
+def cbFun(varBinds, **context):
+ for oid, val in varBinds:
+ print('%s = %s' % ('.'.join([str(x) for x in oid]), not val.isValue and 'N/A' or val.prettyPrint()))
+
print('Create/update SNMP-COMMUNITY-MIB::snmpCommunityEntry table row: ')
-varBinds = mibInstrum.writeVars(
+mibInstrum.writeVars(
(snmpCommunityEntry.name + (2,) + instanceId, 'mycomm'),
(snmpCommunityEntry.name + (3,) + instanceId, 'mynmsname'),
- (snmpCommunityEntry.name + (7,) + instanceId, 'volatile')
+ (snmpCommunityEntry.name + (7,) + instanceId, 'volatile'),
+ cbFun=cbFun
)
-for oid, val in varBinds:
- print('%s = %s' % ('.'.join([str(x) for x in oid]), not val.isValue and 'N/A' or val.prettyPrint()))
print('done')
+
+def cbFun(varBinds, **context):
+ for oid, val in varBinds:
+ if exval.endOfMib.isSameTypeWith(val):
+ context['state']['stop'] = True
+ print('%s = %s' % ('.'.join([str(x) for x in oid]), not val.isValue and 'N/A' or val.prettyPrint()))
+
+ context['state']['varBinds'] = varBinds
+
+context = {
+ 'cbFun': cbFun,
+ 'state': {
+ 'varBinds': [((1, 3, 6), None)],
+ 'stop': False
+ }
+}
+
print('Read whole MIB (table walk)')
-varBinds = [((), None)]
-while True:
- varBinds = mibInstrum.readNextVars(*varBinds)
- oid, val = varBinds[0]
- if exval.endOfMib.isSameTypeWith(val):
- break
- print('%s = %s' % ('.'.join([str(x) for x in oid]), not val.isValue and 'N/A' or val.prettyPrint()))
+while not context['state']['stop']:
+ mibInstrum.readNextVars(*context['state']['varBinds'], **context)
print('done')
print('Unloading MIB modules...'),
diff --git a/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py b/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py
index 94bdb7de..7e74df3d 100644
--- a/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py
+++ b/examples/v3arch/asyncore/agent/cmdrsp/custom-mib-controller.py
@@ -54,7 +54,9 @@ snmpContext = context.SnmpContext(snmpEngine)
# always echos request var-binds in response.
class EchoMibInstrumController(instrum.AbstractMibInstrumController):
def readVars(self, *varBinds, **context):
- return [(ov[0], v2c.OctetString('You queried OID %s' % ov[0])) for ov in varBinds]
+ cbFun = context.get('cbFun')
+ if cbFun:
+ cbFun([(ov[0], v2c.OctetString('You queried OID %s' % ov[0])) for ov in varBinds], **context)
# Create a custom Management Instrumentation Controller and register at