Module: check_mk
Branch: master
Commit: dea0e5d9ac0f9b99129179e56893d1a5f7cea504
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dea0e5d9ac0f9b…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Aug 24 12:18:27 2017 +0200
5117 esx_vsphere_vm.devices: Check mounted devices in order to monitor HA functionality
If devices of typ VirtualCdrom, VirtualFloppy are mounted,
the HA functionality of the ESX system is not guaranteed
any more.
Change-Id: Ie7709767820abd78b130e90f238d48bcda68cb5a
---
.werks/5117 | 11 +++++++++
agents/special/agent_vsphere | 37 +++++++++++++++++++++------
checkman/esx_vsphere_vm.devices | 14 +++++++++++
checks/esx_vsphere_vm | 55 ++++++++++++++++++++++++++++++++++++++++-
4 files changed, 109 insertions(+), 8 deletions(-)
diff --git a/.werks/5117 b/.werks/5117
new file mode 100644
index 0000000..fbee863
--- /dev/null
+++ b/.werks/5117
@@ -0,0 +1,11 @@
+Title: esx_vsphere_vm.devices: Check mounted devices in order to monitor HA
functionality
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1503569745
+Class: feature
+
+If devices of the type VirtualCdrom, VirtualFloppy are mounted,
+the HA functionality of the ESX system is not guaranteed any more.
diff --git a/agents/special/agent_vsphere b/agents/special/agent_vsphere
index 8bfdc88..cebc547 100755
--- a/agents/special/agent_vsphere
+++ b/agents/special/agent_vsphere
@@ -1013,6 +1013,15 @@ if opt_tracefile:
sys.stderr.write("Path for tracefile %s does not exist" %
opt_tracefile)
sys.stderr.flush()
+
+# Create a search pattern for the get_pattern function
+# create_search_pattern(["label", "summary",
"startConnected", "allowGuestControl", "connected",
"status"])
+def create_search_pattern(tokens):
+ pattern_elements = []
+ for token in tokens:
+ pattern_elements.append("<%(token)s>(.*?)</%(token)s>" %
{"token": token})
+ return ".*?".join(pattern_elements)
+
def get_pattern(pattern, line):
if not line:
return []
@@ -1533,15 +1542,30 @@ if not error:
vm_data =
dict(get_pattern("<name>(.*?)</name><val.*?>(.*?)</val>",
entry))
if opt_skip_placeholder_vm and
is_placeholder_vm(vm_data.get("config.hardware.device")):
continue
- else:
- # we don't need this in the agent output
- if vm_data.get("config.hardware.device"):
- del vm_data["config.hardware.device"]
+
if "runtime.host" in vm_data:
vm_data["runtime.host"] =
hostsystems.get(vm_data["runtime.host"], vm_data["runtime.host"])
vm_esx_host.setdefault(vm_data["runtime.host"],
[]).append(vm_data["name"])
+
+ def eval_virtual_device(info):
+ response = []
+ virtual_devices = get_pattern("<VirtualDevice
(.*?)</VirtualDevice>", info)
+ show_fields = ["label", "summary",
"startConnected", "allowGuestControl", "connected",
"status"]
+ search_pattern = create_search_pattern(show_fields)
+ for virtual_device in virtual_devices:
+ type_info =
get_pattern("type=\"(.*?)\"", virtual_device)
+ device_info = get_pattern(search_pattern, virtual_device)
+ if device_info:
+ response.append("virtualDeviceType %s|%s" %
+ (type_info[0],
+ "|".join(map(lambda x:
"%s %s" % x, zip(show_fields, device_info[0]))))
+ )
+
+ return "@@".join(response)
+
+
def eval_snapshot_list(info):
response = []
snapshot_info =
get_pattern("<name>(.*?)</name>.*?<id>(.*?)</id><createTime>(.*?)</createTime><state>(.*?)</state>",
info)
@@ -1576,6 +1600,7 @@ if not error:
transform_functions = {
"snapshot.rootSnapshotList" : eval_snapshot_list,
"config.datastoreUrl" : eval_datastores,
+ "config.hardware.device" : eval_virtual_device,
}
for key, transform in transform_functions.items():
if key in vm_data:
@@ -1592,9 +1617,7 @@ if not error:
if data.get("name"):
output("<<<<%s>>>>" %
convert_hostname(key))
output("<<<esx_vsphere_vm>>>")
- entries = list(data.items())
- entries.sort()
- for entry in entries:
+ for entry in sorted(data.items()):
output("%s %s" % entry)
diff --git a/checkman/esx_vsphere_vm.devices b/checkman/esx_vsphere_vm.devices
new file mode 100644
index 0000000..f1df008
--- /dev/null
+++ b/checkman/esx_vsphere_vm.devices
@@ -0,0 +1,14 @@
+title: Virtual Machine under ESX: Mounted devices
+agents: vsphere
+catalog: os/kernel
+license: GPL
+distribution: check_mk
+description:
+ For a virtual machine running on ESX this check reviews the
+ mounted devices in order to monitor HA functionality.
+
+ Considered devices are of the type VirtualCdrom or VirtualFloppy.
+ If such device is connected, the check goes WARN, otherwise OK.
+
+inventory:
+ On each VM one check is generated.
diff --git a/checks/esx_vsphere_vm b/checks/esx_vsphere_vm
index d5492b5..efd3d13 100644
--- a/checks/esx_vsphere_vm
+++ b/checks/esx_vsphere_vm
@@ -24,6 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+
# TODO: name the next new subcheck "esx_vsphere_vm" and introduce a parse
function
def esx_vsphere_vm_convert(info):
data = {}
@@ -32,9 +33,9 @@ def esx_vsphere_vm_convert(info):
if line[0] == "config.template" and line[1] == "true":
return {}
data[line[0]] = line[1:]
-
return data
+
# .--Memory--------------------------------------------------------------.
# | __ __ |
# | | \/ | ___ _ __ ___ ___ _ __ _ _ |
@@ -453,3 +454,55 @@ check_info['esx_vsphere_vm.snapshots'] = {
"group" : "vm_snapshots",
"has_perfdata" : True,
}
+
+
+#.
+# .--VM devices----------------------------------------------------------.
+# | __ ____ __ _ _ |
+# | \ \ / / \/ | __| | _____ _(_) ___ ___ ___ |
+# | \ \ / /| |\/| | / _` |/ _ \ \ / / |/ __/ _ \/ __| |
+# | \ V / | | | | | (_| | __/\ V /| | (_| __/\__ \ |
+# | \_/ |_| |_| \__,_|\___| \_/ |_|\___\___||___/ |
+# | |
+# '----------------------------------------------------------------------'
+
+
+def parse_esx_vsphere_vm_mounted_devices(info):
+ data = esx_vsphere_vm_convert(info).get("config.hardware.device", [])
+ parsed = {}
+ for device_data in " ".join(data).split("@@"):
+ device_attrs = {}
+ for entry in device_data.split("|"):
+ k, v = entry.split(" ", 1)
+ device_attrs.setdefault(k, v)
+ device_name = device_attrs["label"]
+ del device_attrs["label"]
+ parsed.setdefault(device_name, device_attrs)
+ return parsed
+
+
+def inventory_esx_vsphere_vm_mounted_devices(info):
+ if parse_esx_vsphere_vm_mounted_devices(info):
+ return [(None, None)]
+
+
+def check_esx_vsphere_vm_mounted_devices(item, params, info):
+ device_types = ['VirtualCdrom', 'VirtualFloppy']
+ mounted_devices = []
+ for device_name, attrs in parse_esx_vsphere_vm_mounted_devices(info).iteritems():
+ if attrs['virtualDeviceType'] in device_types and \
+ attrs['connected'] == 'true':
+ mounted_devices.append(device_name)
+
+ if mounted_devices:
+ return 1, "HA functionality not guaranteed, Mounted devices: %s" % \
+ ", ".join(mounted_devices)
+ else:
+ return 0, "HA functionality guaranteed"
+
+
+check_info['esx_vsphere_vm.mounted_devices'] = {
+ "inventory_function" : inventory_esx_vsphere_vm_mounted_devices,
+ "check_function" : check_esx_vsphere_vm_mounted_devices,
+ "service_description" : "ESX Mounted Devices",
+}