Module: check_mk
Branch: master
Commit: 50f085ba4831f6879c65e1e26027a87617ae6164
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=50f085ba4831f6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Feb 24 10:17:49 2015 +0100
win_dmidecode.bat: make output parsable by MK inventory
---
agents/windows/plugins/win_dmidecode.bat | 4 ++--
inventory/dmidecode | 8 +++++++-
modules/check_mk_base.py | 20 ++++++++++++--------
3 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/agents/windows/plugins/win_dmidecode.bat
b/agents/windows/plugins/win_dmidecode.bat
index e0bfb9f..5d60a83 100644
--- a/agents/windows/plugins/win_dmidecode.bat
+++ b/agents/windows/plugins/win_dmidecode.bat
@@ -11,5 +11,5 @@ REM * This plugin should work out of the box if you install dmidecode
REM * to the default location.
REM ***
-echo ^<^<^<dmidecode^>^>^>
-C:\Programme\GnuWin32\sbin\dmidecode.exe -t 1 -q
+echo ^<^<^<dmidecode:sep(0):nostrip^>^>^>
+C:\Programme\GnuWin32\sbin\dmidecode.exe -q
diff --git a/inventory/dmidecode b/inventory/dmidecode
index 382875e..4feeb3c 100644
--- a/inventory/dmidecode
+++ b/inventory/dmidecode
@@ -62,11 +62,17 @@
#
# ... any many other sections...
-
+# Note: on Linux \t is replaced by : and then the split
+# is done by :. On Windows the \t comes 1:1 and no splitting
+# is being done. So we need to split manually here
def inv_dmidecode(info):
section_name = None
section_lines = []
for line in info:
+ # Windows plugin keeps tabs and has no separator
+ if len(line) == 1:
+ parts = line[0].replace("\t", ":").split(":")
+ line = [ x.strip() for x in parts ]
if len(line) == 1:
if section_name:
inv_dmidecode_parse_section(section_name, section_lines)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index f97061e..50d471f 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -475,8 +475,7 @@ def get_realhost_info(hostname, ipaddress, check_type, max_cache_age,
ignore_che
elif len(output) < 16:
raise MKAgentError("Too short output from agent: '%s'" %
output)
- lines = [ l.strip() for l in output.split('\n') ]
- info, piggybacked, persisted = parse_info(lines, hostname)
+ info, piggybacked, persisted = parse_info(output.split("\n"), hostname)
store_piggyback_info(hostname, piggybacked)
store_persisted_info(hostname, persisted)
store_cached_hostinfo(hostname, info)
@@ -794,7 +793,6 @@ def store_cached_checkinfo(hostname, checkname, table):
# 2. piggy-backed data for other hosts
# 3. Sections to be persisted for later usage
def parse_info(lines, hostname):
-
info = {}
piggybacked = {} # unparsed info for other hosts
persist = {} # handle sections with option persist(...)
@@ -804,8 +802,10 @@ def parse_info(lines, hostname):
separator = None
encoding = None
for line in lines:
- if line[:4] == '<<<<' and line[-4:] ==
'>>>>':
- host = line[4:-4]
+ line = line.rstrip("\r")
+ stripped_line = line.strip()
+ if stripped_line[:4] == '<<<<' and stripped_line[-4:] ==
'>>>>':
+ host = stripped_line[4:-4]
if not host:
host = None
else:
@@ -817,8 +817,8 @@ def parse_info(lines, hostname):
# Found normal section header
# section header has format
<<<name:opt1(args):opt2:opt3(args)>>>
- elif line[:3] == '<<<' and line[-3:] == '>>>':
- section_header = line[3:-3]
+ elif stripped_line[:3] == '<<<' and stripped_line[-3:] ==
'>>>':
+ section_header = stripped_line[3:-3]
headerparts = section_header.split(":")
section_name = headerparts[0]
section_options = {}
@@ -848,7 +848,10 @@ def parse_info(lines, hostname):
# The section data might have a different encoding
encoding = section_options.get("encoding")
- elif line != '':
+ elif stripped_line != '':
+ if "nostrip" not in section_options:
+ line = stripped_line
+
if encoding:
try:
decoded_line = line.decode(encoding)
@@ -856,6 +859,7 @@ def parse_info(lines, hostname):
except:
pass
section.append(line.split(separator))
+
return info, piggybacked, persist