Module: check_mk
Branch: master
Commit: b2a575d6404db4c98ec5ffe99d96336c8470a12c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b2a575d6404db4…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed May 9 08:32:42 2018 +0200
6006 FIX pvecm_nodes, pvecm_status: Now supports Proxmox VE Cluster versions greater equal
3
Change-Id: Ie081ab8430b64bc44e32f126706cc7ee8db73d9a
---
.werks/6006 | 10 +++++++
checks/pvecm_nodes | 82 ++++++++++++++++++++++++++++++++++++++++++-----------
checks/pvecm_status | 27 +++++++++++-------
3 files changed, 92 insertions(+), 27 deletions(-)
diff --git a/.werks/6006 b/.werks/6006
new file mode 100644
index 0000000..62d6730
--- /dev/null
+++ b/.werks/6006
@@ -0,0 +1,10 @@
+Title: pvecm_nodes, pvecm_status: Now supports Proxmox VE Cluster versions greater equal
3
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1525847478
+Class: fix
+
+
diff --git a/checks/pvecm_nodes b/checks/pvecm_nodes
index de0af76..21f6b98 100644
--- a/checks/pvecm_nodes
+++ b/checks/pvecm_nodes
@@ -25,6 +25,7 @@
# Boston, MA 02110-1301 USA.
+# Version 2
# healthy if all nodes are reachable (at discovery)
# <<<pvecm_nodes>>>
# Node Sts Inc Joined Name
@@ -56,34 +57,81 @@
# 6 M 36032 BAR-host003
# 7 M 35960 2016-01-20 13:17:24 BAR-host001
+# Version >2
+# <<<pvecm_nodes>>>
+#
+# Membership information
+# ~~~~~~~~~~~~~~~~~~~~~~
+# Nodeid Votes Name
+# 1 1 hp1 (local)
+# 2 1 hp2
+# 3 1 hp3
+# 4 1 hp4
+
+
+def parse_pvecm_nodes(info):
+ parsed = {}
+ header = None
+ for line in info:
+ if line == ["Node", "Sts", "Inc",
"Joined", "Name"]:
+ header = ["node_id", "status", "joined",
"name"]
+ parse_func = _parse_version_eq_2
+ continue
+
+ elif line == ["Nodeid", "Votes", "Name"]:
+ header = ["node_id", "votes", "name"]
+ parse_func = _parse_version_gt_2
+ continue
+
+ if header is None:
+ continue
+
+ k, v = parse_func(line, header)
+ parsed.setdefault(k, v)
+ return parsed
+
-def inventory_pvecm_nodes(info):
- for line in info[1:]:
- yield (line[-1], None)
+def _parse_version_eq_2(line, header):
+ if len(line) == 6:
+ data = dict(zip(header[:3], line[:2] + [" ".join(line[3:5])]))
+ else:
+ data = dict(zip(["node_id", "status"], line[:2]))
+ return line[-1], data
-def check_pvecm_nodes(item, _no_params, info):
+def _parse_version_gt_2(line, header):
+ return " ".join(line[2:]), dict(zip(header[:2], line[:2]))
+
+
+def inventory_pvecm_nodes(parsed):
+ for name in parsed:
+ yield name, None
+
+
+def check_pvecm_nodes(item, _no_params, parsed):
+ if item not in parsed:
+ return 2, "Node is missing"
+
map_states = {
"m" : (0, "member of the cluster"),
"x" : (1, "not a member of the cluster"),
"d" : (2, "known to the cluster but disallowed access to
it"),
}
- for line in info[1:]:
- if item == line[-1]:
- state, state_readable = map_states[line[1].lower()]
- infotext = "Status: %s" % state_readable
- if len(line) >= 6:
- infotext += ", Joined: %s (%s)" % (line[4], line[3])
-
- else:
- infotext += ", Joined: missing"
-
- return state, infotext
-
- return 2, "Node is missing"
+ data = parsed[item]
+ infotexts = ["ID: %s" % data["node_id"]]
+ state = 0
+ if "status" in data:
+ state, state_readable = map_states[data["status"].lower()]
+ infotexts.append("Status: %s" % state_readable)
+ if "joined" in data:
+ infotexts.append("Joined: %s" % data["joined"])
+ if "votes" in data:
+ infotexts.append("Votes: %s" % data["votes"])
+ return state, ", ".join(infotexts)
check_info['pvecm_nodes'] = {
+ 'parse_function' : parse_pvecm_nodes,
'inventory_function' : inventory_pvecm_nodes,
'check_function' : check_pvecm_nodes,
'service_description' : 'PVE Node %s',
diff --git a/checks/pvecm_status b/checks/pvecm_status
index 7c87fb3..6728630 100644
--- a/checks/pvecm_status
+++ b/checks/pvecm_status
@@ -71,27 +71,33 @@
# Node addresses: nnn.mmm.ooo.ppp
-def inventory_pvecm_status(info):
- return [(None, None)]
-
-
-def check_pvecm_status(_no_item, _no_params, info):
+def parse_pvecm_status(info):
parsed = {}
for line in info:
- if len(line) != 2:
+ if len(line) < 2:
continue
- what, value = line
+ k = line[0].strip().lower()
+ if k == "date":
+ v = ":".join(line[1:]).strip()
+ else:
+ v = " ".join(line[1:]).strip()
+ parsed.setdefault(k, v)
+ return parsed
+
+
+def inventory_pvecm_status(parsed):
+ if parsed:
+ return [(None, None)]
- parsed[what.lower()] = value.strip().lower()
+def check_pvecm_status(_no_item, _no_params, parsed):
if "cman_tool" in parsed and \
"cannot open connection to cman" in parsed["cman_tool"]:
yield 2, "Cluster management tool: %s" % parsed["cman_tool"]
else:
name = parsed.get("cluster name",
- parsed.get("quorum provider",
- "unknown"))
+ parsed.get("quorum provider", "unknown"))
yield 0, "Name: %s, Nodes: %s" % \
(name, parsed["nodes"])
@@ -107,6 +113,7 @@ def check_pvecm_status(_no_item, _no_params, info):
check_info['pvecm_status'] = {
+ 'parse_function' : parse_pvecm_status,
'inventory_function' : inventory_pvecm_status,
'check_function' : check_pvecm_status,
'service_description' : 'PVE Cluster State',