Module: check_mk
Branch: master
Commit: ecb92f873e30d9e5a5f97804bec36805ef0c113e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ecb92f873e30d9…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed Apr 10 09:06:20 2019 +0200
openhardwaremonitor: Refactored reading, unit, perf_var handling
Change-Id: I5db5a37eb0d6321cfb042c594315a8a47b441961
---
checks/openhardwaremonitor | 163 +++++++++++++++++++++++----------------------
1 file changed, 84 insertions(+), 79 deletions(-)
diff --git a/checks/openhardwaremonitor b/checks/openhardwaremonitor
index a5d876f..ce20800 100644
--- a/checks/openhardwaremonitor
+++ b/checks/openhardwaremonitor
@@ -63,15 +63,57 @@
factory_settings['openhardwaremonitor_temperature_default_levels'] = {
}
}
-
-def _create_openhardwaremonitor_full_name(parent, name):
- def dict_replace(input_, replacements):
- pattern = regex(r'\b(' + '|'.join(replacements.keys()) +
r')\b')
- return pattern.sub(lambda x: replacements[x.group()], input_)
-
- parent = dict_replace(parent, {"intelcpu": "cpu",
"amdcpu": "cpu", "genericcpu": "cpu"})
- name = dict_replace(name, {"CPU ": "", "Temperature":
""})
- return (parent.replace("/", "") + " " + name).strip()
+OpenhardwaremonitorTraits = {
+ 'Clock': {
+ 'unit': " MHz",
+ 'factor': 1.0,
+ 'perf_var': 'clock'
+ },
+ 'Temperature': {
+ 'unit': u"°C",
+ 'factor': 1.0
+ },
+ 'Power': {
+ 'unit': " W",
+ 'factor': 1.0,
+ 'perf_var': 'w'
+ },
+ 'Fan': {
+ 'unit': " RPM",
+ 'factor': 1.0
+ },
+ 'Level': {
+ 'unit': "%",
+ 'factor': 1.0
+ },
+ # unused below here
+ 'Voltage': {
+ 'unit': " V",
+ 'factor': 1.0
+ },
+ 'Load': {
+ 'unit': "%",
+ 'factor': 1.0
+ },
+ 'Flow': {
+ 'unit': " L/h",
+ 'factor': 1.0
+ },
+ 'Control': {
+ 'unit': "%",
+ 'factor': 1.0
+ },
+ 'Factor': {
+ 'unit': "1",
+ 'factor': 1.0
+ },
+ 'Data': {
+ 'unit': " B",
+ 'factor': 1073741824.0
+ }
+}
+OpenhardwaremonitorSensor =
collections.namedtuple("OpenhardwaremonitorSensor",
+ ("reading",
"unit", "perf_var", "WMIstatus"))
def parse_openhardwaremonitor(info):
@@ -84,67 +126,30 @@ def parse_openhardwaremonitor(info):
if len(line) == 5:
# Old agent output has no WMIStatus column
_index, name, parent, sensor_type, value = line
- _wmistatus = 'OK'
+ wmistatus = 'OK'
elif len(line) == 6:
- _index, name, parent, sensor_type, value, _wmistatus = line
+ _index, name, parent, sensor_type, value, wmistatus = line
else:
continue
full_name = _create_openhardwaremonitor_full_name(parent, name)
- parsed.setdefault(sensor_type, {}).setdefault(full_name, float(value))
+ traits = OpenhardwaremonitorTraits.get(sensor_type, {})
+ parsed.setdefault(sensor_type, {}).setdefault(
+ full_name,
+ OpenhardwaremonitorSensor(
+ float(value) * traits.get('factor', 1),
traits.get('unit', ''),
+ traits.get('perf_var'), wmistatus))
return parsed
-def _openhardwaremonitor_type_trait(sensor_type):
- return {
- 'Clock': {
- 'unit': " MHz",
- 'factor': 1.0,
- 'perf_var': 'clock'
- },
- 'Temperature': {
- 'unit': u"°C",
- 'factor': 1.0
- },
- 'Power': {
- 'unit': " W",
- 'factor': 1.0,
- 'perf_var': 'w'
- },
- 'Fan': {
- 'unit': " RPM",
- 'factor': 1.0
- },
- 'Level': {
- 'unit': "%",
- 'factor': 1.0
- },
- # unused below here
- 'Voltage': {
- 'unit': " V",
- 'factor': 1.0
- },
- 'Load': {
- 'unit': "%",
- 'factor': 1.0
- },
- 'Flow': {
- 'unit': " L/h",
- 'factor': 1.0
- },
- 'Control': {
- 'unit': "%",
- 'factor': 1.0
- },
- 'Factor': {
- 'unit': "1",
- 'factor': 1.0
- },
- 'Data': {
- 'unit': " B",
- 'factor': 1073741824.0
- }
- }[sensor_type]
+def _create_openhardwaremonitor_full_name(parent, name):
+ def dict_replace(input_, replacements):
+ pattern = regex(r'\b(' + '|'.join(replacements.keys()) +
r')\b')
+ return pattern.sub(lambda x: replacements[x.group()], input_)
+
+ parent = dict_replace(parent, {"intelcpu": "cpu",
"amdcpu": "cpu", "genericcpu": "cpu"})
+ name = dict_replace(name, {"CPU ": "", "Temperature":
""})
+ return (parent.replace("/", "") + " " + name).strip()
def _openhardwaremonitor_worst_status(*args):
@@ -164,24 +169,24 @@ def inventory_openhardwaremonitor(sensor_type, parsed):
def check_openhardwaremonitor(sensor_type, item, params, parsed):
if item in parsed.get(sensor_type, {}):
- traits = _openhardwaremonitor_type_trait(sensor_type)
- val = parsed[sensor_type][item] * traits['factor']
+ data = parsed[sensor_type][item]
if 'lower' in params:
status_lower = _openhardwaremonitor_expect_order(params['lower'][1],
params['lower'][0],
- val)
+ data.reading)
else:
status_lower = 0
if 'upper' in params:
- status_upper = _openhardwaremonitor_expect_order(val,
params['upper'][0],
+ status_upper = _openhardwaremonitor_expect_order(data.reading,
params['upper'][0],
params['upper'][1])
else:
status_upper = 0
+
perfdata = []
- if 'perf_var' in traits:
- perfdata = [(traits['perf_var'], val)]
+ if data.perf_var:
+ perfdata = [(data.perf_var, data.reading)]
return (_openhardwaremonitor_worst_status(status_lower, status_upper),
- '%.1f%s' % (val, traits['unit']), perfdata)
+ '%.1f%s' % (data.reading, data.unit), perfdata)
# .--clock---------------------------------------------------------------.
@@ -223,10 +228,10 @@ def check_openhardwaremonitor_temperature(item, params, parsed):
break
if not found:
params = params["_default"]
+
if item in parsed.get('Temperature', {}):
- traits = _openhardwaremonitor_type_trait('Temperature')
- val = parsed['Temperature'][item] * traits['factor']
- return check_temperature(val, params, "openhardwaremonitor_%s" % item)
+ data = parsed['Temperature'][item]
+ return check_temperature(data.reading, params, "openhardwaremonitor_%s"
% item)
check_info['openhardwaremonitor.temperature'] = {
@@ -275,7 +280,8 @@ factory_settings['openhardwaremonitor_fan_default_levels'] =
{
def check_openhardwaremonitor_fan(item, params, parsed):
if item in parsed.get("Fan", {}):
- return check_fan(parsed["Fan"][item], params)
+ data = parsed["Fan"][item]
+ return check_fan(data.reading, params)
check_info['openhardwaremonitor.fan'] = {
@@ -323,7 +329,6 @@ def inventory_openhardwaremonitor_smart(parsed):
def check_openhardwaremonitor_smart(item, params, parsed):
for sensor_type, readings in openhardwaremonitor_smart_readings.iteritems():
- traits = _openhardwaremonitor_type_trait(sensor_type)
for reading in readings:
reading_name = "%s %s" % (item, reading['name'])
@@ -332,17 +337,17 @@ def check_openhardwaremonitor_smart(item, params, parsed):
continue
warn, crit = params[reading['key']]
- value = parsed[sensor_type][reading_name] * traits['factor']
+ data = parsed[sensor_type][reading_name]
if reading.get('lower_bounds', False):
- status = _openhardwaremonitor_expect_order(crit, warn, value)
+ status = _openhardwaremonitor_expect_order(crit, warn, data.reading)
else:
- status = _openhardwaremonitor_expect_order(value, warn, crit)
+ status = _openhardwaremonitor_expect_order(data.reading, warn, crit)
yield (
status,
- "%s %.1f%s" % (reading['name'], value,
traits['unit']),
- [(reading['key'], value)],
+ "%s %.1f%s" % (reading['name'], data.reading,
data.unit),
+ [(reading['key'], data.reading)],
)