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
verbose = true
[Wattmeter 1]
probes = ['A']
driver = Wattsup
parameters = {'device': '/dev/ttyUSB0'}
#[Wattmeter 1]
#probes = ['A']
#driver = Wattsup
#parameters = {'device': '/dev/ttyUSB0'}
[Wattmeter 2]
probes = ['B']
driver = Dummy
parameters = {'min': 10, 'max': 20}
# Wattmeter config examples
[Wattmeter 3]
probes = ['C', 'D']
driver = Dummy
#[Wattmeter 2]
#probes = ['B']
#driver = Dummy
#parameters = {'min': 10, 'max': 20}
[Wattmeter 4]
probes = ['E']
driver = Ipmi
parameters = {'interface':'lanplus', 'host':'192.168.0.70', 'username':'user', 'password':'secret', 'sensor':'Power'}
#[Wattmeter 3]
#probes = ['C', 'D']
#driver = Dummy
[Wattmeter 5]
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']
driver = Eaton
parameters = {'ip': '192.168.0.71', 'user': 'SNMPv3 User 1'}
#[Wattmeter 4]
#probes = ['E']
#driver = Ipmi
#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__)
class Eaton(Driver):
"""Driver for Eaton PDUs with 24 outlets."""
class Snmp(Driver):
"""Driver for SNMP based PDUs."""
def __init__(self, probe_ids, **kwargs):
"""Initializes the Eaton driver.
"""Initializes the SNMP driver.
Keyword arguments:
probe_ids -- list containing the probes IDs
(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)
@ -49,19 +52,31 @@ class Eaton(Driver):
for watts in watts_list:
measurements = {}
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
time.sleep(1)
def get_watts(self):
"""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 = \
self.cmd_gen.bulkCmd(
cmdgen.UsmUserData(self.kwargs.get('user')),
community_or_user,
cmdgen.UdpTransportTarget((self.kwargs.get('ip'), 161)),
1, 0,
'1.3.6.1.4.1.534.6.6.7.6.5.1.3',
maxRows=24,
self.kwargs.get('oid'),
maxRows=len(self.probe_ids),
)
if errorIndication:
LOG.error(errorIndication)