From dc10dbfd6fb551725ca878573432871a7494f4e0 Mon Sep 17 00:00:00 2001 From: elie Date: Wed, 14 Jul 2010 17:29:38 +0000 Subject: some more 'app' debugging added --- CHANGES | 2 +- pysnmp/entity/rfc3413/cmdgen.py | 4 ++-- pysnmp/entity/rfc3413/cmdrsp.py | 19 +++++++++++++++---- pysnmp/entity/rfc3413/ntfrcv.py | 12 ++++++++++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index 4098720..ec21c0d 100644 --- a/CHANGES +++ b/CHANGES @@ -31,7 +31,7 @@ Revision 4.1.14a - Debug category 'app' (for Application) added to facilitate Standard SNMP Applications debugging. - The retryCount semantic of CommandGenerator application changed to include - solely retries and do not include initial request. Thus, retryCount=1 will + sole retries and do not include initial request. Thus, retryCount=1 will now send up to two packets, not just one as it used to be. - Debugging printout now escapes non-printable characters. diff --git a/pysnmp/entity/rfc3413/cmdgen.py b/pysnmp/entity/rfc3413/cmdgen.py index adb905a..88e2332 100644 --- a/pysnmp/entity/rfc3413/cmdgen.py +++ b/pysnmp/entity/rfc3413/cmdgen.py @@ -56,9 +56,9 @@ class CommandGeneratorBase: # 3.1.3 if statusInformation: - debug.logger & debug.flagApp and debug.logger('processResponsePdu: sendPduHandle %s statusInformation %s' % (sendPduHandle, statusInformation)) + debug.logger & debug.flagApp and debug.logger('processResponsePdu: sendPduHandle %s, statusInformation %s' % (sendPduHandle, statusInformation)) if origRetries == origRetryCount: - debug.logger & debug.flagApp and debug.logger('processResponsePdu: sendPduHandle %s retry count %d exceeded' % (sendPduHandle, origRetries)) + debug.logger & debug.flagApp and debug.logger('processResponsePdu: sendPduHandle %s, retry count %d exceeded' % (sendPduHandle, origRetries)) cbFun(origSendRequestHandle, statusInformation['errorIndication'], 0, 0, (), cbCtx) diff --git a/pysnmp/entity/rfc3413/cmdrsp.py b/pysnmp/entity/rfc3413/cmdrsp.py index 17bcd2f..636346e 100644 --- a/pysnmp/entity/rfc3413/cmdrsp.py +++ b/pysnmp/entity/rfc3413/cmdrsp.py @@ -2,6 +2,7 @@ from pysnmp.proto import rfc1157, rfc1905, rfc3411, error from pysnmp.proto.api import v2c # backend is always SMIv2 compliant from pysnmp.proto.proxy import rfc2576 import pysnmp.smi.error +from pysnmp import debug vacmID = 3 @@ -40,6 +41,8 @@ class CommandResponderBase: del self.__pendingReqs[stateReference] + debug.logger & debug.flagApp and debug.logger('__sendResponse: stateReference %s, errorStatus %s, errorIndex %s, varBinds %s' % (stateReference, errorStatus, errorIndex, varBinds)) + v2c.apiPDU.setErrorStatus(PDU, errorStatus) v2c.apiPDU.setErrorIndex(PDU, errorIndex) v2c.apiPDU.setVarBinds(PDU, varBinds) @@ -64,7 +67,8 @@ class CommandResponderBase: stateReference, statusInformation ) - except error.StatusInformation: + except error.StatusInformation, why: + debug.logger & debug.flagApp and debug.logger('__sendResponse: stateReference %s, statusInformation %s' % (stateReference, why)) snmpSilentDrops, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols('__SNMPv2-MIB', 'snmpSilentDrops') snmpSilentDrops.syntax = snmpSilentDrops.syntax + 1 @@ -90,7 +94,7 @@ class CommandResponderBase: # Agent-side API complies with SMIv2 if messageProcessingModel == 0: PDU = rfc2576.v1ToV2(PDU) - + # 3.2.1 if rfc3411.readClassPDUs.has_key(PDU.tagSet): viewType = 'read' @@ -126,13 +130,17 @@ class CommandResponderBase: # 3.2.5 varBinds = v2c.apiPDU.getVarBinds(PDU) errorStatus, errorIndex = 'noError', 0 + + debug.logger & debug.flagApp and debug.logger('processPdu: stateReference %s, varBinds %s' % (stateReference, varBinds)) + try: - errorStatus, errorIndex, varBinds = self._handleManagementOperation( + errorStatus,errorIndex,varBinds = self._handleManagementOperation( snmpEngine, self.snmpContext.getMibInstrum(contextName), PDU, (self.__verifyAccess, acCtx) ) # SNMPv2 SMI exceptions except pysnmp.smi.error.GenError, errorIndication: + debug.logger & debug.flagApp and debug.logger('processPdu: stateReference %s, errorIndication %s' % (stateReference, errorIndication)) if errorIndication.has_key('oid'): # Request REPORT generation statusInformation['oid'] = errorIndication['oid'] @@ -165,7 +173,7 @@ class CommandResponderBase: errorStatus, errorIndex = 'genErr', 1 except pysnmp.error.PySnmpError, errorIndication: errorStatus, errorIndex = 'genErr', 1 - + self.__sendResponse( snmpEngine, errorStatus, errorIndex, varBinds, stateReference ) @@ -181,6 +189,7 @@ class CommandResponderBase: ) # Map ACM errors onto SMI ones except error.StatusInformation, statusInformation: + debug.logger & debug.flagApp and debug.logger('__verifyAccess: name %s, statusInformation %s' % (name, statusInformation)) errorIndication = statusInformation['errorIndication'] # 3.2.5... if errorIndication == 'noSuchView' or \ @@ -248,6 +257,8 @@ class BulkCommandResponder(CommandResponderBase): N = min(nonRepeaters, len(reqVarBinds)) M = int(maxRepetitions) R = max(len(reqVarBinds)-N, 0) + + debug.logger & debug.flagApp and debug.logger('_handleManagementOperation: N %d, M %d, R %d' % (N, M, R)) if nonRepeaters: rspVarBinds = contextMibInstrumCtl.readNextVars( diff --git a/pysnmp/entity/rfc3413/ntfrcv.py b/pysnmp/entity/rfc3413/ntfrcv.py index 3ff4274..ff89d8c 100644 --- a/pysnmp/entity/rfc3413/ntfrcv.py +++ b/pysnmp/entity/rfc3413/ntfrcv.py @@ -1,6 +1,7 @@ from pysnmp.proto import rfc3411, error from pysnmp.proto.api import v1, v2c # backend is always SMIv2 compliant from pysnmp.proto.proxy import rfc2576 +from pysnmp import debug # 3.4 class NotificationReceiver: @@ -44,6 +45,8 @@ class NotificationReceiver: errorStatus = 'noError'; errorIndex = 0 varBinds = v2c.apiPDU.getVarBinds(PDU) + + debug.logger & debug.flagApp and debug.logger('processPdu: stateReference %s, varBinds %s' % (stateReference, varBinds)) # 3.4 if rfc3411.confirmedClassPDUs.has_key(PDU.tagSet): @@ -56,12 +59,14 @@ class NotificationReceiver: v2c.apiPDU.setErrorIndex(rspPDU, errorIndex) v2c.apiPDU.setVarBinds(rspPDU, varBinds) + debug.logger & debug.flagApp and debug.logger('processPdu: stateReference %s, confirm PDU %s' % (stateReference, rspPDU.prettyPrint())) + # Agent-side API complies with SMIv2 if messageProcessingModel == 0: rspPDU = rfc2576.v2ToV1(rspPDU) statusInformation = {} - + # 3.4.3 try: snmpEngine.msgAndPduDsp.returnResponsePdu( @@ -78,7 +83,8 @@ class NotificationReceiver: stateReference, statusInformation ) - except error.StatusInformation: + except error.StatusInformation, why: + debug.logger & debug.flagApp and debug.logger('processPdu: stateReference %s, statusInformation %s' % (stateReference, why)) snmpSilentDrops, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols('__SNMPv2-MIB', 'snmpSilentDrops') snmpSilentDrops.syntax = snmpSilentDrops.syntax + 1 @@ -87,6 +93,8 @@ class NotificationReceiver: else: raise error.ProtocolError('Unexpected PDU class %s' % PDU.tagSet) + debug.logger & debug.flagApp and debug.logger('processPdu: stateReference %s, user cbFun %s, cbCtx %s, varBinds %s' % (stateReference, self.__cbFun, self.__cbCtx, varBinds)) + if self.__cbFunVer: self.__cbFun( snmpEngine, stateReference, contextEngineId, contextName, -- cgit v1.2.1