-
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.
Merge pull request #46 from zenoss/release/0.43.0
release/0.43.0
- Loading branch information
Showing
23 changed files
with
1,508 additions
and
463 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
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 |
---|---|---|
@@ -1,11 +1,36 @@ | ||
from __future__ import absolute_import | ||
|
||
from ipaddr import IPAddress | ||
|
||
|
||
def asOidStr(oid): | ||
"""converts an oid int sequence to an oid string""" | ||
return "." + ".".join([str(x) for x in oid]) | ||
return "." + ".".join(str(x) for x in oid) | ||
|
||
|
||
def asOid(oidStr): | ||
"""converts an OID string into a tuple of integers""" | ||
return tuple([int(x) for x in oidStr.strip(".").split(".")]) | ||
return tuple(int(x) for x in oidStr.strip(".").split(".")) | ||
|
||
|
||
def asAgent(ip, port): | ||
"""take a google ipaddr object and port number and produce a net-snmp | ||
agent specification (see the snmpcmd manpage)""" | ||
ip, interface = ip.split("%") if "%" in ip else (ip, None) | ||
address = IPAddress(ip) | ||
|
||
if address.version == 4: | ||
return "udp:{}:{}".format(address.compressed, port) | ||
|
||
if address.version == 6: | ||
if address.is_link_local: | ||
if interface is None: | ||
raise RuntimeError( | ||
"Cannot create agent specification from link local " | ||
"IPv6 address without an interface" | ||
) | ||
else: | ||
return "udp6:[{}%{}]:{}".format( | ||
address.compressed, interface, port | ||
) | ||
return "udp6:[{}]:{}".format(address.compressed, port) |
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) |
Oops, something went wrong.