Module: check_mk
Branch: master
Commit: 4ef50e58ec8dc2911430daf9aacd455a64d5e78d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4ef50e58ec8dc2…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Mon Oct 26 16:06:10 2015 +0100
#2705 winperf_if: added option to warn if an interface is using dhcp
if the new plugin mk_dhcp_enabled.bat is installed, the interface will
go into warn state if it received its ip via dhcp.
---
.werks/2705 | 10 +++
ChangeLog | 1 +
agents/windows/plugins/mk_dhcp_enabled.bat | 3 +
checkman/winperf_if | 3 +
checks/winperf_if | 99 ++++++++++++++++++++--------
5 files changed, 90 insertions(+), 26 deletions(-)
diff --git a/.werks/2705 b/.werks/2705
new file mode 100644
index 0000000..b882dfa
--- /dev/null
+++ b/.werks/2705
@@ -0,0 +1,10 @@
+Title: winperf_if: added option to warn if an interface is using dhcp
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i4
+Date: 1445871802
+Class: feature
+
+if the new plugin mk_dhcp_enabled.bat is installed, the interface will
+go into warn state if it received its ip via dhcp.
diff --git a/ChangeLog b/ChangeLog
index bdb8d92..b3038b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,7 @@
NOTE: Please refer to the migration notes!
* 2688 mssql agent plugin can now handle clustered MSSQL instances
* 2703 logwatch.ec: now transfers the service level to the event console...
+ * 2705 winperf_if: added option to warn if an interface is using dhcp...
* 2660 FIX: fixed windows agent using the wrong working directory...
* 2664 FIX: ps: Speedup in situation with many matching processes...
* 2661 FIX: windows agent: fixed incomplete process list...
diff --git a/agents/windows/plugins/mk_dhcp_enabled.bat
b/agents/windows/plugins/mk_dhcp_enabled.bat
new file mode 100644
index 0000000..4b4d2e3
--- /dev/null
+++ b/agents/windows/plugins/mk_dhcp_enabled.bat
@@ -0,0 +1,3 @@
+@echo off
+echo ^<^<^<dhcp:sep^(44^)^>^>^>
+wmic path Win32_NetworkAdapterConfiguration get Description, dhcpenabled /format:csv
diff --git a/checkman/winperf_if b/checkman/winperf_if
index 3e0ed86..f52b5e0 100644
--- a/checkman/winperf_if
+++ b/checkman/winperf_if
@@ -16,6 +16,9 @@ description:
We propose to not installing the plugin in that case and save a few
CPU ressources.
+ The plugin "mk_dhcp_enabled.bat" can be used to get a WARN if the ip
+ address of the interface was assigned by dhcp.
+
The interface index (in SNMP known as {ifIndex}) is simulated by
creating an artificial running index after sorting the names of
the interfaces alphabetically.
diff --git a/checks/winperf_if b/checks/winperf_if
index dfd076d..5777404 100644
--- a/checks/winperf_if
+++ b/checks/winperf_if
@@ -59,14 +59,41 @@
# WINDOWSXP,00:E5:20:52:41:53,Paketplaner-Miniport,,
# WINDOWSXP,08:00:27:35:20:4D,Ethernetadapter der AMD-PCNET-Familie,LAN-Verbindung 2,2
# WINDOWSXP,08:00:27:35:20:4D,Paketplaner-Miniport,,
+#
+# Example output for the optional dhcp section. If this plugin is active, any interface
for which
+# dhcp is enabled will warn
+# <<<dhcp:sep(44)>>>
+# Node,Description,DHCPEnabled
+# WINDOWS,Intel(R) PRO/1000 MT-Desktopadapter,TRUE
+# WINDOWS,WAN Miniport (IP),FALSE
+# WINDOWS,Microsoft-ISATAP-Adapter,FALSE
+# WINDOWS,RAS Async Adapter,FALSE
+# WINDOWS,Intel(R) PRO/1000 MT-Desktopadapter #2,TRUE
+
+
+def winperf_if_canonize_nic_name(name):
+ return name.replace("_", " ").replace(" ", "
").rstrip()
+
+def winperf_if_normalize_nic_name(name, nic_names):
+ # Intel[R] PRO 1000 MT-Desktopadapter__3 (perf counter)
+ # Intel(R) PRO/1000 MT-Desktopadapter 3 (wmic name)
+ # Intel(R) PRO/1000 MT-Desktopadapter #3 (wmic InterfaceDescription)
+ mod_nic_name = name
+ for from_token, to_token in [ ("/", " "), ("(",
"["), (")", "]"), ("#", " ") ]:
+ for n in nic_names:
+ if from_token in n:
+ # we do not modify it if this character is in any of the counter names
+ break
+ else:
+ mod_nic_name = mod_nic_name.replace(from_token, to_token).replace("
", " ")
+ return mod_nic_name
-def convert_winperf_if(info):
- def canonize_nic_name(n):
- return n.replace("_", " ").replace(" ", "
").rstrip()
+
+def convert_winperf_if(info, nic_names, nic_index):
lines = iter(info)
lines.next() # skip line with timestamp and counter number
- nic_names = map(canonize_nic_name, lines.next()[2:])
+ lines.next() # skip interface line (already evaluated)
nics = dict([(n, {}) for n in nic_names])
# Scan lines with counters
@@ -117,27 +144,13 @@ def convert_winperf_if(info):
if guid in teaming_info:
guid_to_name =
dict(zip(teaming_info[guid]["GUID"].split(";"),
teaming_info[guid]["MemberDescriptions"].split(";")))
- nic_name = canonize_nic_name(guid_to_name[guid])
+ nic_name = winperf_if_canonize_nic_name(guid_to_name[guid])
elif "Name" in as_dict:
- nic_name = canonize_nic_name(as_dict["Name"])
+ nic_name =
winperf_if_canonize_nic_name(as_dict["Name"])
else:
- # There seams a bug with some windows configurations
+ # There seems a bug with some windows configurations
continue
- def transform_name(name):
- # Intel[R] PRO 1000 MT-Desktopadapter__3 (perf counter)
- # Intel(R) PRO/1000 MT-Desktopadapter 3 (wmic name)
- # Intel(R) PRO/1000 MT-Desktopadapter #3 (wmic
InterfaceDescription)
- mod_nic_name = name
- for from_token, to_token in [ ("/", " "),
("(", "["), (")", "]"), ("#", "
") ]:
- for n in nic_names:
- if from_token in n:
- # we do not modify it if this character is in any of
the counter names
- break
- else:
- mod_nic_name = mod_nic_name.replace(from_token,
to_token).replace(" ", " ")
- return mod_nic_name
-
found_match = False
# we need to ignore data on interfaces in the optional
@@ -156,7 +169,7 @@ def convert_winperf_if(info):
# Ethernetadapter der AMD-PCNET-Familie 2 - Paketplaner-Miniport,
while
# in wmic it's only named "Ethernetadapter der
AMD-PCNET-Familie 2".
if not found_match:
- mod_nic_name = transform_name(nic_name)
+ mod_nic_name = winperf_if_normalize_nic_name(nic_name,
nic_names)
if mod_nic_name not in nic_names:
for n in nic_names:
@@ -182,8 +195,7 @@ def convert_winperf_if(info):
# Now convert the dicts into the format that is needed by if.include
converted = []
- # Sort NIC names and create artifical index
- nic_index = dict(map(lambda x: (x[1], x[0] + 1), enumerate(nic_names)))
+ # Sort NIC names
nic_names.sort(reverse=True)
for nic_name in nic_names:
@@ -263,11 +275,45 @@ def convert_winperf_if(info):
return converted
+
+def winperf_if_get_nic_index_map(nic_names):
+ return dict(map(lambda x: (x[1], x[0] + 1), enumerate(nic_names)))
+
+
+def check_if_dhcp(item, params, info, nic_names, nic_index):
+ lines = iter(info)
+ header = lines.next()
+
+ for line in lines:
+ as_dict = dict(zip(header, map(lambda x: x.rstrip(), line)))
+ name = winperf_if_normalize_nic_name(as_dict["Description"],
nic_names)
+ idx = nic_index.get(name)
+ if idx == int(item):
+ if as_dict["DHCPEnabled"]:
+ return 1, "dhcp enabled"
+ else:
+ return 0, "dhcp %s" % as_dict["DHCPEnabled"]
+ return 0, ""
+
+
def inventory_winperf_if(info):
- return inventory_if_common(convert_winperf_if(info))
+ perf, dhcp = info
+ nic_names = map(winperf_if_canonize_nic_name, perf[1][2:])
+ nic_index = winperf_if_get_nic_index_map(nic_names)
+
+ return inventory_if_common(convert_winperf_if(perf, nic_names, nic_index))
+ # dhcp info irrelevant to inventory
+
def check_winperf_if(item, params, info):
- return check_if_common(item, params, convert_winperf_if(info), group_name =
"Teaming")
+ perf, dhcp = info
+ nic_names = map(winperf_if_canonize_nic_name, perf[1][2:])
+ nic_index = winperf_if_get_nic_index_map(nic_names)
+
+ yield check_if_common(item, params, convert_winperf_if(perf, nic_names, nic_index),
+ group_name = "Teaming")
+ if dhcp is not None:
+ yield check_if_dhcp(item, params, dhcp, nic_names, nic_index)
check_info["winperf_if"] = {
@@ -278,4 +324,5 @@ check_info["winperf_if"] = {
'includes': [ 'if.include' ],
'group': 'if',
'default_levels_variable': 'if_default_levels',
+ "extra_sections" : [ 'dhcp' ],
}