1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
from __future__ import unicode_literals, absolute_import
from .compat import urepr
from .helpers import normalize_oid
from .utils import strip_non_printable, tostr
class SNMPVariable(object):
"""
An SNMP variable binding which is used to represent a piece of
information being retreived via SNMP.
:param oid: the OID being manipulated
:param oid_index: the index of the OID
:param value: the OID value
:param snmp_type: the snmp_type of data contained in val (please see
http://www.net-snmp.org/wiki/index.php/TUT:snmpset#Data_Types
for further information); in the case that an object
or instance is not found, the type will be set to
NOSUCHOBJECT and NOSUCHINSTANCE respectively
"""
def __init__(self, oid=None, oid_index=None, value=None, snmp_type=None):
self.oid, self.oid_index = normalize_oid(oid, oid_index)
self.value = value
self.snmp_type = snmp_type
def __repr__(self):
printable_value = strip_non_printable(self.value)
return "<{0} value={1} (oid={2}, oid_index={3}, snmp_type={4})>".format(
self.__class__.__name__,
urepr(printable_value),
urepr(self.oid),
urepr(self.oid_index),
urepr(self.snmp_type),
)
def __setattr__(self, name, value):
self.__dict__[name] = tostr(value)
class SNMPVariableList(list):
"""
An slight variation of a list which is used internally by the
Net-SNMP C interface.
"""
@property
def varbinds(self):
return self
|