Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / pvecm_nodes
blob7d4bb91318ac6dd0eb6a3ce19e670ccbcd68bc03
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2016 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 # Version 2
28 # healthy if all nodes are reachable (at discovery)
29 # <<<pvecm_nodes>>>
30 # Node Sts Inc Joined Name
31 # 1 M 35960 2016-01-20 13:17:24 BAR-host002
32 # 2 M 36020 2016-01-20 13:30:18 FOO-host001
33 # 3 M 35960 2016-01-20 13:17:24 FOO-host003
34 # 4 M 35964 2016-01-20 13:17:24 FOO-host004
35 # 5 M 35764 2016-01-20 12:59:03 FOO-host002
36 # 6 M 36032 2016-01-20 13:34:27 BAR-host003
37 # 7 M 35960 2016-01-20 13:17:24 BAR-host001
39 # faulty because some nodes are missing
40 # <<<pvecm_nodes>>>
41 # Node Sts Inc Joined Name
42 # 1 M 35960 2016-01-20 13:17:24 BAR-host002
43 # 2 M 36020 2016-01-20 13:30:18 FOO-host001
44 # 4 M 35964 2016-01-20 13:17:24 FOO-host004
45 # 6 M 36032 2016-01-20 13:34:27 BAR-host003
46 # 7 M 35960 2016-01-20 13:17:24 BAR-host001
48 # faulty communication between nodes
49 # <<<pvecm_nodes>>>
50 # Node Sts Inc Joined Name
51 # 1 M 35960 2016-01-20 13:17:24 BAR-host002
52 # 2 M 36020 FOO-host001
53 # 3 M 35960 2016-01-20 13:17:24 FOO-host003
54 # 4 M 35964 2016-01-20 13:17:24 FOO-host004
55 # 5 M 35764 FOO-host002
56 # 6 M 36032 BAR-host003
57 # 7 M 35960 2016-01-20 13:17:24 BAR-host001
59 # Version >2
60 # <<<pvecm_nodes>>>
62 # Membership information
63 # ~~~~~~~~~~~~~~~~~~~~~~
64 # Nodeid Votes Name
65 # 1 1 hp1 (local)
66 # 2 1 hp2
67 # 3 1 hp3
68 # 4 1 hp4
71 def parse_pvecm_nodes(info):
72 parsed = {}
73 header = None
74 for line in info:
75 if line == ["Node", "Sts", "Inc", "Joined", "Name"]:
76 header = ["node_id", "status", "joined", "name"]
77 parse_func = _parse_version_eq_2
78 continue
80 elif line == ["Nodeid", "Votes", "Name"]:
81 header = ["node_id", "votes", "name"]
82 parse_func = _parse_version_gt_2
83 continue
85 if header is None:
86 continue
88 k, v = parse_func(line, header)
89 parsed.setdefault(k, v)
90 return parsed
93 def _parse_version_eq_2(line, header):
94 if len(line) == 6:
95 data = dict(zip(header[:3], line[:2] + [" ".join(line[3:5])]))
96 else:
97 data = dict(zip(["node_id", "status"], line[:2]))
98 return line[-1], data
101 def _parse_version_gt_2(line, header):
102 return " ".join(line[2:]), dict(zip(header[:2], line[:2]))
105 def inventory_pvecm_nodes(parsed):
106 for name in parsed:
107 yield name, None
110 def check_pvecm_nodes(item, _no_params, parsed):
111 if item not in parsed:
112 return 2, "Node is missing"
114 map_states = {
115 "m": (0, "member of the cluster"),
116 "x": (1, "not a member of the cluster"),
117 "d": (2, "known to the cluster but disallowed access to it"),
119 data = parsed[item]
120 infotexts = ["ID: %s" % data["node_id"]]
121 state = 0
122 if "status" in data:
123 state, state_readable = map_states[data["status"].lower()]
124 infotexts.append("Status: %s" % state_readable)
125 if "joined" in data:
126 infotexts.append("Joined: %s" % data["joined"])
127 if "votes" in data:
128 infotexts.append("Votes: %s" % data["votes"])
129 return state, ", ".join(infotexts)
132 check_info['pvecm_nodes'] = {
133 'parse_function': parse_pvecm_nodes,
134 'inventory_function': inventory_pvecm_nodes,
135 'check_function': check_pvecm_nodes,
136 'service_description': 'PVE Node %s',