Module: check_mk
Branch: master
Commit: ddc0cf0432919336d2ee8bda9ab9bbb4f7858568
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ddc0cf04329193…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Jan 18 13:12:34 2018 +0100
5619 FIX memory.include: Ignoring levels led to a crash because the handling of the
paramters was not correct
Change-Id: Ibfffb74ea8a391d4f27eaa24849fe8b4920ab319
---
.werks/5619 | 11 +++++++++++
checks/memory.include | 53 ++++++++++++++++++++++++---------------------------
2 files changed, 36 insertions(+), 28 deletions(-)
diff --git a/.werks/5619 b/.werks/5619
new file mode 100644
index 0000000..efb311c
--- /dev/null
+++ b/.werks/5619
@@ -0,0 +1,11 @@
+Title: memory.include: Ignoring levels led to a crash because the handling of the
paramters was not correct
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i3
+Date: 1516277491
+
+
diff --git a/checks/memory.include b/checks/memory.include
index c5e40ef..3b34235 100644
--- a/checks/memory.include
+++ b/checks/memory.include
@@ -39,38 +39,35 @@ def check_memory_simple(used, total, params):
get_bytes_human_readable(used),
get_bytes_human_readable(total))
- levelstext = ""
-
status = 0
- # No levels imposed
- if params["levels"][0] == "ignore":
- warn_abs, crit_abs = None, None
-
- # Absolute or percentual levels
- else:
- if params["levels"][0] == "perc_used":
- warn_perc, crit_perc = params["levels"][1]
- warn_abs = (warn_perc / 100.0) * total
- crit_abs = (crit_perc / 100.0) * total
- levelstext = " (warn/crit at %s/%s used)" % (
- get_percent_human_readable(warn_perc),
- get_percent_human_readable(crit_perc))
+ if params["levels"][0] == "perc_used":
+ warn_perc, crit_perc = params["levels"][1]
+ warn_abs = (warn_perc / 100.0) * total
+ crit_abs = (crit_perc / 100.0) * total
+ levelstext = " (warn/crit at %s/%s used)" % (
+ get_percent_human_readable(warn_perc),
+ get_percent_human_readable(crit_perc))
- elif params["levels"][0] == "abs_free":
- warn_abs_free, crit_abs_free = params["levels"][1]
- warn_abs = total - warn_abs_free
- crit_abs = total - crit_abs_free
- levelstext = " (warn/crit below %s/%s free)" % (
- get_bytes_human_readable(warn_abs_free),
- get_bytes_human_readable(crit_abs_free))
+ elif params["levels"][0] == "abs_free":
+ warn_abs_free, crit_abs_free = params["levels"][1]
+ warn_abs = total - warn_abs_free
+ crit_abs = total - crit_abs_free
+ levelstext = " (warn/crit below %s/%s free)" % (
+ get_bytes_human_readable(warn_abs_free),
+ get_bytes_human_readable(crit_abs_free))
- if used >= crit_abs:
- status = 2
- elif used >= warn_abs:
- status = 1
+ else:
+ # No levels imposed, ie. params = {'levels': 'ignore'}
+ crit_abs = None
+ warn_abs = None
+ levelstext = ""
- if status:
- infotext += levelstext
+ if crit_abs is not None and used >= crit_abs:
+ status = 2
+ elif warn_abs is not None and used >= warn_abs:
+ status = 1
+ if status:
+ infotext += levelstext
perfdata = [ ("memory_used", used, warn_abs, crit_abs, 0, total) ]
return status, infotext, perfdata