Module: check_mk
Branch: master
Commit: 5846b23a6a63d7e4ffa693100f3b5eb19bef234a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5846b23a6a63d7…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Apr 1 13:48:48 2019 +0200
Revert "wmi.include: Refactored WMI timeout handling; Use a more generic way and
removed NullTable"
This reverts commit ff4532c4b1e6ef456058205259d2b75ba87c761d.
---
checks/wmi.include | 91 ++++++++++++++++--------------------------------------
1 file changed, 27 insertions(+), 64 deletions(-)
diff --git a/checks/wmi.include b/checks/wmi.include
index aab6fa6..bbf3420 100644
--- a/checks/wmi.include
+++ b/checks/wmi.include
@@ -45,6 +45,13 @@
# '----------------------------------------------------------------------'
+class NullTable(object):
+ """Represents an empty table caused by a WMI
timeout."""
+
+ def __getattr__(self, name):
+ raise MKCounterWrapped('WMI query timed out')
+
+
class WMITable(object):
"""
Represents a 2-dimensional table of performance metrics.
@@ -65,9 +72,10 @@ class WMITable(object):
self.__headers = {}
self.__timestamp = timestamp
self.__frequency = frequency
+ index = 0
prev_header = None
- for index, header in enumerate(headers):
+ for header in headers:
if not header.strip() and prev_header:
# MS apparently doesn't bother to provide a name
# for base columns with performance counters
@@ -75,7 +83,7 @@ class WMITable(object):
header = self._normalize_key(header)
self.__headers[header] = index
prev_header = header
-
+ index += 1
self.__key_index = None
if key_field is not None:
try:
@@ -86,7 +94,6 @@ class WMITable(object):
self.__row_lookup = {}
self.__rows = []
- self.timed_out = False
if rows:
for row in rows:
self.add_row(row)
@@ -124,16 +131,7 @@ class WMITable(object):
self.__row_lookup[key] = len(self.__rows)
self.__rows.append(row)
- if not self.timed_out and self._get_row_col_value(-1,
"WMIStatus").lower() == "timeout":
- # Check if there's a timeout in the last added line, ie. row (index) ==
-1
- self.timed_out = True
-
def get(self, row, column):
- if self.timed_out:
- raise MKCounterWrapped('WMI query timed out')
- return self._get_row_col_value(row, column)
-
- def _get_row_col_value(self, row, column):
if isinstance(row, int):
row_index = row
else:
@@ -200,15 +198,23 @@ def parse_wmi_table(info, key="Name"):
# single-table input
tablename = ""
- missing_wmi_status, current_table =\
- _prepare_wmi_table(parsed, tablename, line, key, timestamp, frequency)
+ if is_wmi_timeout(line):
+ parsed[tablename] = NullTable()
+ line = info_iter.next()
+ continue
+
+ if tablename not in parsed:
+ parsed[tablename] = WMITable(tablename, line, key, timestamp, frequency)
+ current = parsed[tablename]
# read table content
line = info_iter.next()
while not line[0].startswith("["):
- if missing_wmi_status:
- line.append("OK")
- current_table.add_row(line)
+ if is_wmi_timeout(line):
+ parsed[tablename] = NullTable()
+ line = info_iter.next()
+ continue
+ current.add_row(line)
line = info_iter.next()
except (StopIteration, ValueError):
# regular end of block
@@ -217,51 +223,8 @@ def parse_wmi_table(info, key="Name"):
return parsed
-def _prepare_wmi_table(parsed, tablename, line, key, timestamp, frequency):
- # Possibilities:
- # #1 Agent provides extra column for WMIStatus; since 1.5.0p14
- # <<<SEC>>>
- # [foo]
- # Name,...,WMIStatus
- # ABC,...,OK/Timeout
- # [bar]
- # Name,...,WMIStatus
- # DEF,...,OK/Timeout
- #
- # #2 Old agents have no WMIStatus column; before 1.5.0p14
- # <<<SEC>>>
- # [foo]
- # Name,...,
- # ABC,...,
- # [bar]
- # Name,...,
- # DEF,...,
- #
- # #3 Old agents which report a WMITimeout in any sub section; before 1.5.0p14
- # <<<SEC>>>
- # [foo]
- # WMItimeout
- # [bar]
- # Name,...,
- # DEF,...,
- if line[0].lower() == "wmitimeout":
- old_timed_out = True
- header = ['WMIStatus']
- key = None
- else:
- old_timed_out = False
- header = line[:]
-
- missing_wmi_status = False
- if 'WMIStatus' not in header:
- missing_wmi_status = True
- header.append('WMIStatus')
-
- current_table = parsed.setdefault(tablename,
- WMITable(tablename, header, key, timestamp,
frequency))
- if old_timed_out:
- current_table.add_row(['Timeout'])
- return missing_wmi_status, current_table
+def is_wmi_timeout(line):
+ return line[0] == "WMItimeout"
#.
@@ -292,8 +255,8 @@ def wmi_filter_global_only(tables, row):
def _required_tables_missing(tables, required_tables):
is_subset = set(required_tables).issubset(set(tables.keys()))
- contains_timed_out_table = any(table.timed_out for table in tables.itervalues())
- return not is_subset or contains_timed_out_table
+ contains_null = any(isinstance(table, NullTable) for table in tables.itervalues())
+ return not is_subset or contains_null
def inventory_wmi_table_instances(tables, required_tables=None, filt=None, levels=None):