Skip to content

Commit

Permalink
Add func for raising varbind errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Jun 20, 2024
1 parent 1ea910a commit 7f51422
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/zino/snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
nextCmd,
)
from pysnmp.proto import errind
from pysnmp.proto.rfc1905 import errorStatus
from pysnmp.proto.rfc1905 import NoSuchInstance, NoSuchObject, endOfMibView, errorStatus
from pysnmp.smi import builder, view
from pysnmp.smi.error import MibNotFoundError as PysnmpMibNotFoundError

Expand Down Expand Up @@ -169,6 +169,17 @@ def _raise_errors(
else:
raise ErrorStatus(f"SNMP operation failed with error {error_name} for {error_object.oid}")

def _raise_varbind_errors(self, object_type: ObjectType):
"""Raises a relevant exception if an error has occurred in a varbind"""
oid = OID(str(object_type[0]))
value = object_type[1]
if isinstance(value, NoSuchObject):
raise NoSuchObjectError(f"Could not find object at {oid}")
if isinstance(value, NoSuchInstance):
raise NoSuchInstanceError(f"Could not find instance at {oid}")
if isinstance(value, endOfMibView):
raise EndOfMibViewError("Reached end of MIB view")

Check warning on line 181 in src/zino/snmp.py

View check run for this annotation

Codecov / codecov/patch

src/zino/snmp.py#L174-L181

Added lines #L174 - L181 were not covered by tests

async def getnext(self, *oid: str) -> MibObject:
"""SNMP-GETNEXTs the given oid
Example usage:
Expand Down

0 comments on commit 7f51422

Please sign in to comment.