Module: check_mk
Branch: master
Commit: 41e1fb0dd0d247081957cc9dde60139ab5231ca8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=41e1fb0dd0d247…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Jul 13 10:10:35 2018 +0200
Minor cleanup
Change-Id: Ia228c468551ef77ade51e76b294129e534603206
---
checks/hwg_temp | 120 +++++++++++++++++++++++++++++++++-----------------------
1 file changed, 72 insertions(+), 48 deletions(-)
diff --git a/checks/hwg_temp b/checks/hwg_temp
index de9dc7e..caab1e2 100644
--- a/checks/hwg_temp
+++ b/checks/hwg_temp
@@ -29,66 +29,90 @@ factory_settings["hwg_temp_defaultlevels"] = {
"levels": (30, 35)
}
-def inventory_hwg_temp(info):
- for line in info:
- if int(line[2]) != 0 and line[4] in ["1", "2",
"3"]:
- yield line[0], {}
-
-def check_hwg_temp(item, params, info):
- status_text = {
- "0" : "Invalid",
- "1" : "Normal",
- "2" : "Out Of Range Low",
- "3" : "Out Of Range High",
- "4" : "Alarm Low",
- "5" : "Alarm High",
+
+def parse_hwg_temp(info):
+ map_units = {
+ "1": "c",
+ "2": "f",
+ "3": "k",
+ # Also possible but invalid: "4"
+ }
+
+ map_dev_states = {
+ "0" : "invalid",
+ "1" : "normal",
+ "2" : "out of range low",
+ "3" : "out of range high",
+ "4" : "alarm low",
+ "5" : "alarm high",
}
- # Nomenclature in this check: sensorstatus is what the device sends, state is what
the check returns.
+ parsed = {}
for index, descr, sensorstatus, current, unit in info:
- if index == item:
+ try:
tempval = float(current)
- if unit == "2":
- dev_unit = "f"
- elif unit == "3":
- dev_unit = "k"
- elif unit == "4":
- return
- else:
- dev_unit = "c"
-
- state, infotext, perfdata = check_temperature(tempval, params,
"hwg_temp_%s" % item,
- dev_unit)
- if descr:
- infotext += " (%s)" % descr
- yield state, infotext, perfdata
-
- if sensorstatus != '1':
- if sensorstatus in ['2', '3', '4', '5']:
- state = 2
- else:
- state = 3
-
- yield state, "Status is %s" % status_text.get(sensorstatus,
"UNKNOWN")
+ except ValueError:
+ tempval = None
+
+ parsed.setdefault(index, {
+ "description" : descr,
+ "dev_unit" : map_units.get(unit),
+ "temperature" : tempval,
+ "dev_status_name" : map_dev_states.get(sensorstatus,
""),
+ "dev_status" : sensorstatus,
+ })
+
+ return parsed
+
+
+def inventory_hwg_temp(parsed):
+ for index, attrs in parsed.iteritems():
+ if attrs["dev_status_name"] not in ["invalid", ""]
\
+ and attrs["dev_unit"] in ["c", "f",
"k"]:
+ yield index, {}
+
+
+def check_hwg_temp(item, params, parsed):
+ if item not in parsed:
+ return
+
+ map_readable_states = {
+ "invalid" : 3,
+ "normal" : 0,
+ "out of range low" : 2,
+ "out of range high" : 2,
+ "alarm low" : 2,
+ "alarm high" : 2,
+ }
+
+ attrs = parsed[item]
+ state = map_readable_states.get(attrs["dev_status"], 3)
+ state_readable = attrs["dev_status_name"]
+ temp = attrs["temperature"]
+ if temp is None:
+ return state, "Status: %s" % state_readable
+ else:
+ state, infotext, perfdata = check_temperature(temp, params,
"hwg_temp_%s" % item,
+
dev_unit=attrs["dev_unit"], dev_status=state,
+ dev_status_name=state_readable)
+ descr = attrs["description"]
+ return state, "%s%s" % ("[%s] " % descr if descr else
"", infotext), perfdata
check_info['hwg_temp'] = {
+ 'parse_function' : parse_hwg_temp,
"check_function" : check_hwg_temp,
"inventory_function" : inventory_hwg_temp,
"service_description" : "Temperature %s",
"has_perfdata" : True,
- "snmp_info" : (".1.3.6.1.4.1.21796.4.1.3", [# sensors index
(1-2)
- "1.1",
- # sensor name string
- "1.2",
- # unit state: 0=Invalid, 1=Normal, 2=OutOfRangeLo, 3=OutOfRangeHi, 4=AlarmLo,
5=AlarmHi
- "1.3",
- # current value string
- "1.4",
- # sensor unit integer 0=unknown, 1=°C, 2=°F, 3=°K, 4=%
- "1.7",
+ "snmp_info" : (".1.3.6.1.4.1.21796.4.1.3", [ # DAMOCLES-MIB.txt
+ "1.1", # index
+ "1.2", # sensName
+ "1.3", # sensState
+ "1.4", # sensString
+ "1.7", # sensUnit
]),
- "snmp_scan_function" : lambda oid: "hwg" in
oid(".1.3.6.1.2.1.1.1.0").lower(),
+ "snmp_scan_function" : lambda oid: "hwg" in
oid(".1.3.6.1.2.1.1.1.0", "").lower(),
"group" : "temperature",
"includes" : [ "temperature.include" ],
"default_levels_variable" : "hwg_temp_defaultlevels"