Module: check_mk
Branch: master
Commit: 482e439fa06475a83bd3034b5ffab6c04479702a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=482e439fa06475…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Mon Sep 3 10:44:50 2018 +0200
wmi.include: fix two possible exceptions during parsing and inventory
Change-Id: Ice8cfb9cab3730f1a689ac3df78172881f977857
---
checks/wmi.include | 12 ++++++------
.../datasets/wmi_include_empty_info_regression.py | 12 ++++++++++++
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/checks/wmi.include b/checks/wmi.include
index 7ddede6..1f6e986 100644
--- a/checks/wmi.include
+++ b/checks/wmi.include
@@ -167,6 +167,8 @@ class WMITable(object):
def parse_wmi_table(info, key="Name"):
+ parsed = {}
+
try:
# read input line by line. rows with [] start the table name.
# Each table has to start with a header line
@@ -181,7 +183,6 @@ def parse_wmi_table(info, key="Name"):
timestamp, frequency = int(line[1]), int(line[2])
line = info_iter.next()
- parsed = {}
while line is not None:
check_wmi_timeout(line)
@@ -249,7 +250,7 @@ def inventory_wmi_table(tables, **kwargs):
# only happen if required_tables was set
return []
- potential_instances = None
+ potential_instances = set()
if kwargs.get("skip_intersection", False):
# Unfortunately there are tables which do NOT provide any
# names. In this case we fallback to old behaviour.
@@ -263,10 +264,10 @@ def inventory_wmi_table(tables, **kwargs):
# inventarize one item per instance that exists in all tables
for required_table in required_tables:
table_rows = tables[required_table].row_labels()
- if potential_instances is None:
- potential_instances = set(table_rows)
- else:
+ if potential_instances:
potential_instances &= set(table_rows)
+ else:
+ potential_instances = set(table_rows)
# if there are multiple instances, don't include the summary line as it is
redundant
if len(potential_instances) > 1:
@@ -479,4 +480,3 @@ def wmi_yield_raw_fraction(table, row, column, label, perfvar,
levels=None):
)
#.
-
diff --git a/tests/unit/checks/generictests/datasets/wmi_include_empty_info_regression.py
b/tests/unit/checks/generictests/datasets/wmi_include_empty_info_regression.py
new file mode 100644
index 0000000..ccd9730
--- /dev/null
+++ b/tests/unit/checks/generictests/datasets/wmi_include_empty_info_regression.py
@@ -0,0 +1,12 @@
+
+
+checkname = 'wmi_webservices'
+
+
+info = []
+
+
+discovery = {}
+
+
+checks = {}