Module: check_mk
Branch: master
Commit: b2983a5520ede601b2d4ef79fa2cfcfefe4b7062
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b2983a5520ede6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Feb 20 14:49:35 2015 +0100
#2028 FIX hyperv_vms: new plugin that allows spaces in VM names
The new plugin uses a vertical tabulator (Ascii 9) instead of spaces as
separators. By that way spaces in VM names are now allowed. Such names are
e.g. used by snapshot VMs.
---
.werks/2028 | 12 ++++++++++++
ChangeLog | 1 +
agents/windows/plugins/hyperv_vms.ps1 | 6 +++---
checks/hyperv_vms | 24 +++++++++++++++++++-----
4 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/.werks/2028 b/.werks/2028
new file mode 100644
index 0000000..620547c
--- /dev/null
+++ b/.werks/2028
@@ -0,0 +1,12 @@
+Title: hyperv_vms: new plugin that allows spaces in VM names
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i1
+Date: 1424440111
+
+The new plugin uses a vertical tabulator (Ascii 9) instead of spaces as
+separators. By that way spaces in VM names are now allowed. Such names are
+e.g. used by snapshot VMs.
diff --git a/ChangeLog b/ChangeLog
index 01b4689..195c66e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -173,6 +173,7 @@
* 2004 FIX: windows_updates: fix exception in WATO when displaying default levels
* 2006 FIX: services: Add WATO rule for configuring parameters of discovered
checks...
* 2007 FIX: md: Handle rebuild of RAID 5 correctly, handle sitatuation of replacement
correctly...
+ * 2028 FIX: hyperv_vms: new plugin that allows spaces in VM names...
Multisite:
* 1758 Improved exception hander: Shows details without additional debug request,
added mailto link for error report...
diff --git a/agents/windows/plugins/hyperv_vms.ps1
b/agents/windows/plugins/hyperv_vms.ps1
index bc90ed4..7ce0dad 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 -Autosize -property Name, State, Uptime, Status
-Write-Host
+Write-Host "<<<hyperv_vms:sep(9)>>>"
+
+Get-VM | select Name, State, Uptime, Status | ConvertTo-Csv -Delimiter "`t"
-NoTypeInformation
diff --git a/checks/hyperv_vms b/checks/hyperv_vms
index ff30717..86b79d9 100644
--- a/checks/hyperv_vms
+++ b/checks/hyperv_vms
@@ -45,6 +45,17 @@
# z4065084 Running 1.10:28:39 Operating normally
# z4133235 Running 1.03:38:23 Operating normally
+# A Version with a plugin that uses tab as seperator and quotes the strings:
+# <<<hyperv_vms:sep(9)>>>
+# "Name" "State" "Uptime" "Status"
+# "z4058013" "Running" "06:05:16"
"Operating normally"
+# "z4058020" "Running" "01:01:57"
"Operating normally"
+# "z4058021" "Running" "01:02:11"
"Operating normally"
+# "z4065012" "Running" "01:02:04"
"Operating normally"
+# "z4065013" "Running" "07:47:27"
"Operating normally"
+# "z4065020" "Running" "01:02:09"
"Operating normally"
+# "z4065025" "Running" "01:02:05"
"Operating normally"
+# "z4133199" "Running" "00:57:23"
"Operating normally"
# result:
# {
@@ -58,6 +69,8 @@
def parse_hyperv_vms(info):
parsed = {}
for line in info:
+ # Remove quotes
+ line = [ x.strip('"') for x in line ]
if line[1].endswith("..."): # broken output
vm_name = line[0]
line = line[2:]
@@ -73,11 +86,12 @@ def parse_hyperv_vms(info):
vm_name = line[0]
line = line[1:]
- parsed[vm_name] = {
- "state" : line[0],
- "uptime" : line[1],
- "state_msg" : " ".join(line[2:]),
- }
+ if ':' in line[1]: # skip heading line
+ parsed[vm_name] = {
+ "state" : line[0],
+ "uptime" : line[1],
+ "state_msg" : " ".join(line[2:]),
+ }
return parsed