Resulted in ruleset mixup during core reload
Message-ID: <550bdc5b.9xm6rVxN89kCqWbt%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: 8daa56a64c45b2e6e2b0afd89f08a39f9398d427
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8daa56a64c45b2…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Mar 20 09:37:37 2015 +0100
Fixed reseting of global caches; Resulted in ruleset mixup during core reload
---
modules/check_mk.py | 27 ++++++++++++++++++---------
modules/check_mk_base.py | 20 +++++++++++---------
2 files changed, 29 insertions(+), 18 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 37b434c..31103fc 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -453,11 +453,14 @@ def collect_hosttags():
parts = taggedhost.split("|")
hosttags[parts[0]] = parts[1:]
+
+g_hosttag_taglist_cache = {}
+g_global_caches.append('g_hosttag_taglist_cache')
+
# Check if a host fullfills the requirements of a tags
# list. The host must have all tags in the list, except
# for those negated with '!'. Those the host must *not* have!
# New in 1.1.13: a trailing + means a prefix match
-g_hosttag_taglist_cache = {}
def hosttags_match_taglist(hosttags, required_tags):
try:
cache_id = tuple(hosttags)+tuple(required_tags)
@@ -875,7 +878,6 @@ def host_of_clustered_service(hostname, servicedesc):
# | Code for computing the table of checks of a host. |
# '----------------------------------------------------------------------'
-
# Returns check table for a specific host
# Format: (checkname, item) -> (params, description)
@@ -1087,6 +1089,8 @@ def get_datasource_program(hostname, ipaddress):
# Variables needed during the renaming of hosts (see automation.py)
ignore_ip_lookup_failures = False
failed_ip_lookups = []
+g_dns_cache = {}
+g_global_caches.append('g_dns_cache')
# Determine the IP address of a host
def lookup_ipaddress(hostname):
@@ -1145,6 +1149,7 @@ def lookup_ipaddress(hostname):
g_dns_cache[hostname] = None
raise
+g_global_caches.append('g_ip_lookup_cache')
def init_ip_lookup_cache():
global g_ip_lookup_cache
if g_ip_lookup_cache is None:
@@ -1568,6 +1573,8 @@ def service_deps(hostname, servicedesc):
g_converted_host_rulesets_cache = {}
+g_global_caches.append('g_converted_host_rulesets_cache')
+
def convert_host_ruleset(ruleset):
new_rules = []
if len(ruleset) == 1 and ruleset[0] == "":
@@ -1721,8 +1728,9 @@ def convert_pattern(pattern):
def convert_pattern_list(patterns):
return tuple([ convert_pattern(p) for p in patterns ])
-
g_hostlist_match_cache = {}
+g_global_caches.append('g_hostlist_match_cache')
+
def all_matching_hosts(tags, hostlist):
cache_id = tuple(tags), tuple(hostlist)
try:
@@ -1743,6 +1751,8 @@ def all_matching_hosts(tags, hostlist):
g_converted_service_rulesets_cache = {}
+g_global_caches.append('g_converted_service_rulesets_cache')
+
def convert_service_ruleset(ruleset):
new_rules = []
for rule in ruleset:
@@ -1771,8 +1781,10 @@ def convert_service_ruleset(ruleset):
return new_rules
-# Compute outcome of a service rule set that has an item
g_extraconf_servicelist_cache = {}
+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):
try:
ruleset = g_converted_service_rulesets_cache[id(ruleset)]
@@ -5075,13 +5087,10 @@ def copy_globals():
for varname, value in globals().items():
# Some global caches are allowed to change.
if varname not in [ "g_service_description",
"g_multihost_checks",
- "g_check_table_cache",
"g_singlehost_checks",
+ "g_singlehost_checks",
"g_nodesof_cache", "g_compiled_regexes",
"vars_before_config",
"g_initial_times",
"g_keepalive_initial_memusage",
- "g_dns_cache", "g_ip_lookup_cache",
- "g_converted_host_rulesets_cache",
"g_converted_service_rulesets_cache",
- "g_extraconf_servicelist_cache",
"g_hostlist_match_cache",
- "g_hosttag_taglist_cache" ] \
+ "g_global_caches" ] + g_global_caches \
and type(value).__name__ not in [ "function", "module",
"SRE_Pattern" ]:
global_saved[varname] = copy.copy(value)
return global_saved
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 6db4bb2..4b0c130 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -79,22 +79,15 @@ except NameError:
# are need to be reset in keepalive mode after a configuration change has
# been signalled.
def reset_global_caches():
- global g_check_table_cache
- g_check_table_cache = {} # per-host-checktables
global g_singlehost_checks
g_singlehost_checks = None # entries in checks used by just one host
global g_multihost_checks
g_multihost_checks = None # entries in checks used by more than one host
- global g_nodesof_cache
- g_nodesof_cache = {} # Nodes of cluster hosts
- global g_dns_cache
- g_dns_cache = {}
global g_ip_lookup_cache
g_ip_lookup_cache = None # permanently cached ipaddresses from ipaddresses.cache
- global g_converted_rulesets_cache
- g_converted_rulesets_cache = {}
-reset_global_caches()
+ for cachevar_name in g_global_caches:
+ globals()[cachevar_name] = {}
# Prepare colored output if stdout is a TTY. No colors in pipe, etc.
if sys.stdout.isatty():
@@ -176,7 +169,16 @@ g_broken_snmp_hosts = set([])
g_broken_agent_hosts = set([])
g_timeout = None
g_compiled_regexes = {}
+g_global_caches = []
+
+# global variables used to cache temporary values that need to
+# be reset after a configuration change.
+g_check_table_cache = {} # per-host-checktables
+g_global_caches.append('g_check_table_cache')
+g_nodesof_cache = {} # Nodes of cluster hosts
+g_global_caches.append('g_nodesof_cache')
+reset_global_caches()
# variables set later by getopt. These are defined here since in precompiled
# mode the module check_mk.py is not present and we need all options to be