Module: check_mk
Branch: master
Commit: 2b3acd7bca68a47c050cc5d2b4fc58aa8b01d743
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2b3acd7bca68a4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Dec 2 10:10:54 2015 +0100
The autocheck entries of clustered services were stored in
[cluster].mk autocheck files in past versions. Current versions
are now storing the autochecks in the node specific files.
The old [cluster].mk files were not cleaned up during discovery
leading into duplicate autochecks entries. As these files were
never updated again, they could result in unwanted services on
the cluster hosts. This could be fixed manually by removing the
[cluster].mk autocheck files via command line.
The current version is now cleaning up the files during discovery.
Conflicts:
ChangeLog
modules/automation.py
---
.werks/2848 | 20 +++++++++++++++++++
ChangeLog | 1 +
modules/discovery.py | 54 +++++++++++++++++++++++++++++++++-----------------
3 files changed, 57 insertions(+), 18 deletions(-)
diff --git a/.werks/2848 b/.werks/2848
new file mode 100644
index 0000000..3b993fb
--- /dev/null
+++ b/.werks/2848
@@ -0,0 +1,20 @@
+Title: Fixed cleanup of old autocheck files of cluster hosts
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i4
+Date: 1449047196
+
+The autocheck entries of clustered services were stored in
+[cluster].mk autocheck files in past versions. Current versions
+are now storing the autochecks in the node specific files.
+
+The old [cluster].mk files were not cleaned up during discovery
+leading into duplicate autochecks entries. As these files were
+never updated again, they could result in unwanted services on
+the cluster hosts. This could be fixed manually by removing the
+[cluster].mk autocheck files via command line.
+
+The current version is now cleaning up the files during discovery.
diff --git a/ChangeLog b/ChangeLog
index 234846e..8e1cba7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@
* 2759 FIX: Allowing Emails to contain special characters like umlauts...
* 2764 FIX: Fixed broken SNMP checks in case SNMP check interval is configured for
clusters...
* 2770 FIX: Check_MK is now warning the user about deprecated but configured
checkgroup parameters...
+ * 2848 FIX: Fixed cleanup of old autocheck files of cluster hosts...
Checks & Agents:
* 2434 NetApp monitoring: Cluster-Mode is now supported, changes in existing 7Mode
checks...
diff --git a/modules/discovery.py b/modules/discovery.py
index 2e281f3..a5b729d 100644
--- a/modules/discovery.py
+++ b/modules/discovery.py
@@ -52,9 +52,11 @@ def do_discovery(hostnames, check_types, only_new):
# cannot be discovered but the user is allowed to specify
# them and we do discovery on the nodes instead.
nodes = []
+ cluster_hosts = []
for h in hostnames:
nodes = nodes_of(h)
if nodes:
+ cluster_hosts.append(h)
hostnames += nodes
# Then remove clusters and make list unique
@@ -78,6 +80,11 @@ def do_discovery(hostnames, check_types, only_new):
cleanup_globals()
+ # Check whether or not the cluster host autocheck files are still
+ # existant. Remove them. The autochecks are only stored in the nodes
+ # autochecks files these days.
+ for hostname in cluster_hosts:
+ remove_autochecks_file(hostname)
def do_discovery_for(hostname, check_types, only_new, use_caches, on_error):
# Usually we disable SNMP scan if cmk -I is used without a list of
@@ -1203,6 +1210,15 @@ def has_autochecks(hostname):
return os.path.exists(autochecksdir + "/" + hostname + ".mk")
+def remove_autochecks_file(hostname):
+ filepath = autochecksdir + "/" + hostname + ".mk"
+ try:
+ os.remove(filepath)
+ except OSError:
+ pass
+
+
+# FIXME TODO: Consolidate with automation.py automation_write_autochecks_file()
def save_autochecks_file(hostname, items):
if not os.path.exists(autochecksdir):
os.makedirs(autochecksdir)
@@ -1231,6 +1247,11 @@ def set_autochecks_of(hostname, new_items):
new_autochecks.append((check_type, item, paramstring))
# write new autochecks file for that host
save_autochecks_file(node, new_autochecks)
+
+ # Check whether or not the cluster host autocheck files are still
+ # existant. Remove them. The autochecks are only stored in the nodes
+ # autochecks files these days.
+ remove_autochecks_file(hostname)
else:
existing = parse_autochecks_file(hostname)
# write new autochecks file, but take paramstrings from existing ones
@@ -1254,25 +1275,22 @@ def remove_autochecks_of(hostname):
nodes = nodes_of(hostname)
if nodes:
for node in nodes:
- old_items = parse_autochecks_file(node)
- new_items = []
- for check_type, item, paramstring in old_items:
- descr = service_description(check_type, item)
- if hostname != host_of_clustered_service(node, descr):
- new_items.append((check_type, item, paramstring))
- else:
- removed += 1
- save_autochecks_file(node, new_items)
+ removed += remove_autochecks_of_host(node)
else:
- old_items = parse_autochecks_file(hostname)
- new_items = []
- for check_type, item, paramstring in old_items:
- descr = service_description(check_type, item)
- if hostname != host_of_clustered_service(hostname, descr):
- new_items.append((check_type, item, paramstring))
- else:
- removed += 1
- save_autochecks_file(hostname, new_items)
+ removed += remove_autochecks_of_host(hostname)
return removed
+
+def remove_autochecks_of_host(hostname):
+ old_items = parse_autochecks_file(hostname)
+ removed = 0
+ new_items = []
+ for check_type, item, paramstring in old_items:
+ descr = service_description(check_type, item)
+ if hostname != host_of_clustered_service(hostname, descr):
+ new_items.append((check_type, item, paramstring))
+ else:
+ removed += 1
+ save_autochecks_file(hostname, new_items)
+ return removed