diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-07-30 20:29:22 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2019-07-30 20:41:18 +0200 |
commit | 86790dd94886c743341f598533046f112ba6aea8 (patch) | |
tree | 42b33134f737745dc1d242b842a9218ec8c3b483 /pysnmp | |
parent | 6b8ee5ec9eb744e872d5d8d4b036ed7dfcfdcfc8 (diff) | |
download | pysnmp-git-86790dd94886c743341f598533046f112ba6aea8.tar.gz |
Make received MIB objects resolution more forgiving
Previously, MIB resolution errors were ignored (whenever possible)
for objects we were sending and receiving. This change tightens
outgoing objects MIB compliance (send will fail), but tolerate
non quite compliant objects we receive.
Also, extend the same policy onto `NotificationOriginator`.
Diffstat (limited to 'pysnmp')
-rw-r--r-- | pysnmp/hlapi/varbinds.py | 10 | ||||
-rw-r--r-- | pysnmp/smi/rfc1902.py | 16 |
2 files changed, 18 insertions, 8 deletions
diff --git a/pysnmp/hlapi/varbinds.py b/pysnmp/hlapi/varbinds.py index 0eed7e50..6f118c78 100644 --- a/pysnmp/hlapi/varbinds.py +++ b/pysnmp/hlapi/varbinds.py @@ -45,7 +45,8 @@ class CommandGeneratorVarBinds(MibViewControllerManager): else: varBind = ObjectType(ObjectIdentity(varBind[0]), varBind[1]) - resolvedVarBinds.append(varBind.resolveWithMib(mibViewController)) + resolvedVarBinds.append( + varBind.resolveWithMib(mibViewController, ignoreErrors=False)) return resolvedVarBinds @@ -65,13 +66,16 @@ class NotificationOriginatorVarBinds(MibViewControllerManager): mibViewController = self.getMibViewController(userCache) if isinstance(varBinds, NotificationType): - return varBinds.resolveWithMib(mibViewController) + return varBinds.resolveWithMib( + mibViewController, ignoreErrors=False) resolvedVarBinds = [] for varBind in varBinds: if isinstance(varBind, NotificationType): - resolvedVarBinds.extend(varBind.resolveWithMib(mibViewController)) + resolvedVarBinds.extend( + varBind.resolveWithMib( + mibViewController, ignoreErrors=False)) continue if isinstance(varBind, ObjectType): diff --git a/pysnmp/smi/rfc1902.py b/pysnmp/smi/rfc1902.py index c96996b9..5b8f994e 100644 --- a/pysnmp/smi/rfc1902.py +++ b/pysnmp/smi/rfc1902.py @@ -1236,7 +1236,7 @@ class NotificationType(object): def isFullyResolved(self): return self._state & self.ST_CLEAN - def resolveWithMib(self, mibViewController): + def resolveWithMib(self, mibViewController, ignoreErrors=True): """Perform MIB variable ID conversion and notification objects expansion. Parameters @@ -1244,6 +1244,12 @@ class NotificationType(object): mibViewController : :py:class:`~pysnmp.smi.view.MibViewController` class instance representing MIB browsing functionality. + Other Parameters + ---------------- + ignoreErrors: :py:class:`bool` + If `True` (default), ignore MIB object name or value casting + failures if possible. + Returns ------- : :py:class:`~pysnmp.smi.rfc1902.NotificationType` @@ -1280,7 +1286,8 @@ class NotificationType(object): self._varBinds.append( ObjectType(ObjectIdentity(v2c.apiTrapPDU.snmpTrapOID), - self._objectIdentity).resolveWithMib(mibViewController)) + self._objectIdentity).resolveWithMib( + mibViewController, ignoreErrors)) SmiNotificationType, = mibViewController.mibBuilder.importSymbols( 'SNMPv2-SMI', 'NotificationType') @@ -1301,7 +1308,7 @@ class NotificationType(object): objectIdentity, self._objects.get( notificationObject, rfc1905.unSpecified)) - objectType.resolveWithMib(mibViewController) + objectType.resolveWithMib(mibViewController, ignoreErrors) self._varBinds.append(objectType) @@ -1315,8 +1322,7 @@ class NotificationType(object): for varBinds in self._additionalVarBinds: if not isinstance(varBinds, ObjectType): varBinds = ObjectType(ObjectIdentity(varBinds[0]), varBinds[1]) - - varBinds.resolveWithMib(mibViewController) + varBinds.resolveWithMib(mibViewController, ignoreErrors) if varBinds[0] in varBindsLocation: self._varBinds[varBindsLocation[varBinds[0]]] = varBinds |