2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
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.
28 # healthy if all nodes are reachable (at discovery)
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
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
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
62 # Membership information
63 # ~~~~~~~~~~~~~~~~~~~~~~
71 def parse_pvecm_nodes(info
):
75 if line
== ["Node", "Sts", "Inc", "Joined", "Name"]:
76 header
= ["node_id", "status", "joined", "name"]
77 parse_func
= _parse_version_eq_2
80 elif line
== ["Nodeid", "Votes", "Name"]:
81 header
= ["node_id", "votes", "name"]
82 parse_func
= _parse_version_gt_2
88 k
, v
= parse_func(line
, header
)
89 parsed
.setdefault(k
, v
)
93 def _parse_version_eq_2(line
, header
):
95 data
= dict(zip(header
[:3], line
[:2] + [" ".join(line
[3:5])]))
97 data
= dict(zip(["node_id", "status"], line
[:2]))
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
):
110 def check_pvecm_nodes(item
, _no_params
, parsed
):
111 if item
not in parsed
:
112 return 2, "Node is missing"
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"),
120 infotexts
= ["ID: %s" % data
["node_id"]]
123 state
, state_readable
= map_states
[data
["status"].lower()]
124 infotexts
.append("Status: %s" % state_readable
)
126 infotexts
.append("Joined: %s" % data
["joined"])
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',