Module: check_mk
Branch: master
Commit: eacda39d46a58b02e2995e2f1d1eb0959dc6c71d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=eacda39d46a58b…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Oct 7 13:56:17 2016 +0200
cleanup in humidity.include, made levels handling more flexible
---
checks/humidity.include | 46 +++++++++++++++++++++++-------------
web/plugins/wato/check_parameters.py | 38 ++++++++++++++++++++++-------
2 files changed, 60 insertions(+), 24 deletions(-)
diff --git a/checks/humidity.include b/checks/humidity.include
index 9d3baaa..b3e7834 100644
--- a/checks/humidity.include
+++ b/checks/humidity.include
@@ -24,37 +24,51 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-def check_humidity(humidity, params):
- if params:
- crit_lower, warn_lower, warn_upper, crit_upper = params
+# old params = (crit_low , warn_low, warn, crit)
+def check_humidity(humidity, params):
+ if params and type(params) in [ list, tuple ]:
+ params = {
+ "levels_lower" : (params[0], params[1]),
+ "levels" : (params[2], params[3]),
+ }
else:
- crit_lower, warn_lower, warn_upper, crit_upper = -1, -1, 101, 101
+ params = {
+ "levels_lower" : (-1, -1),
+ "levels" : (101, 101),
+ }
+ crit_lower, warn_lower = params["levels_lower"]
+ warn_upper, crit_upper = params["levels"]
perfdata = [ ("humidity", humidity, warn_upper, crit_upper, 0, 100) ]
infotext = get_percent_human_readable(humidity)
- levelstext = ""
- levelstext_lower = " (warn/crit at or below %s/%s)" % (
+
+ levelstext_lower = " (warn/crit below %s/%s)" % (
get_percent_human_readable(warn_lower),
get_percent_human_readable(crit_lower))
- levelstext_upper = " (warn/crit at or above %s/%s)" % (
+ levelstext_upper = " (warn/crit at %s/%s)" % (
get_percent_human_readable(warn_upper),
get_percent_human_readable(crit_upper))
- if humidity <= crit_lower:
+ status = 0
+ levelstext = ""
+ if humidity < crit_lower:
status = 2
- levelstext += levelstext_lower
+ levelstext = levelstext_lower
+
elif humidity >= crit_upper:
status = 2
- levelstext += levelstext_upper
- elif humidity <= warn_lower:
+ levelstext = levelstext_upper
+
+ elif humidity < warn_lower:
status = 1
- levelstext += levelstext_lower
+ levelstext = levelstext_lower
+
elif humidity >= warn_upper:
status = 1
- levelstext += levelstext_upper
- else:
- status = 0
+ levelstext = levelstext_upper
+
+ if status:
+ infotext += levelstext
- infotext += levelstext
return status, infotext, perfdata
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index e2c7056..47b2844 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -7188,18 +7188,40 @@ register_check_parameters(
"dict",
)
+def transform_humidity(p):
+ if type(p) in [ list, tuple ]:
+ p = {
+ "levels_lower" : (float(p[1]), float(p[0])),
+ "levels" : (float(p[2]), float(p[3])),
+ }
+ return p
+
register_check_parameters(
subgroup_environment,
"humidity",
_("Humidity Levels"),
- Tuple(
- help = _("This Ruleset sets the threshold limits for humidity
sensors"),
- elements = [
- Integer(title = _("Critical at or below"), unit="%" ),
- Integer(title = _("Warning at or below"), unit="%" ),
- Integer(title = _("Warning at or above"), unit="%" ),
- Integer(title = _("Critical at or above"), unit="%" ),
- ]),
+ Transform(
+ Dictionary(
+ help = _("This Ruleset sets the threshold limits for humidity
sensors"),
+ elements = [
+ ("levels", Tuple(
+ title = _("Upper levels"),
+ elements = [
+ Percentage(title=_("Warning at")),
+ Percentage(title=_("Critical at")),
+ ]
+ )),
+ ("levels_lower", Tuple(
+ title = _("Lower levels"),
+ elements = [
+ Percentage(title=_("Warning below")),
+ Percentage(title=_("Critical below")),
+ ]
+ )),
+ ]
+ ),
+ forth = transform_humidity,
+ ),
TextAscii(
title = _("Sensor name"),
help = _("The identifier of the sensor."),