Module: check_mk
Branch: master
Commit: ba0515c2c740dc5cda7b160905f471a8a19618b3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ba0515c2c740dc…
Author: Marcel Arentz <ma(a)mathias-kettner.de>
Date: Wed Mar 15 17:02:52 2017 +0100
4541 esx_vsphere_vm: Added age of oldest snapshot
This new information can also be configured by rule as the existing one.
Change-Id: I4271b08c28da7ee7fe83f918c32dd4d6c26b344c
---
.werks/4541 | 10 +++++++
checkman/esx_vsphere_vm.snapshots | 1 +
checks/esx_vsphere_vm | 53 ++++++++++++++++++++++++++++--------
web/plugins/wato/check_parameters.py | 12 +++++++-
4 files changed, 63 insertions(+), 13 deletions(-)
diff --git a/.werks/4541 b/.werks/4541
new file mode 100644
index 0000000..aa63253
--- /dev/null
+++ b/.werks/4541
@@ -0,0 +1,10 @@
+Title: esx_vsphere_vm: Added age of oldest snapshot
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1489593672
+Class: feature
+
+This new information can also be configured by rule as the existing one.
diff --git a/checkman/esx_vsphere_vm.snapshots b/checkman/esx_vsphere_vm.snapshots
index 84c4315..481901e 100644
--- a/checkman/esx_vsphere_vm.snapshots
+++ b/checkman/esx_vsphere_vm.snapshots
@@ -6,6 +6,7 @@ distribution: check_mk
description:
For a virtual machine running on ESX this check reports the number of
snapshots, the currently running snapshot and the age of the latest snapshot
+ as well as the oldest snapshot.
inventory:
On each VM one check is generated if there is snapshot information available
diff --git a/checks/esx_vsphere_vm b/checks/esx_vsphere_vm
index 18501c4..c6e49b6 100644
--- a/checks/esx_vsphere_vm
+++ b/checks/esx_vsphere_vm
@@ -379,43 +379,72 @@ def inventory_esx_vsphere_vm_snapshots(info):
return [(None, {})]
def check_esx_vsphere_vm_snapshots(_no_item, params, info):
+ def check_levels(age, warn, crit):
+ if age >= crit:
+ return (2, "snapshot is older than %s" %
get_age_human_readable(age))
+ elif age >= warn:
+ return (1, "snapshot is older than %s" %
get_age_human_readable(age))
+ else:
+ return (0, "")
+
data = esx_vsphere_vm_convert(info)
if 'snapshot.rootSnapshotList' not in data:
yield 0, "No snapshots found"
else:
last_snapshot = None
+ oldest_snapshot = None
powered_on_snapshot = None
snapshots = map(lambda x: x.split(" ", 3), "
".join(data["snapshot.rootSnapshotList"]).split("|"))
snapshots = map(lambda x: (int(x[0]), int(x[1]), x[2], x[3]) , snapshots)
yield 0, "Number of Snapshots %d" % len(snapshots)
if len(snapshots) > 0:
+ perfdata = []
+ last_time = max(zip(*snapshots)[1])
+ oldest_time = min(zip(*snapshots)[1])
last_snapshot = snapshots[0]
+ oldest_snapshot = snapshots[0]
for snapshot in snapshots:
- if snapshot[1] > last_snapshot[1]:
+ if last_time == snapshot[1]:
last_snapshot = snapshot
- if snapshot[2] == "poweredOn":
+ elif oldest_time == snapshot[1]:
+ oldest_snapshot = snapshot
+
+ if "poweredOn" == snapshot[2]:
powered_on_snapshot = snapshot
yield 0, "Powered On: %s" % (powered_on_snapshot and
powered_on_snapshot[3] or "None")
- perfdata = []
- snapshot_age = time.time() - last_snapshot[1]
+ last_snapshot_age = time.time() - last_snapshot[1]
if params.get("age"):
warn, crit = params["age"]
- if snapshot_age > crit:
- yield 2, "Snapshot is older than %s" %
get_age_human_readable(snapshot_age)
- elif snapshot_age > warn:
- yield 1, "Snapshot is older than %s" %
get_age_human_readable(snapshot_age)
- perfdata = [("age", snapshot_age, warn, crit)]
- else:
- perfdata = [("age", snapshot_age)]
-
+ state, message = check_levels(last_snapshot_age, warn, crit)
+ if state > 0:
+ yield state, "Last %s" % message,
+ perfdata = [ ("age", last_snapshot_age, warn, crit) ]
+ else:
+ perfdata = [ ("age", last_snapshot_age) ]
yield 0, "Last Snapshot: %s %s" % (last_snapshot[3],
time.strftime("%D
%H:%M",time.localtime(last_snapshot[1]))),\
perfdata
+ # Display oldest snapshot only, if it is not identical with the last
snapshot
+ if not oldest_snapshot == last_snapshot:
+ oldest_snapshot_age = time.time() - oldest_snapshot[1]
+ if params.get("age_oldest"):
+ warn, crit = params["age_oldest"]
+ state, message = check_levels(oldest_snapshot_age, warn, crit)
+ if state > 0:
+ yield state, "Oldest %s" % message,
+ perfdata = [ ("age_oldst", oldest_snapshot_age, warn,
crit) ]
+ else:
+ perfdata = [ ("age_oldest", oldest_snapshot_age) ]
+
+ yield 0, "Oldest Snapshot: %s %s" % (oldest_snapshot[3],
+ time.strftime("%D
%H:%M",time.localtime(oldest_snapshot[1]))),\
+ perfdata
+
check_info['esx_vsphere_vm.snapshots'] = {
"inventory_function" : inventory_esx_vsphere_vm_snapshots,
diff --git a/web/plugins/wato/check_parameters.py b/web/plugins/wato/check_parameters.py
index 96d5b96..bb82c0b 100644
--- a/web/plugins/wato/check_parameters.py
+++ b/web/plugins/wato/check_parameters.py
@@ -9028,7 +9028,17 @@ register_check_parameters(
Age(title = _("Critical if older than"))
]
)
- )]
+ ),
+ ("age_oldest",
+ Tuple(
+ title = _("Age of the oldest snapshot"),
+ elements = [
+ Age(title = _("Warning if older than")),
+ Age(title = _("Critical if older than"))
+ ]
+ )
+ ),
+ ]
),
None,
match_type = "dict",