Cleanup config.nodes_of
[check_mk.git] / checks / windows_intel_bonding
blob0a7e335b908ef8f2ed3789ff4cb09ef4367c47b6
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # <<<windows_intel_bonding>>>
28 # Caption Name RedundancyStatus
29 # Bond_10.4 {714F579F-D17A-40DC-B684-083C561EE352} 2
31 # ###
32 # AdapterFunction AdapterStatus GroupComponent PartComponent
33 # 1 1 IANet_TeamOfAdapters.CreationClassName="IANet_TeamOfAdapters",Name="{714F579F-D17A-40DC-B684-083C561EE352}" IANet_PhysicalEthernetAdapter.CreationClassName="IANet_PhysicalEthernetAdapter",DeviceID="{18EC3002-F03B-4B69-AD88-BFEB700460DC}",SystemCreationClassName="Win32_ComputerSystem",SystemName="Z3061021"
34 # 2 2 IANet_TeamOfAdapters.CreationClassName="IANet_TeamOfAdapters",Name="{714F579F-D17A-40DC-B684-083C561EE352}" IANet_PhysicalEthernetAdapter.CreationClassName="IANet_PhysicalEthernetAdapter",DeviceID="{1EDEBE50-005F-4533-BAFC-E863617F1030}",SystemCreationClassName="Win32_ComputerSystem",SystemName="Z3061021"
36 # ###
37 # AdapterStatus Caption DeviceID
38 # 51 TEAM : Bond_10.4 - Intel(R) Gigabit ET Dual Port Server Adapter {18EC3002-F03B-4B69-AD88-BFEB700460DC}
39 # 51 TEAM : Bond_10.4 - Intel(R) Gigabit ET Dual Port Server Adapter #2 {1EDEBE50-005F-4533-BAFC-E863617F1030}
40 # 35 Broadcom BCM5709C NetXtreme II GigE (NDIS VBD Client) #43 {55799336-A84B-4DA5-8EB9-B7426AA1AB75}
41 # 35 Broadcom BCM5709C NetXtreme II GigE (NDIS VBD Client) #35 {7DB9B461-FAC0-4763-9AF9-9A6CA6648188}
42 # 35 Broadcom BCM5709C NetXtreme II GigE (NDIS VBD Client) #40 {82AE1F27-BF28-4E30-AC3D-809DF5FF0D39}
43 # 35 Broadcom BCM5709C NetXtreme II GigE (NDIS VBD Client) #38 {DC918766-F61C-4801-92F8-E5532907EA0D}
46 def get_real_adapter_name(bond, name):
47 prefix = "TEAM : %s - " % bond
48 return name[len(prefix):]
51 def parse_windows_intel_bonding(info):
52 lines = iter(info)
53 bonds = {}
54 adapters = {}
55 adapter_names = {}
57 try:
58 # Get bond info
59 line = lines.next()
60 if line[0] != "###":
61 while True:
62 line = lines.next()
63 if line[0] == "###":
64 break
65 bond_caption = " ".join(line[:-2])
66 bond_name, bond_mode = line[-2], line[-1]
67 bonds[bond_name] = {"caption": bond_caption, "mode": bond_mode}
69 # Get adapter info
70 line = lines.next()
71 if line[0] != "###":
72 while True:
73 line = lines.next()
74 if line[0] == "###":
75 break
76 adapter_function, adapter_status = line[0], line[1]
77 adapter_bond = line[2].split(",")[-1].split("=")[1][1:-1]
78 adapter = line[3].split(",")[1].split("=")[1][1:-1]
79 adapters[adapter] = {
80 "function": adapter_function,
81 "status": adapter_status,
82 "bond": adapter_bond
85 # Get adapter names
86 line = lines.next() # Skip header
87 while True:
88 line = lines.next()
89 adapter_names[line[-1]] = " ".join(line[1:-1])
91 except StopIteration:
92 pass
94 # Now convert to generic dict, also used by other bonding checks
95 converted = {}
96 map_adapter_status = {"0": "Unknown", "1": "up", "2": "up", "3": "down"}
97 for bond, status in bonds.items():
98 interfaces = {}
99 bond_status = "down"
100 converted[status["caption"]] = {}
101 for adapter, adapter_info in adapters.items():
102 if bond == adapter_info["bond"]:
103 real_adapter_name = get_real_adapter_name(status["caption"], adapter_names[adapter])
104 if adapter_info["function"] == "1":
105 converted[status["caption"]]["primary"] = real_adapter_name
106 if adapter_info["status"] == "1":
107 converted[status["caption"]]["active"] = real_adapter_name
108 bond_status = "up"
109 interfaces[real_adapter_name] = {
110 "status": map_adapter_status.get(adapter_info["status"], "down"),
113 converted[status["caption"]].update({
114 "status": bond_status,
115 "mode": status["mode"],
116 "interfaces": interfaces,
119 return converted
122 check_info['windows_intel_bonding'] = {
123 "parse_function": parse_windows_intel_bonding,
124 "check_function": check_bonding,
125 "inventory_function": inventory_bonding,
126 "service_description": "Bonding interface %s",
127 "default_levels_variable": "bonding_default_levels",
128 "group": "bonding",
129 "includes": ["bonding.include"],