summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2019-07-30 20:29:22 +0200
committerIlya Etingof <etingof@gmail.com>2019-07-30 20:41:18 +0200
commit86790dd94886c743341f598533046f112ba6aea8 (patch)
tree42b33134f737745dc1d242b842a9218ec8c3b483
parent6b8ee5ec9eb744e872d5d8d4b036ed7dfcfdcfc8 (diff)
downloadpysnmp-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`.
-rw-r--r--CHANGES.txt6
-rw-r--r--pysnmp/hlapi/varbinds.py10
-rw-r--r--pysnmp/smi/rfc1902.py16
3 files changed, 21 insertions, 11 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 76c94d9f..8925a725 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -116,9 +116,9 @@ Revision 4.4.10, released 2019-07-29
- Rebased MIB importing code onto `importlib` because `imp` is long
deprecated
-- MIB objects resolution made more forgiving to errors, added optional
- `ignoreErrors` parameter to `ObjectType.resolveWithMib()` to control
- that behaviour.
+- Received MIB objects resolution made more forgiving to errors, added
+ optional `ignoreErrors` parameter to `ObjectType.resolveWithMib()` to
+ control that behaviour.
- Fixed asyncore main loop to respect non-default timer resolution
- Fixed `.setTimerResolution()` behaviour of abstract main loop dispatcher
to update call intervals of the existing periodic dispatcher jobs
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