diff options
Diffstat (limited to 'examples/smi')
4 files changed, 19 insertions, 7 deletions
diff --git a/examples/smi/agent/custom-managed-object.py b/examples/smi/agent/custom-managed-object.py index 50aee947..a6c3137b 100644 --- a/examples/smi/agent/custom-managed-object.py +++ b/examples/smi/agent/custom-managed-object.py @@ -55,9 +55,12 @@ if __name__ == '__main__': def cbFun(varBinds, **context): + for oid, val in varBinds: + if exval.endOfMib.isSameTypeWith(val): context['app']['stop'] = True + print('%s = %s' % ('.'.join([str(x) for x in oid]), not val.isValue and 'N/A' or val.prettyPrint())) context['app']['varBinds'] = varBinds @@ -69,6 +72,8 @@ if __name__ == '__main__': } print('Remote manager read access to MIB instrumentation (table walk)') + while not app_context['stop']: mibInstrum.readNextMibObjects(*app_context['varBinds'], cbFun=cbFun, app=app_context) + print('done') diff --git a/examples/smi/agent/operations-on-managed-objects.py b/examples/smi/agent/operations-on-managed-objects.py index 75b9a765..704a6be5 100644 --- a/examples/smi/agent/operations-on-managed-objects.py +++ b/examples/smi/agent/operations-on-managed-objects.py @@ -10,12 +10,10 @@ from pysnmp.smi import builder from pysnmp.smi import instrum from pysnmp.smi import exval from pysnmp.smi import error -from pysnmp import debug - -#debug.setLogger(debug.Debug('all')) def walkMib(): + def cbFun(varBinds, **context): err = context.get('error') if err: @@ -38,6 +36,7 @@ def walkMib(): } print('Read whole MIB (table walk)') + while not app_context['stop']: mibInstrum.readNextMibObjects(*app_context['varBinds'], cbFun=cbFun, app=app_context) @@ -103,6 +102,7 @@ def cbFun(varBinds, **context): err = context.get('errors', None) if err: print(err) + for oid, val in varBinds: print('%s = %s' % ('.'.join([str(x) for x in oid]), not val.isValue and 'N/A' or val.prettyPrint())) diff --git a/examples/smi/manager/configure-mib-viewer-and-resolve-pdu-varbinds.py b/examples/smi/manager/configure-mib-viewer-and-resolve-pdu-varbinds.py index 82957fb3..2f2e83e0 100644 --- a/examples/smi/manager/configure-mib-viewer-and-resolve-pdu-varbinds.py +++ b/examples/smi/manager/configure-mib-viewer-and-resolve-pdu-varbinds.py @@ -31,7 +31,8 @@ varBinds = [ # Run var-binds through MIB resolver # You may want to catch and ignore resolution errors here -varBinds = [rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]), x[1]).resolveWithMib(mibViewController) for x in varBinds] +varBinds = [rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]), x[1]).resolveWithMib(mibViewController) + for x in varBinds] for varBind in varBinds: print(varBind.prettyPrint()) diff --git a/examples/smi/manager/mib-tree-inspection.py b/examples/smi/manager/mib-tree-inspection.py index 58b110a6..899ef36b 100644 --- a/examples/smi/manager/mib-tree-inspection.py +++ b/examples/smi/manager/mib-tree-inspection.py @@ -66,19 +66,25 @@ print(rowNode.getIndicesFromInstId(oid)) print('MIB tree traversal') oid, label, suffix = mibView.getFirstNodeName() -while 1: + +while True: try: modName, nodeDesc, suffix = mibView.getNodeLocation(oid) print('%s::%s == %s' % (modName, nodeDesc, oid)) oid, label, suffix = mibView.getNextNodeName(oid) + except error.NoSuchObjectError: break print('Modules traversal') modName = mibView.getFirstModuleName() -while 1: - if modName: print(modName) + +while True: + if modName: + print(modName) + try: modName = mibView.getNextModuleName(modName) + except error.SmiError: break |