Module: check_mk
Branch: master
Commit: c0e206a5204a9e6986403d33acfda01c1d410b07
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c0e206a5204a9e…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Jul 6 14:20:55 2018 +0200
6307 FIX hyperv_checkpoints: Parameters did not correctly apply
Change-Id: Ic57cd6b715de3cdd5259f984cb49ead70dfb55a6
---
.werks/6307 | 11 +++++++++++
checks/hyperv_checkpoints | 49 +++++++++++++++++++++++++++--------------------
2 files changed, 39 insertions(+), 21 deletions(-)
diff --git a/.werks/6307 b/.werks/6307
new file mode 100644
index 0000000..01c580e
--- /dev/null
+++ b/.werks/6307
@@ -0,0 +1,11 @@
+Title: hyperv_checkpoints: Parameters did not correctly apply
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1530879569
+
+
diff --git a/checks/hyperv_checkpoints b/checks/hyperv_checkpoints
index 9378e0a..0c3d79d 100644
--- a/checks/hyperv_checkpoints
+++ b/checks/hyperv_checkpoints
@@ -31,33 +31,41 @@
def inventory_hyperv_checkpoints(info):
- return [ (None, {} )]
+ return [(None, {})]
-def check_hyperv_checkpoints(item, params, info):
- oldest = 0
- number_of_checkpoints = 0
+def check_hyperv_checkpoints(item, params, info):
+ snapshots = []
for line in info:
- if len(line) == 2:
- snapshot, age = line
- oldest = max(int(age), oldest)
- number_of_checkpoints += 1
+ if len(line) != 2:
+ continue
+ snapshots.append((line[0], int(line[1])))
- if number_of_checkpoints > 0:
- state = 0
- if params.get('age'):
- warn, crit = params['age']
- if crit >= oldest:
+ if snapshots:
+ yield 0, "%s checkpoints" % len(snapshots)
+
+ # We assume that the last snapshot is the last line
+ # of the agent output
+ for title, key, snapshot in [
+ ("Oldest", "age_oldest", max(snapshots, key=lambda
x:x[1])),
+ ("Last", "age", snapshots[-1]),
+ ]:
+ name, age = snapshot
+ infotext = "%s: %s (%s)" % (title, get_age_human_readable(age),
name)
+ warn, crit = params.get(key, (None, None))
+ if crit is not None and age >= crit:
state = 2
- elif warn >= oldest:
+ elif warn is not None and age >= warn:
state = 1
- perfdata = [("age", oldest, warn, crit)]
- else:
- perfdata = [("age", oldest)]
- return state, "%s Checkpoints, Oldest is: %s" % \
- (number_of_checkpoints, get_age_human_readable(oldest)),
perfdata
+ else:
+ state = 0
+ if state:
+ infotext += " (warn/crit at %s/%s)" % (
+ get_age_human_readable(warn),
+ get_age_human_readable(crit))
+ yield state, infotext, [(key, age, warn, crit)]
else:
- return 0, "No Checkpoints found", [("age", 0)]
+ yield 0, "No Checkpoints found"
check_info["hyperv_checkpoints"] = {
@@ -67,4 +75,3 @@ check_info["hyperv_checkpoints"] = {
"group" : "vm_snapshots",
"has_perfdata" : True,
}
-