Module: check_mk
Branch: master
Commit: 73abf667b85e09c2e86623dd4e19141cc560957e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=73abf667b85e09…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Sep 27 15:22:31 2018 +0200
6605 FIX winperf_if: Fixed discovery of network interface alias
Change-Id: Iaee373b2edf23218f6390a36b866b3ce100a0438
---
.werks/6605 | 21 ++++++++++++++++
checks/winperf_if | 7 +++---
tests/unit/checks/test_if_winperf_if.py | 43 +++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/.werks/6605 b/.werks/6605
new file mode 100644
index 0000000..b5736c3
--- /dev/null
+++ b/.werks/6605
@@ -0,0 +1,21 @@
+Title: winperf_if: Fixed discovery of network interface alias
+Level: 1
+Component: checks
+Compatible: incomp
+Edition: cre
+Version: 1.6.0i1
+Date: 1537876236
+Class: fix
+
+While parsing the winperf interface section only trailing spaces were stripped
+off. There may also be leading spaces. Without cutting them off additional
+information like NetConnectionID, GUID or MAC address of the interfaces were
+not found. In this case the instance name of the interace was used as alias
+(fallback) instead of the NetConnectionID.
+
+Now if one has configured <tt>Use alias</tt> in the
+<tt>Network Interface and Switch Port Discovery</tt> ruleset new services
+may be discovered and old ones will be vanished.
+In order to obtained the already used iterface names please use
+<tt>Use description</tt> in the <tt>Network Interface and Switch Port
Discovery</tt>
+ruleset.
diff --git a/checks/winperf_if b/checks/winperf_if
index 4f9d7d1..a906493 100644
--- a/checks/winperf_if
+++ b/checks/winperf_if
@@ -92,8 +92,8 @@ def winperf_if_normalize_nic_name(name, nic_names):
def parse_winperf_if(info):
try:
timestamp_info, names_info, data = info[0], info[1], info[2:]
- except ValueError:
- return []
+ except (IndexError, ValueError):
+ return None, [], [], [], {}
try:
agent_timestamp = float(timestamp_info[0])
@@ -155,7 +155,7 @@ def parse_winperf_if(info):
teaming_headers = lines.next()
break
- as_dict = dict(zip(headers, [x.rstrip() for x in line]))
+ as_dict = dict(zip(headers, [x.strip() for x in line]))
# Unfortunately teamed interfaces lose their #x index and are no
longer
# distinguishable with the data from the Win32_NetworkAdapter.
@@ -212,7 +212,6 @@ def parse_winperf_if(info):
except StopIteration:
pass
-
# Now convert the dicts into the format that is needed by if.include
converted = []
diff --git a/tests/unit/checks/test_if_winperf_if.py
b/tests/unit/checks/test_if_winperf_if.py
new file mode 100644
index 0000000..ce9843d
--- /dev/null
+++ b/tests/unit/checks/test_if_winperf_if.py
@@ -0,0 +1,43 @@
+import pytest
+import ast
+from testlib import cmk_path
+
+# Mark all tests in this file as check related tests
+pytestmark = pytest.mark.checks
+
+(a)pytest.mark.parametrize("info,settings,items"tems", [
+ ([], [{}], []),
+ ([['123', '456', '789'], ['1', 'instances:',
'A_B-C_1'],
+ [u'-122', u'29370873405', u'5887351577', u'0',
u'0', u'bulk_count'],
+ [u'-110', u'5692885', u'5153077', u'0',
u'0', u'bulk_count'],
+ [u'-244', u'5018312', u'4921974', u'0',
u'0', u'bulk_count'],
+ [u'-58', u'674573', u'231103', u'0', u'0',
u'bulk_count'],
+ [u'10', u'10000000000', u'10000000000', u'100000',
u'100000', u'large_rawcount'],
+ [u'-246', u'20569013293', u'5685847946', u'0',
u'0', u'bulk_count'],
+ [u'14', u'4961765', u'4425455', u'0', u'0',
u'bulk_count'],
+ [u'16', u'4447', u'490897', u'0', u'0',
u'bulk_count'],
+ [u'18', u'52100', u'5622', u'0', u'0',
u'large_rawcount'],
+ [u'20', u'0', u'0', u'0', u'0',
u'large_rawcount'],
+ [u'22', u'0', u'0', u'0', u'0',
u'large_rawcount'],
+ [u'-4', u'8801860112', u'201503631', u'0',
u'0', u'bulk_count'],
+ [u'26', u'673929', u'230448', u'0', u'0',
u'bulk_count'],
+ [u'28', u'644', u'655', u'0', u'0',
u'bulk_count'],
+ [u'30', u'0', u'0', u'0', u'0',
u'large_rawcount'],
+ [u'32', u'0', u'0', u'0', u'0',
u'large_rawcount'],
+ [u'34', u'0', u'0', u'0', u'0',
u'large_rawcount'],
+ [u'1086', u'0', u'0', u'0', u'0',
u'large_rawcount'],
+ [u'1088', u'1', u'0', u'0', u'0',
u'large_rawcount'],
+ [u'1090', u'3734320', u'4166703', u'0',
u'0', u'bulk_count'],
+ [u'1092', u'0', u'0', u'0', u'0',
u'bulk_count'],
+ [u'1094', u'22618', u'22618', u'22618',
u'22618', u'large_rawcount'],
+ [u'Node', u'MACAddress', u'Name',
u'NetConnectionID', u'NetConnectionStatus', u'Speed',
u'GUID'],
+ [u'NODE1 ', u' 00:00:00:00:00:00 ', u' A_B-C_1 ', u'
Ethernet1-XYZ ', u' 2 ', u' 10000000000 ', u'
{FOO-123-BAR}']],
+ [{"use_alias": True}], ['Ethernet1-XYZ']),
+])
+def test_winperf_if_netconnection_id(check_manager, monkeypatch, info, settings, items):
+ check = check_manager.get_check("winperf_if")
+ monkeypatch.setitem(check.context, "host_extra_conf", lambda _, __:
settings)
+ monkeypatch.setitem(check.context, "_prepare_if_group_patterns_from_conf",
lambda: {})
+ parsed = check.run_parse(info)
+ discovered_items = [e[0] for e in check.run_discovery(parsed)]
+ assert discovered_items == items