Module: check_mk
Branch: master
Commit: 0ecd71cf46e03e6b57273739b15d17900050bd39
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0ecd71cf46e03e…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Wed Sep 26 14:07:06 2018 +0200
6576 agent_vsphere: Display snapshots on ESX host
An aggregation of the created VM snapshots can now be shown for
every ESX host (configurable via WATO rule
"Check state of VMWare ESX via vSphere").
Change-Id: I01012ebdd0dbe81e5ea3d59b1d41bc8eb205f133
---
.werks/6576 | 12 +++++++++++
agents/special/agent_vsphere | 32 +++++++++++++++++++++++++++--
checks/agent_vsphere | 3 +++
checks/esx_vsphere_vm | 2 +-
cmk/gui/plugins/wato/datasource_programs.py | 17 +++++++++++++++
5 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/.werks/6576 b/.werks/6576
new file mode 100644
index 0000000..2bebde7
--- /dev/null
+++ b/.werks/6576
@@ -0,0 +1,12 @@
+Title: agent_vsphere: Display snapshots on ESX host
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1537963438
+Class: feature
+
+An aggregation of the created VM snapshots can now be shown for
+every ESX host (configurable via WATO rule
+"Check state of VMWare ESX via vSphere").
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index ff742be..e0ef0b7 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -834,14 +834,17 @@ OPTIONS:
Default (no option) is on the queried vCenter or
ESX-Host
Possible WHERE options: * esxhost : show on ESX host
* vm : show on virtual
machine
-
+ --snapshot_display WHERE Specifies where the virtual machines snapshots should be
shown
+ Default (no option) is on the VM
+ Possible WHERE options: * esxhost : show on ESX host
+ * vCenter : show on vCenter
""")
short_options = "hi:u:s:Dat:H:Pp:S:"
long_options = [
"help", "user=", "secret=", "direct",
"agent", "debug", "modules=", "timeout=",
"no-cert-check",
"hostname=", "tracefile=", "pysphere",
"port=", "spaces=", "host_pwr_display=",
"vm_pwr_display=",
- "vm_piggyname="
+ "snapshot_display=", "vm_piggyname="
]
opt_debug = False
@@ -855,6 +858,7 @@ opt_pysphere = False
opt_tracefile = None
opt_host_pwr_display = None
opt_vm_pwr_display = None
+opt_snapshot_display = None
opt_vm_piggyname = "alias"
opt_spaces = "underscore"
opt_no_cert = False
@@ -908,6 +912,8 @@ for o,a in opts:
opt_vm_pwr_display = a
elif o in [ '--host_pwr_display' ]:
opt_host_pwr_display = a
+ elif o in [ '--snapshot_display' ]:
+ opt_snapshot_display = a
elif o in [ '-S', '--spaces']:
if a not in [ "cut", "underscore" ]:
usage()
@@ -1175,6 +1181,24 @@ def login():
cookie_file.write(server_cookie)
+def output_aggregated_snapshots(vms, hostsystems=None):
+
+ aggregated = {}
+ for data in vms.itervalues():
+ if hostsystems is not None:
+ running_on = hostsystems.get(data.get("runtime.host"),
data.get("runtime.host"))
+ else:
+ running_on = ''
+ snapshots = data.get("snapshot.rootSnapshotList")
+ if snapshots is not None:
+ aggregated.setdefault(running_on, []).append(snapshots)
+
+ for piggytarget, sn_list in aggregated.iteritems():
+ output('<<<<%s>>>>' % piggytarget)
+ output('<<<esx_vsphere_vm>>>')
+ output('snapshot.rootSnapshotList %s' % '|'.join(sn_list))
+ output('<<<<>>>>')
+
# .--Main----------------------------------------------------------------.
# | __ __ _ |
@@ -1600,6 +1624,10 @@ if not error:
for entry in sorted(data.items()):
output("%s %s" % entry)
+ if opt_snapshot_display == 'esxhost':
+ output_aggregated_snapshots(vms, hostsystems)
+ elif opt_snapshot_display == 'vCenter':
+ output_aggregated_snapshots(vms)
output("<<<<>>>>")
diff --git a/checks/agent_vsphere b/checks/agent_vsphere
index c44a9bb..d6abe5c 100644
--- a/checks/agent_vsphere
+++ b/checks/agent_vsphere
@@ -74,6 +74,9 @@ def agent_vsphere_arguments(params, hostname, ipaddress):
if params.get("host_pwr_display"):
args += ' --host_pwr_display %s' %
params.get("host_pwr_display")
+ if params.get("snapshot_display", False):
+ args += ' --snapshot_display %s' %
params.get("snapshot_display")
+
if "ssl" in params:
if params["ssl"] is False:
args += ' --no-cert-check ' + quote_shell_string(ipaddress)
diff --git a/checks/esx_vsphere_vm b/checks/esx_vsphere_vm
index 3b1547b..38e6b5f 100644
--- a/checks/esx_vsphere_vm
+++ b/checks/esx_vsphere_vm
@@ -404,7 +404,7 @@ def check_esx_vsphere_vm_snapshots(_no_item, params, info):
return
powerd_on_list = [s for s in snapshots if s.state == "poweredOn"]
- yield 0, "Powered On: %s" % powerd_on_list[0].name if powerd_on_list else
"None"
+ yield 0, "Powered On: %s" % (', '.join(s.name for s in
powerd_on_list) or "None")
latest_snapshot = max(snapshots, key=lambda s: s.time)
latest_snapshot_age = time.time() - latest_snapshot.time
diff --git a/cmk/gui/plugins/wato/datasource_programs.py
b/cmk/gui/plugins/wato/datasource_programs.py
index 67c237a..f0e99f5 100644
--- a/cmk/gui/plugins/wato/datasource_programs.py
+++ b/cmk/gui/plugins/wato/datasource_programs.py
@@ -208,6 +208,23 @@ register_rule(group,
default = None,
)
),
+ ( "snapshot_display",
+ DropdownChoice(
+ title = _("<i>Additionally</i> display snapshots
on"),
+ help = _("The created snapshots can be displayed additionally
either "
+ "on the ESX host or the vCenter. This will result in
services "
+ "for <i>both</i> the queried system and
the ESX host / vCenter. "
+ "By disabling the unwanted services it is then
possible "
+ "to configure where the services are
displayed."
+ ),
+ choices = [
+ ( None, _("The Virtual Machine") ),
+ ( "esxhost", _("The ESX Host") ),
+ ( "vCenter", _("The queried ESX system (vCenter
/ Host)") ),
+ ],
+ default = None,
+ )
+ ),
( "vm_piggyname",
DropdownChoice(
title = _("Piggyback name of virtual machines"),