Fixes Nagios inconsistency)
Message-ID: <58d0d8f1.rBCuTQgL1SJNielF%lm(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 62e64f32faa328ce9ca9b485841a96a47115fd8c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=62e64f32faa328…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Mar 21 08:22:14 2017 +0100
4508 FIX Clusters: Now always have their nodes as parents (Fixes Nagios inconsistency)
When configuring clusters via Check_MK it was possible to configure custom parent nodes
for the cluster nodes when using the Nagios core. The Microcore already used it's
nodes
before as it was designed. We have now changed the Nagios handling to also enforce the
nodes to be parent hosts of their cluster hosts.
The assumption is: The cluster host is reachable while at least one node is up.
Change-Id: Icb7c245a169129f1b55a2757bbe778d4ac882313
---
.werks/4508 | 16 ++++++++++++++++
modules/check_mk.py | 18 ++++++++++++++----
modules/nagios.py | 27 ++++++++++++++-------------
3 files changed, 44 insertions(+), 17 deletions(-)
diff --git a/.werks/4508 b/.werks/4508
new file mode 100644
index 0000000..ec24b50
--- /dev/null
+++ b/.werks/4508
@@ -0,0 +1,16 @@
+Title: Clusters: Now always have their nodes as parents (Fixes Nagios inconsistency)
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.5.0i1
+Date: 1490080766
+
+When configuring clusters via Check_MK it was possible to configure custom parent nodes
+for the cluster nodes when using the Nagios core. The Microcore already used it's
nodes
+before as it was designed. We have now changed the Nagios handling to also enforce the
+nodes to be parent hosts of their cluster hosts.
+
+The assumption is: The cluster host is reachable while at least one node is up.
diff --git a/modules/check_mk.py b/modules/check_mk.py
index bfa5907..3823a0b 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1115,8 +1115,10 @@ def in_extraconf_hostlist(hostlist, hostname):
return False
-def extra_host_conf_of(hostname):
- return extra_conf_of(extra_host_conf, hostname, None)
+def extra_host_conf_of(hostname, exclude=None):
+ if exclude == None:
+ exclude = []
+ return extra_conf_of(extra_host_conf, hostname, None, exclude)
def extra_summary_host_conf_of(hostname):
return extra_conf_of(extra_summary_host_conf, hostname, None)
@@ -1144,16 +1146,24 @@ def extra_service_conf_of(hostname, description):
def extra_summary_service_conf_of(hostname, description):
return extra_conf_of(extra_summary_service_conf, hostname, description)
-def extra_conf_of(confdict, hostname, service):
+def extra_conf_of(confdict, hostname, service, exclude=None):
+ if exclude == None:
+ exclude = []
+
result = ""
for key, conflist in confdict.items():
if service != None:
values = service_extra_conf(hostname, service, conflist)
else:
values = host_extra_conf(hostname, conflist)
- if len(values) > 0:
+
+ if exclude and key in exclude:
+ continue
+
+ if values:
format = " %-29s %s\n"
result += format % (key, values[0])
+
return result
def autodetect_plugin(command_line):
diff --git a/modules/nagios.py b/modules/nagios.py
index f6d891f..f3cc109 100644
--- a/modules/nagios.py
+++ b/modules/nagios.py
@@ -172,21 +172,22 @@ def create_nagios_hostdefs(outfile, hostname, attrs):
outfile.write(" contact_groups\t\t%s\n" %
make_utf8(",".join(cgrs)))
contactgroups_to_define.update(cgrs)
- # Get parents manually defined via extra_host_conf["parents"]. Only honor
- # variable "parents" and implicit parents if this setting is empty
- extra_conf_parents = host_extra_conf(hostname,
extra_host_conf.get("parents", []))
+ if not is_clust:
+ # Parents for non-clusters
- # Parents for non-clusters
- if not extra_conf_parents and not is_clust:
- parents_list = parents_of(hostname)
- if len(parents_list) > 0:
- outfile.write(" parents\t\t\t%s\n" %
(",".join(parents_list)))
+ # Get parents manually defined via extra_host_conf["parents"]. Only
honor
+ # variable "parents" and implicit parents if this setting is empty
+ extra_conf_parents = host_extra_conf(hostname,
extra_host_conf.get("parents", []))
- # Special handling of clusters
- if is_clust:
- alias = "cluster of %s" % ", ".join(nodes)
if not extra_conf_parents:
- outfile.write(" parents\t\t\t%s\n" % ",".join(nodes))
+ parents_list = parents_of(hostname)
+ if parents_list:
+ outfile.write(" parents\t\t\t%s\n" %
(",".join(parents_list)))
+
+ elif is_cluster:
+ # Special handling of clusters
+ alias = "cluster of %s" % ", ".join(nodes)
+ outfile.write(" parents\t\t\t%s\n" % ",".join(nodes))
# Output alias, but only if it's not defined in extra_host_conf
alias = alias_of(hostname, None)
@@ -196,7 +197,7 @@ def create_nagios_hostdefs(outfile, hostname, attrs):
alias = make_utf8(alias)
# Custom configuration last -> user may override all other values
- outfile.write(make_utf8(extra_host_conf_of(hostname)))
+ outfile.write(make_utf8(extra_host_conf_of(hostname, exclude=["parents"] if
is_clust else [])))
outfile.write("}\n")