Module: check_mk
Branch: master
Commit: 4e7e20681bc73d79570b2687590f67d30bd5a4e9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4e7e20681bc73d…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue May 8 11:05:36 2018 +0200
6000 FIX statgrab_mem: Missing data caused UnboundLocalError
Change-Id: I45830cc7e8d4d22f4c9a97d6fab83bb09eea9a20
---
.werks/6000 | 10 ++++++++++
checks/statgrab_mem | 38 +++++++++++++++++++++++++-------------
2 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/.werks/6000 b/.werks/6000
new file mode 100644
index 0000000..27a3162
--- /dev/null
+++ b/.werks/6000
@@ -0,0 +1,10 @@
+Title: statgrab_mem: Missing data caused UnboundLocalError
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1525770293
+Class: fix
+
+
diff --git a/checks/statgrab_mem b/checks/statgrab_mem
index e171359..ba8dc19 100644
--- a/checks/statgrab_mem
+++ b/checks/statgrab_mem
@@ -24,23 +24,35 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+
memused_default_levels = (150.0, 200.0)
+
def parse_statgrab_mem(info):
+ parsed = {}
for var, value in info:
- if var == 'mem.used': memused_kb = int(value) / 1024
- elif var == 'mem.total': totalmem_kb = int(value) / 1024
- elif var == 'swap.used': swapused_kb = int(value) / 1024
- elif var == 'swap.total': totalswap_kb = int(value) / 1024
- elif var == 'mem.cache': caches_kb = int(value) / 1024
-
- return {
- "MemTotal" : totalmem_kb,
- "MemFree" : totalmem_kb - memused_kb,
- "SwapTotal" : totalswap_kb,
- "SwapFree" : totalswap_kb - swapused_kb,
- "Cached" : caches_kb,
- }
+ try:
+ parsed.setdefault(var, int(value) / 1024)
+ except ValueError:
+ pass
+
+ try:
+ totalmem_kb = parsed['mem.total']
+ memused_kb = parsed['mem.used']
+ totalswap_kb = parsed['swap.total']
+ swapused_kb = parsed['swap.used']
+ instance = {
+ "MemTotal" : totalmem_kb,
+ "MemFree" : totalmem_kb - memused_kb,
+ "SwapTotal" : totalswap_kb,
+ "SwapFree" : totalswap_kb - swapused_kb,
+ }
+ if 'mem.cache' in parsed:
+ instance.setdefault("Cached", parsed['mem.cache'])
+ return instance
+
+ except KeyError:
+ return {}
def inventory_statgrab_mem(parsed):