Module: check_mk
Branch: master
Commit: 1577f5816924cb45259014ba92262554bf1744aa
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1577f5816924cb…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Dec 8 16:08:19 2014 +0100
#1712 FIX hyper_vms: fixed for snapshot VMs with (...) in their names
When restoring snapshots then HyperV creates names like <tt>VM z4058044_snap
(23.05.2014 - 09:29:29)</tt>. These names had not been handled correctly by
neither the agent plugin nor the check. Both has been fixed. The check is
still compatible with the old agent output - and removes everying after
the <tt>_snap</tt> in the VM name. Thanks to Alexander Scholler.
---
.werks/1712 | 13 ++++
ChangeLog | 1 +
agents/windows/plugins/hyperv_vms.ps1 | 2 +-
checks/hyperv_vms | 95 ++++++++++++++++++++++------
modules/check_mk.py | 1 +
web/htdocs/wato.py | 1 +
web/plugins/wato/check_mk_configuration.py | 1 +
7 files changed, 93 insertions(+), 21 deletions(-)
diff --git a/.werks/1712 b/.werks/1712
new file mode 100644
index 0000000..85e3f33
--- /dev/null
+++ b/.werks/1712
@@ -0,0 +1,13 @@
+Title: hyper_vms: fixed for snapshot VMs with (...) in their names
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.5i7
+Date: 1418051145
+Class: fix
+
+When restoring snapshots then HyperV creates names like <tt>VM z4058044_snap
+(23.05.2014 - 09:29:29)</tt>. These names had not been handled correctly by
+neither the agent plugin nor the check. Both has been fixed. The check is
+still compatible with the old agent output - and removes everying after
+the <tt>_snap</tt> in the VM name. Thanks to Alexander Scholler.
diff --git a/ChangeLog b/ChangeLog
index 3b8444f..0761491 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -128,6 +128,7 @@
* 1708 FIX: cups_queues: fix outputting of current printer jobs if printer daemon is
CUPS...
* 1710 FIX: omd_status: Fix totally missing section in Linux agent...
* 1711 FIX: win_printers.ps1: ignore temporary printers created by RDP terminal
sessions...
+ * 1712 FIX: hyper_vms: fixed for snapshot VMs with (...) in their names...
Multisite:
* 1508 Allow input of plugin output and perfdata when faking check results...
diff --git a/agents/windows/plugins/hyperv_vms.ps1
b/agents/windows/plugins/hyperv_vms.ps1
index 7245f59..bc90ed4 100644
--- a/agents/windows/plugins/hyperv_vms.ps1
+++ b/agents/windows/plugins/hyperv_vms.ps1
@@ -1,3 +1,3 @@
Write-Host -NoNewLine "<<<hyperv_vms>>>"
-Get-VM | format-table -HideTableHeaders -property Name, State, Uptime, Status
+Get-VM | format-table -HideTableHeaders -Autosize -property Name, State, Uptime, Status
Write-Host
diff --git a/checks/hyperv_vms b/checks/hyperv_vms
index e643266..ff30717 100644
--- a/checks/hyperv_vms
+++ b/checks/hyperv_vms
@@ -25,32 +25,87 @@
# Boston, MA 02110-1301 USA.
# Example output from agent:
-#<<<hyperv_vms>>>
-#DMZ-DC1 Running 4.21:44:58 Operating normally
-#DMZ-DC2 Running 4.21:44:47 Operating normally
+# <<<hyperv_vms>>>
+# DMZ-DC1 Running 4.21:44:58 Operating normally
+# DMZ-DC2 Running 4.21:44:47 Operating normally
-def inventory_hyperv_vms(info):
- return [ (x[0], {'state': x[1] }) for x in info ]
+# Another example, here with a snapshow with spaces in the name:
+# <<<hyperv_vms>>>
+# windows-hyperv2-z4058044 Running 21:33:08 Operating
normally
+# windows-hyperv2-z4058044_snap (23.05.2014 - 09:29:29) Running 18:20:34 Operating
normally
+# windows-hyperv2-z4065002 Running 11:04:50 Operating
normally
+# windows-hyperv2-z4065084 Running 1.10:42:33 Operating
normally
+# windows-hyperv2-z4133235 Running 1.03:52:18 Operating
normally
-def check_hyperv_vms(item, params, info):
+# A broken version of the agent outputted this:
+# <<<hyperv_vms>>>
+# z4058044 Running 21:19:14 Operating normally
+# z4058044_snap (2... Running 18:06:39 Operating normally
+# z4065002 Running 10:50:55 Operating normally
+# z4065084 Running 1.10:28:39 Operating normally
+# z4133235 Running 1.03:38:23 Operating normally
+
+
+# result:
+# {
+# "windows-hyperv2-z4058044_snap (23.05.2014 - 09:29:29)" : {
+# "vm_state" : "Running",
+# "uptime" : "1.10:42:33",
+# "state_msg" : "Operating normally",
+# }
+# }
+
+def parse_hyperv_vms(info):
+ parsed = {}
for line in info:
- if line[0] == item:
- name, vm_state, uptime = line[:3]
- state_msg = " ".join(line[3:])
- if vm_state == params['state']:
- state = 0
- message = "State is %s (%s)" % (vm_state, state_msg)
- else:
- message = "State has changed from %s to %s (%s)" % (
params['state'],\
- vm_state, state_msg)
- state = 2
- return state, message
- return 3, "VM not found"
+ if line[1].endswith("..."): # broken output
+ vm_name = line[0]
+ line = line[2:]
+ elif line[1].startswith("("):
+ idx = 2
+ while idx < len(line):
+ if line[idx].endswith(")"):
+ vm_name = " ".join(line[:idx+1])
+ break
+ idx += 1
+ line = line[idx+1:]
+ else:
+ vm_name = line[0]
+ line = line[1:]
+
+ parsed[vm_name] = {
+ "state" : line[0],
+ "uptime" : line[1],
+ "state_msg" : " ".join(line[2:]),
+ }
+ return parsed
+
+
+def inventory_hyperv_vms(parsed):
+ return [ (vm_name, {'state': vm["state"] })
+ for (vm_name, vm)
+ in parsed.items() ]
+
+
+def check_hyperv_vms(item, params, parsed):
+ if item in parsed:
+ vm = parsed[item]
+ if vm["state"] == params['state']:
+ state = 0
+ message = "State is %s (%s)" % (vm["state"],
vm["state_msg"])
+ else:
+ message = "State has changed from %s to %s (%s)" % (
+ params['state'],\
+ vm["state"],
+ vm["state_msg"])
+ state = 2
+ return state, message
+
check_info["hyperv_vms"] = {
+ "parse_function" : parse_hyperv_vms,
"check_function" : check_hyperv_vms,
"inventory_function" : inventory_hyperv_vms,
- "service_description" : "hyperv_vms",
- "has_perfdata" : False,
+ "service_description" : "VM %s",
}
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 1f2abf0..3f24123 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -370,6 +370,7 @@ old_service_descriptions = {
"ps.perf" : "proc_%s",
"wmic_process" : "proc_%s",
"logwatch" : "LOG %s",
+ "hyperv_vm" : "hyperv_vms",
}
use_new_descriptions_for = []
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 52c6a6e..4fdac7d 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -15901,6 +15901,7 @@ def create_sample_config():
"wmic_process",
"logwatch",
"cmk-inventory",
+ "hyperv_vms",
],
"inventory_check_interval": 120,
"enable_rulebased_notifications": True,
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 626e839..8e55d5e 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -1106,6 +1106,7 @@ register_configvar(group,
( "wmic_process", _("Ressource consumption of
windows processes")),
( "logwatch", _("Check logfiles for relevant new
messages")),
( "cmk-inventory", _("Monitor hosts for unchecked
services (Check_MK inventory)")),
+ ( "hyperv_vms", _("Hyper-V Server: State of
VMs")),
],
render_orientation = "vertical",
),