Module: check_mk
Branch: master
Commit: 2b570e2dce03bb67e5ec97a961aff1fb8b8733f6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2b570e2dce03bb…
Author: Konstantin Büttner <kb(a)mathias-kettner.de>
Date: Wed Oct 1 11:50:10 2014 +0200
hwg_temp: Reworked to use include function
---
checks/hwg_temp | 60 ++++++++++++++++++++++++++++++-------------------------
1 file changed, 33 insertions(+), 27 deletions(-)
diff --git a/checks/hwg_temp b/checks/hwg_temp
index e29dd8b..e397a76 100644
--- a/checks/hwg_temp
+++ b/checks/hwg_temp
@@ -28,11 +28,12 @@
hwg_temp_defaultlevels = (23, 25)
def inventory_hwg_temp(info):
- return [ (line[0], "hwg_temp_defaultlevels" ) for line in info if
int(line[2]) != 0]
+ return [ (line[0], "hwg_temp_defaultlevels")
+ for line in info
+ if int(line[2]) != 0 and line[5] in ["1", "2",
"3"] ]
def check_hwg_temp(item, params, info):
- warn, crit = params
status_text = {
"0" : "Invalid",
"1" : "Normal",
@@ -40,36 +41,42 @@ def check_hwg_temp(item, params, info):
"3" : "Out Of Range High",
"4" : "Alarm Low",
"5" : "Alarm High",
- }
+ }
+
unit_text = {
"0" : "unknown",
"1" : "°C",
"2" : "°F",
"3" : "°K",
"4" : "%",
- }
- for line in info:
- if line[0] == item:
- descr, status, current, current_m, unit = line[1:]
- current_state = savefloat(current_m)/10
+ }
+
+ # Nomenclature in this check: sensorstatus is what the device sends, state is what
the check returns.
+ for index, descr, sensorstatus, current, unit in info:
+ if index == item:
+ tempval = float(current)
+ if unit == "2":
+ temp = fahrenheit_to_celsius(tempval)
+ elif unit == "3":
+ temp = tempval - 273.15
+ elif unit == "4":
+ return
+ else:
+ temp = tempval
+
+ state, infotext, perfdata = check_temperature(temp, params)
+ if descr:
+ infotext += " (%s)" % descr
+ yield state, infotext, perfdata
- state = 0
- if current_state >= crit:
- state = 2
- elif current_state >= warn:
- state = 1
- elif status in ('4', '2'):
- state = 1
- elif status in('0', '3', '5'):
- state = 2
+ if sensorstatus != '1':
+ if sensorstatus in ['2', '3', '4', '5']:
+ state = 2
+ else:
+ state = 3
- perfdata = [ ("temp", current, warn, crit, 0 ) ]
- unit = unit_text.get(unit)
- status = status_text.get(status, "UNKOWN")
- return(state, "%s at %s%s (warn/crit at %s%s/%s%s), Status is %s" %
\
- (descr, current, unit, warn, unit, crit, unit, status), perfdata)
+ yield state, "Status is %s" % status_text.get(sensorstatus,
"UNKNOWN")
- return (3, "Sensor %s not found in SNMP data %s" % (item) )
check_info['hwg_temp'] = {
"check_function" : check_hwg_temp,
@@ -84,12 +91,11 @@ check_info['hwg_temp'] = {
"1.3",
# current value string
"1.4",
- # current value*10 integer
- "1.5",
# sensor unit integer 0=unknown, 1=°C, 2=°F, 3=°K, 4=%
"1.7",
]),
- "snmp_scan_function" : lambda oid: "hwg" in
oid(".1.3.6.1.2.1.1.1.0").lower(),
- "group" : "room_temperature",
+ "snmp_scan_function" : lambda oid: "hwg" in
oid(".1.3.6.1.2.1.1.1.0").lower(),
+ "group" : "room_temperature",
+ "includes" : [ "temperature.include" ],
}