Module: check_mk
Branch: master
Commit: db20975bd9c77ac7bad7701f60b56cb648f6ff04
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=db20975bd9c77a…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Oct 14 14:06:05 2015 +0200
Do not let duplicate hosts fail config generation anymore
This just works for CMC
---
modules/automation.py | 10 ++++++++--
modules/check_mk.py | 26 +++++++++++++++++++-------
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/modules/automation.py b/modules/automation.py
index 0690e29..739705e 100644
--- a/modules/automation.py
+++ b/modules/automation.py
@@ -45,7 +45,7 @@ def do_automation(cmd, args):
elif cmd == "notification-get-bulks":
result = automation_get_bulks(args)
else:
- read_config_files()
+ read_config_files(validate_hosts=False)
if cmd == "try-inventory":
result = automation_try_discovery(args)
elif cmd == "inventory":
@@ -408,10 +408,16 @@ def automation_restart(job = "restart", use_rushd =
True):
try:
if monitoring_core == "nagios":
create_nagios_config(file(objects_file, "w"))
- configuration_warnings = None # not supported
+ configuration_warnings = [] # not supported
else:
configuration_warnings = do_create_cmc_config(opt_cmc_relfilename,
use_rushd = use_rushd)
+ duplicates = duplicate_hosts()
+ if duplicates:
+ configuration_warnings.append(
+ "The following host names have duplicates: %s. "
+ "This might lead to invalid/incomplete monitoring for these
hosts." % ", ".join(duplicates))
+
if "do_bake_agents" in globals() and bake_agents_on_restart:
do_bake_agents()
diff --git a/modules/check_mk.py b/modules/check_mk.py
index d20f98e..d4f42fc 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1536,6 +1536,18 @@ def all_configured_hosts():
def all_active_hosts():
return all_active_realhosts() + all_active_clusters()
+def duplicate_hosts():
+ # Sanity check for duplicate hostnames
+ seen_hostnames = set([])
+ duplicates = set([])
+ for hostname in all_active_hosts():
+ if hostname in seen_hostnames:
+ duplicates.add(hostname)
+ else:
+ seen_hostnames.add(hostname)
+ return sorted(list(duplicates))
+
+
# Returns a list of all host names to be handled by this site
# hosts of other sitest or disabled hosts are excluded
all_hosts_untagged = None
@@ -5764,6 +5776,7 @@ def marks_hosts_with_path(old, all, filename):
if host not in old:
host_paths[host] = path
+
# Helper functions that determines the sort order of the
# configuration files. The following two rules are implemented:
# 1. *.mk files in the same directory will be read
@@ -5779,12 +5792,14 @@ def cmp_config_paths(a, b):
cmp(len(pa), len(pb)) or \
cmp(pa, pb)
+
# Abort after an error, but only in interactive mode.
def interactive_abort(error):
if sys.stdout.isatty() or opt_interactive:
sys.stderr.write(error + "\n")
sys.exit(1)
+
def read_config_files(with_conf_d=True, validate_hosts=True):
global vars_before_config, final_mk, local_mk, checks
@@ -5845,13 +5860,10 @@ def read_config_files(with_conf_d=True, validate_hosts=True):
collect_hosttags()
if validate_hosts:
- # Sanity check for duplicate hostnames
- seen_hostnames = set([])
- for hostname in all_active_hosts():
- if hostname in seen_hostnames:
- sys.stderr.write("Error in configuration: duplicate host
'%s'\n" % hostname)
- sys.exit(3)
- seen_hostnames.add(hostname)
+ duplicates = duplicate_hosts()
+ if duplicates:
+ sys.stderr.write("Error in configuration: duplicate hosts: %s\n" %
", ".join(duplicates))
+ sys.exit(3)
# Add WATO-configured explicit checks to (possibly empty) checks
# statically defined in checks.