-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fe4448
commit 2042209
Showing
10 changed files
with
874 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from __future__ import absolute_import | ||
|
||
from . import oids | ||
|
||
|
||
class SnmpTimeoutError(Exception): | ||
pass | ||
|
||
|
||
class ArgumentParseError(Exception): | ||
pass | ||
|
||
|
||
class TransportError(Exception): | ||
pass | ||
|
||
|
||
class SnmpNameError(Exception): | ||
def __init__(self, oid): | ||
Exception.__init__(self, "Bad Name", oid) | ||
|
||
|
||
class SnmpError(Exception): | ||
def __init__(self, message, *args, **kwargs): | ||
self.message = message | ||
|
||
def __str__(self): | ||
return self.message | ||
|
||
def __repr__(self): | ||
return self.message | ||
|
||
|
||
class SnmpUsmError(SnmpError): | ||
pass | ||
|
||
|
||
class SnmpUsmStatsError(SnmpUsmError): | ||
def __init__(self, mesg, oid): | ||
super(SnmpUsmStatsError, self).__init__(mesg) | ||
self.oid = oid | ||
|
||
|
||
_stats_oid_error_map = { | ||
oids.WrongDigest: SnmpUsmStatsError( | ||
"unexpected authentication digest", oids.WrongDigest | ||
), | ||
oids.UnknownUserName: SnmpUsmStatsError( | ||
"unknown user", oids.UnknownUserName | ||
), | ||
oids.UnknownSecurityLevel: SnmpUsmStatsError( | ||
"unknown or unavailable security level", oids.UnknownSecurityLevel | ||
), | ||
oids.DecryptionError: SnmpUsmStatsError( | ||
"privacy decryption error", oids.DecryptionError | ||
), | ||
} | ||
|
||
|
||
def get_stats_error(oid): | ||
return _stats_oid_error_map.get(oid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from __future__ import absolute_import | ||
|
||
from .conversions import asOidStr | ||
|
||
|
||
class OID(object): | ||
__slots__ = ("oid",) | ||
|
||
def __init__(self, oid): | ||
super(OID, self).__setattr__("oid", oid) | ||
|
||
def __setattr__(self, key, value): | ||
if key in OID.__slots__: | ||
raise AttributeError( | ||
"can't set attribute '{}' on 'OID' object".format(key) | ||
) | ||
super(OID, self).__setattr__(key, value) | ||
|
||
def __eq__(this, that): | ||
if isinstance(that, (tuple, list)): | ||
return this.oid == that | ||
if isinstance(that, OID): | ||
return this.oid == that.oid | ||
return NotImplemented | ||
|
||
def __ne__(this, that): | ||
if isinstance(that, (tuple, list)): | ||
return this.oid != that | ||
if isinstance(that, OID): | ||
return this.oid != that.oid | ||
return NotImplemented | ||
|
||
def __hash__(self): | ||
return hash(self.oid) | ||
|
||
def __repr__(self): | ||
return "<{0.__module__}.{0.__class__.__name__} {1}>".format( | ||
self, asOidStr(self.oid) | ||
) | ||
|
||
def __str__(self): | ||
return asOidStr(self.oid) | ||
|
||
|
||
_base_status_oid = (1, 3, 6, 1, 6, 3, 15, 1, 1) | ||
|
||
|
||
class UnknownSecurityLevel(OID): | ||
__slots__ = () | ||
|
||
|
||
UnknownSecurityLevel = UnknownSecurityLevel(_base_status_oid + (1, 0)) | ||
|
||
|
||
class NotInTimeWindow(OID): | ||
__slots__ = () | ||
|
||
|
||
NotInTimeWindow = NotInTimeWindow(_base_status_oid + (2, 0)) | ||
|
||
|
||
class UnknownUserName(OID): | ||
__slots__ = () | ||
|
||
|
||
UnknownUserName = UnknownUserName(_base_status_oid + (3, 0)) | ||
|
||
|
||
class UnknownEngineId(OID): | ||
__slots__ = () | ||
|
||
|
||
UnknownEngineId = UnknownEngineId(_base_status_oid + (4, 0)) | ||
|
||
|
||
class WrongDigest(OID): | ||
__slots__ = () | ||
|
||
|
||
WrongDigest = WrongDigest(_base_status_oid + (5, 0)) | ||
|
||
|
||
class DecryptionError(OID): | ||
__slots__ = () | ||
|
||
|
||
DecryptionError = DecryptionError(_base_status_oid + (6, 0)) | ||
|
||
|
||
class SysDescr(OID): | ||
__slots__ = () | ||
|
||
|
||
SysDescr = SysDescr((1, 3, 6, 1, 2, 1, 1, 1, 0)) |
Oops, something went wrong.