Add SNMP driver (replacing the Eaton driver).

Supports the SNMP v1, v2c and v3 protocols.

Change-Id: I126b985cb863e69c0b92d55a4f1477a73f3c1ce3
This commit is contained in:
François Rossigneux 2014-01-29 13:58:39 +01:00
parent 8c5d8610aa
commit 71efa38ead
2 changed files with 49 additions and 27 deletions

View File

@ -16,26 +16,33 @@ check_drivers_interval = 60
log_file = /var/log/kwapi/kwapi-drivers.log log_file = /var/log/kwapi/kwapi-drivers.log
verbose = true verbose = true
[Wattmeter 1] #[Wattmeter 1]
probes = ['A'] #probes = ['A']
driver = Wattsup #driver = Wattsup
parameters = {'device': '/dev/ttyUSB0'} #parameters = {'device': '/dev/ttyUSB0'}
[Wattmeter 2] # Wattmeter config examples
probes = ['B']
driver = Dummy
parameters = {'min': 10, 'max': 20}
[Wattmeter 3] #[Wattmeter 2]
probes = ['C', 'D'] #probes = ['B']
driver = Dummy #driver = Dummy
#parameters = {'min': 10, 'max': 20}
[Wattmeter 4] #[Wattmeter 3]
probes = ['E'] #probes = ['C', 'D']
driver = Ipmi #driver = Dummy
parameters = {'interface':'lanplus', 'host':'192.168.0.70', 'username':'user', 'password':'secret', 'sensor':'Power'}
[Wattmeter 5] #[Wattmeter 4]
probes = ['F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F17', 'F18', 'F19', 'F20', 'F21', 'F22', 'F23', 'F24'] #probes = ['E']
driver = Eaton #driver = Ipmi
parameters = {'ip': '192.168.0.71', 'user': 'SNMPv3 User 1'} #parameters = {'interface':'lanplus', 'host':'192.168.0.70', 'username':'user', 'password':'secret', 'sensor':'Power'}
#[Wattmeter 5]
#probes = ['F1', None, 'F3', 'F4']
#driver = Snmp
#parameters = {'protocol': 'v1', 'community': 'public', 'ip': '192.168.0.71', 'oid': '1.3.6.1.4.1.13742.4.1.2.2.1.7'}
#[Wattmeter 6]
#probes = ['E1', None, 'E3', 'E4']
#driver = Snmp
#parameters = {'protocol': 'v3', 'user': 'admin', 'ip': '192.168.0.72', 'oid': '1.3.6.1.4.1.534.6.6.7.6.5.1.3'}

View File

@ -24,16 +24,19 @@ from driver import Driver
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
class Eaton(Driver): class Snmp(Driver):
"""Driver for Eaton PDUs with 24 outlets.""" """Driver for SNMP based PDUs."""
def __init__(self, probe_ids, **kwargs): def __init__(self, probe_ids, **kwargs):
"""Initializes the Eaton driver. """Initializes the SNMP driver.
Keyword arguments: Keyword arguments:
probe_ids -- list containing the probes IDs probe_ids -- list containing the probes IDs
(a wattmeter monitor sometimes several probes) (a wattmeter monitor sometimes several probes)
kwargs -- keyword (ip, user) defining the Eaton SNMP parameters kwargs -- keyword (protocol, user or community, ip, oid) defining the
SNMP parameters
Eaton OID is 1.3.6.1.4.1.534.6.6.7.6.5.1.3
Raritan OID is 1.3.6.1.4.1.13742.4.1.2.2.1.7
""" """
Driver.__init__(self, probe_ids, kwargs) Driver.__init__(self, probe_ids, kwargs)
@ -49,19 +52,31 @@ class Eaton(Driver):
for watts in watts_list: for watts in watts_list:
measurements = {} measurements = {}
measurements['w'] = watts measurements['w'] = watts
self.send_measurements(self.probe_ids[i], measurements) if self.probe_ids[i]:
self.send_measurements(self.probe_ids[i], measurements)
i += 1 i += 1
time.sleep(1) time.sleep(1)
def get_watts(self): def get_watts(self):
"""Returns the power consumption.""" """Returns the power consumption."""
protocol = self.kwargs.get('protocol')
if protocol is '1':
community_or_user = cmdgen.CommunityData(
self.kwargs.get('community'),
mpModel=0)
elif protocol is '2c':
community_or_user = cmdgen.CommunityData(
self.kwargs.get('community'),
mpModel=1)
elif protocol is '3':
community_or_user = cmdgen.UsmUserData(self.kwargs.get('user'))
errorIndication, errorStatus, errorIndex, varBindTable = \ errorIndication, errorStatus, errorIndex, varBindTable = \
self.cmd_gen.bulkCmd( self.cmd_gen.bulkCmd(
cmdgen.UsmUserData(self.kwargs.get('user')), community_or_user,
cmdgen.UdpTransportTarget((self.kwargs.get('ip'), 161)), cmdgen.UdpTransportTarget((self.kwargs.get('ip'), 161)),
1, 0, 1, 0,
'1.3.6.1.4.1.534.6.6.7.6.5.1.3', self.kwargs.get('oid'),
maxRows=24, maxRows=len(self.probe_ids),
) )
if errorIndication: if errorIndication:
LOG.error(errorIndication) LOG.error(errorIndication)