Module: check_mk
Branch: master
Commit: 08d43d82dbca2042b2d7840713c236266ba9e22d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=08d43d82dbca20…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Apr 26 17:12:01 2016 +0200
3437 FIX Improved performance of "activate changes", especially in distributed
environments
---
.werks/3437 | 10 ++++++++++
ChangeLog | 1 +
modules/check_mk.py | 50 +++++++++++++++++++++++++++++++-------------------
3 files changed, 42 insertions(+), 19 deletions(-)
diff --git a/.werks/3437 b/.werks/3437
new file mode 100644
index 0000000..b970c53
--- /dev/null
+++ b/.werks/3437
@@ -0,0 +1,10 @@
+Title: Improved performance of "activate changes", especially in distributed
environments
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1461683485
+
+
diff --git a/ChangeLog b/ChangeLog
index 1c1fb4d..fcaeffb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,7 @@
* 3123 FIX: fix for temperature services discovered pre-1.2.8 that caused errors on
writing configuration
* 3385 FIX: Fixed not updated discovery service after grouped auto discovery...
* 3416 FIX: Avoid warning in cmc.log when rescheduling non-existing discovery
check...
+ * 3437 FIX: Improved performance of "activate changes", especially in
distributed environments
Checks & Agents:
* 3183 aruba_wlc_aps: new check which monitors the provisioned accesspoints of an
Aruba Network WLAN Controller
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 11d51be..26a4b10 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -716,7 +716,7 @@ def parents_of(hostname):
g_converted_host_rulesets_cache = {}
g_global_caches.append('g_converted_host_rulesets_cache')
-def convert_host_ruleset(ruleset):
+def convert_host_ruleset(ruleset, with_foreign_hosts):
new_rules = []
if len(ruleset) == 1 and ruleset[0] == "":
sys.stderr.write('WARNING: deprecated entry [ "" ] in host
configuration list\n')
@@ -728,17 +728,21 @@ def convert_host_ruleset(ruleset):
# Directly compute set of all matching hosts here, this
# will avoid recomputation later
- new_rules.append((item, all_matching_hosts(tags, hostlist,
with_foreign_hosts=True)))
+ new_rules.append((item, all_matching_hosts(tags, hostlist, with_foreign_hosts)))
- g_converted_host_rulesets_cache[id(ruleset)] = new_rules
return new_rules
def host_extra_conf(hostname, ruleset):
+ # When the requested host is part of the local sites configuration,
+ # then use only the sites hosts for processing the rules
+ with_foreign_hosts = hostname not in all_active_hosts()
+ cache_id = id(ruleset), with_foreign_hosts
try:
- ruleset = g_converted_host_rulesets_cache[id(ruleset)]
+ ruleset = g_converted_host_rulesets_cache[cache_id]
except KeyError:
- ruleset = convert_host_ruleset(ruleset)
+ ruleset = convert_host_ruleset(ruleset, with_foreign_hosts)
+ g_converted_host_rulesets_cache[cache_id] = ruleset
entries = []
for item, hostname_list in ruleset:
@@ -898,8 +902,8 @@ def convert_pattern_list(patterns):
g_hostlist_match_cache = {}
g_global_caches.append('g_hostlist_match_cache')
-def all_matching_hosts(tags, hostlist, with_foreign_hosts=False):
- cache_id = tuple(tags), tuple(hostlist)
+def all_matching_hosts(tags, hostlist, with_foreign_hosts):
+ cache_id = tuple(tags), tuple(hostlist), with_foreign_hosts
try:
return g_hostlist_match_cache[cache_id]
except KeyError:
@@ -914,8 +918,8 @@ def all_matching_hosts(tags, hostlist, with_foreign_hosts=False):
for hostname in valid_hosts:
# When no tag matching is requested, do not filter by tags. Accept all hosts
# and filter only by hostlist
- if (not tags or hosttags_match_taglist(tags_of_host(hostname), tags)) and \
- in_extraconf_hostlist(hostlist, hostname):
+ if in_extraconf_hostlist(hostlist, hostname) and \
+ (not tags or hosttags_match_taglist(tags_of_host(hostname), tags)):
matching.add(hostname)
g_hostlist_match_cache[cache_id] = matching
@@ -925,7 +929,7 @@ def all_matching_hosts(tags, hostlist, with_foreign_hosts=False):
g_converted_service_rulesets_cache = {}
g_global_caches.append('g_converted_service_rulesets_cache')
-def convert_service_ruleset(ruleset):
+def convert_service_ruleset(ruleset, with_foreign_hosts):
new_rules = []
for rule in ruleset:
rule, rule_options = get_rule_options(rule)
@@ -944,12 +948,11 @@ def convert_service_ruleset(ruleset):
# Directly compute set of all matching hosts here, this
# will avoid recomputation later
- hosts = all_matching_hosts(tags, hostlist)
+ hosts = all_matching_hosts(tags, hostlist, with_foreign_hosts)
# And now preprocess the configured patterns in the servlist
new_rules.append((item, hosts, convert_pattern_list(servlist)))
- g_converted_service_rulesets_cache[id(ruleset)] = new_rules
return new_rules
@@ -958,10 +961,15 @@ g_global_caches.append('g_extraconf_servicelist_cache')
# Compute outcome of a service rule set that has an item
def service_extra_conf(hostname, service, ruleset):
+ # When the requested host is part of the local sites configuration,
+ # then use only the sites hosts for processing the rules
+ with_foreign_hosts = hostname not in all_active_hosts()
+ cache_id = id(ruleset), with_foreign_hosts
try:
- ruleset = g_converted_service_rulesets_cache[id(ruleset)]
+ ruleset = g_converted_service_rulesets_cache[cache_id]
except KeyError:
- ruleset = convert_service_ruleset(ruleset)
+ ruleset = convert_service_ruleset(ruleset, with_foreign_hosts)
+ g_converted_service_rulesets_cache[cache_id] = ruleset
entries = []
for item, hosts, service_matchers in ruleset:
@@ -978,7 +986,7 @@ def service_extra_conf(hostname, service, ruleset):
return entries
-def convert_boolean_service_ruleset(ruleset):
+def convert_boolean_service_ruleset(ruleset, with_foreign_hosts):
new_rules = []
for rule in ruleset:
entry, rule_options = get_rule_options(rule)
@@ -1002,19 +1010,23 @@ def convert_boolean_service_ruleset(ruleset):
# Directly compute set of all matching hosts here, this
# will avoid recomputation later
- hosts = all_matching_hosts(tags, hostlist)
+ hosts = all_matching_hosts(tags, hostlist, with_foreign_hosts)
new_rules.append((negate, hosts, convert_pattern_list(servlist)))
- g_converted_service_rulesets_cache[id(ruleset)] = new_rules
return new_rules
# Compute outcome of a service rule set that just say yes/no
def in_boolean_serviceconf_list(hostname, service_description, ruleset):
+ # When the requested host is part of the local sites configuration,
+ # then use only the sites hosts for processing the rules
+ with_foreign_hosts = hostname not in all_active_hosts()
+ cache_id = id(ruleset), with_foreign_hosts
try:
- ruleset = g_converted_service_rulesets_cache[id(ruleset)]
+ ruleset = g_converted_service_rulesets_cache[cache_id]
except KeyError:
- ruleset = convert_boolean_service_ruleset(ruleset)
+ ruleset = convert_boolean_service_ruleset(ruleset, with_foreign_hosts)
+ g_converted_service_rulesets_cache[cache_id] = ruleset
for negate, hosts, service_matchers in ruleset:
if hostname in hosts: