Cleanup config.nodes_of
[check_mk.git] / checks / lnx_bonding
blob474eec98a27a9e36569153948edc21c5b91cb126
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 # <<<lnx_bonding:sep(58)>>>
28 # ==> bond0 <==
29 # Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
31 # Bonding Mode: load balancing (round-robin)
32 # MII Status: down
33 # MII Polling Interval (ms): 0
34 # Up Delay (ms): 0
35 # Down Delay (ms): 0
37 # ==> bond1 <==
38 # Ethernet Channel Bonding Driver: v3.2.5 (March 21, 2008)
40 # Bonding Mode: fault-tolerance (active-backup)
41 # Primary Slave: eth0
42 # Currently Active Slave: eth0
43 # MII Status: up
44 # MII Polling Interval (ms): 100
45 # Up Delay (ms): 0
46 # Down Delay (ms): 0
48 # Slave Interface: eth4
49 # MII Status: up
50 # Link Failure Count: 0
51 # Permanent HW addr: 00:1b:21:49:d4:e4
53 # Slave Interface: eth0
54 # MII Status: up
55 # Link Failure Count: 1
56 # Permanent HW addr: 00:26:b9:7d:89:2e
59 def _split_into_bonds(info):
60 bonds = {}
61 for line in info:
62 if len(line) == 1 and line[0].startswith("/"):
63 continue
64 else:
65 line = [i.strip() for i in line]
67 words = line[0].split()
68 if words[0] == '==>':
69 current = bonds.setdefault(words[1], [])
70 elif 'Channel Bonding Driver' in line:
71 pass
72 else:
73 current.append(line)
74 return bonds
77 def _parse_bond(bond_lines):
78 bond = {}
79 interfaces = bond.setdefault("interfaces", {})
80 # start with global part
81 current = bond.setdefault("main", {})
83 for line in bond_lines:
84 # check for start of new sections
85 if line[0] == "Slave Interface":
86 current = interfaces.setdefault(line[1], {})
87 elif line[0] == "802.3ad info":
88 current = bond.setdefault("802.3ad info", {})
89 # or add key/val to current dict
90 else:
91 current[line[0]] = ':'.join(line[1:])
92 return bond
95 def _convert_to_generic(bonds):
96 '''convert to generic dict, also used by other bonding checks'''
97 converted = {}
98 for bond, status in bonds.items():
99 bond = bond.lstrip("./")
100 interfaces = {}
101 for eth, ethstatus in status["interfaces"].items():
102 interfaces[eth] = {
103 "status": ethstatus["MII Status"],
104 "hwaddr": ethstatus.get("Permanent HW addr", ""),
105 "failures": int(ethstatus["Link Failure Count"]),
107 if "Aggregator ID" in ethstatus:
108 interfaces[eth]["aggregator_id"] = ethstatus["Aggregator ID"]
110 converted[bond] = {
111 "status": status["main"]["MII Status"],
112 "mode": status["main"]["Bonding Mode"].split('(')[0].strip(),
113 "interfaces": interfaces,
115 if "802.3ad info" in status:
116 converted[bond]["aggregator_id"] = status["802.3ad info"]["Aggregator ID"]
118 if "Currently Active Slave" in status["main"]:
119 converted[bond]["active"] = status["main"]["Currently Active Slave"]
120 if "Primary Slave" in status["main"]:
121 converted[bond]["primary"] = status["main"]["Primary Slave"].split()[0]
122 return converted
125 def parse_lnx_bonding(info):
126 bond_blocks = _split_into_bonds(info)
127 bonds = {k: _parse_bond(bond_blocks[k]) for k in bond_blocks}
128 return _convert_to_generic(bonds)
131 check_info['lnx_bonding'] = {
132 "parse_function": parse_lnx_bonding,
133 "check_function": check_bonding,
134 "inventory_function": inventory_bonding,
135 "service_description": "Bonding Interface %s",
136 "group": "bonding",
137 "default_levels_variable": "bonding_default_levels",
138 "includes": ["bonding.include"],