Module: check_mk
Branch: master
Commit: bd125da12fd5d9bdb357d649d2b184978a09e0e8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bd125da12fd5d9…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Apr 27 14:18:21 2018 +0200
6039 FIX Nagios: Fixed monitoring of cluster hosts and nodes
Monitoring Check_MK clusters was not correctly working in all
previous 1.5 releases.
Change-Id: Ia38df05938d5ff31c5318f5ef8b8453744fe6c8b
---
.werks/6039 | 12 ++++++++++++
cmk_base/core_nagios.py | 32 +++++++++++++++++---------------
2 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/.werks/6039 b/.werks/6039
new file mode 100644
index 0000000..b0006df
--- /dev/null
+++ b/.werks/6039
@@ -0,0 +1,12 @@
+Title: Nagios: Fixed monitoring of cluster hosts and nodes
+Level: 2
+Component: checks
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1524831426
+
+Monitoring Check_MK clusters was not correctly working in all
+previous 1.5 releases.
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 3a9b14a..ecaa1e2 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -951,8 +951,8 @@ def _precompile_hostcheck(hostname):
pass
# check table, enriched with addition precompiled information.
- check_table = check_table.get_precompiled_check_table(hostname)
- if not check_table:
+ host_check_table = check_table.get_precompiled_check_table(hostname,
filter_mode="include_clustered")
+ if not host_check_table:
console.verbose("(no Check_MK checks)\n")
return
@@ -1013,23 +1013,27 @@ if '-d' in sys.argv:
# has at least one SNMP based check. Also collect the needed check
# types and sections.
needed_check_plugin_names = set([])
- needed_sections = set([])
- for check_plugin_name, _unused_item, _unused_param, descr in check_table:
+ for check_plugin_name, _unused_item, _unused_param, descr in host_check_table:
if check_plugin_name not in checks.check_info:
sys.stderr.write('Warning: Ignoring missing check %s.\n' %
check_plugin_name)
continue
+
if checks.check_info[check_plugin_name].get("extra_sections"):
for section_name in
checks.check_info[check_plugin_name]["extra_sections"]:
if section_name in checks.check_info:
needed_check_plugin_names.add(section_name)
- needed_sections.add(section_name)
- needed_sections.add(checks.section_name_of(check_plugin_name))
needed_check_plugin_names.add(check_plugin_name)
+ # Also include the check plugins of the cluster nodes to be able to load
+ # the autochecks of the nodes
+ if config.is_cluster(hostname):
+ for node in config.nodes_of(hostname):
+ needed_check_plugin_names.update([ e[0] for e in
check_table.get_precompiled_check_table(node) ])
+
# check info table
# We need to include all those plugins that are referenced in the host's
- # check table
+ # check table.
filenames = []
for check_plugin_name in needed_check_plugin_names:
section_name = checks.section_name_of(check_plugin_name)
@@ -1054,25 +1058,23 @@ if '-d' in sys.argv:
filenames.append(path)
output.write("checks.load_checks(%r)\n" % filenames)
- for filename in filenames:
- console.verbose(" %s%s%s", tty.green, filename.split('/')[-1],
tty.normal, stream=sys.stderr)
+ for check_plugin_name in sorted(needed_check_plugin_names):
+ console.verbose(" %s%s%s", tty.green, check_plugin_name, tty.normal,
stream=sys.stderr)
output.write("config.load(validate_hosts=False)\n")
# handling of clusters
if config.is_cluster(hostname):
cluster_nodes = config.nodes_of(hostname)
- output.write("clusters = { %r : %r }\n" %
- (hostname, cluster_nodes))
- output.write("def is_cluster(hostname):\n return hostname == %r\n\n"
% hostname)
+ output.write("config.is_cluster = lambda h: h == %r\n" % hostname)
nodes_of_map = {hostname: cluster_nodes}
for node in config.nodes_of(hostname):
nodes_of_map[node] = None
- output.write("def nodes_of(hostname):\n return %r[hostname]\n\n" %
nodes_of_map)
+ output.write("config.nodes_of = lambda h: %r[h]\n" % nodes_of_map)
else:
- output.write("clusters = {}\ndef is_cluster(hostname):\n return
False\n\n")
- output.write("def nodes_of(hostname):\n return None\n")
+ output.write("config.is_cluster = lambda h: False\n")
+ output.write("config.nodes_of = lambda h: None\n")
# IP addresses
needed_ipaddresses, needed_ipv6addresses, = {}, {}