Module: check_mk
Branch: master
Commit: 5a6b5fa1d59a6fe2157e14dc6cc272dd27e72d26
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5a6b5fa1d59a6f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Mar 28 20:42:14 2019 +0100
Cleaned up core specific autochecks loading
The CMC check helper specific autocheck file hierarchy was used when a
"world" parameter was set to "active". This parameter was propagated
several levels through the code to tell
cmk_base.autochecks.read_autochecks_of() to use a helper specific path.
Since each invokation of the Check_MK base code is either a helper or
not this can be swapped per execution in a central place.
This central place is the keepalive.enable() function now. It simply
changes the global path definitions in keepalive mode to point to
the keepalive helper specific directory.
CMK-1818
Change-Id: Ia58642b4e20a097aeb619daab52fb788b97a42f0
---
cmk_base/autochecks.py | 10 +++-------
cmk_base/check_table.py | 15 ++++-----------
cmk_base/checking.py | 10 ++--------
cmk_base/config.py | 9 ++++-----
cmk_base/data_sources/__init__.py | 5 +----
5 files changed, 14 insertions(+), 35 deletions(-)
diff --git a/cmk_base/autochecks.py b/cmk_base/autochecks.py
index 54a5ef8..74ff933 100644
--- a/cmk_base/autochecks.py
+++ b/cmk_base/autochecks.py
@@ -38,19 +38,14 @@ import cmk_base.console
# Read automatically discovered checks of one host.
-# world: "config" -> File in var/check_mk/autochecks
-# "active" -> Copy in var/check_mk/core/autochecks
# Returns a table with three columns:
# 1. check_plugin_name
# 2. item
# 3. parameters evaluated!
# TODO: use store.load_data_from_file()
# TODO: Common code with parse_autochecks_file? Cleanup.
-def read_autochecks_of(hostname, world="config"):
- if world == "config":
- basedir = cmk.utils.paths.autochecks_dir
- else:
- basedir = cmk.utils.paths.var_dir + "/core/autochecks"
+def read_autochecks_of(hostname):
+ basedir = cmk.utils.paths.autochecks_dir
filepath = basedir + '/' + hostname + '.mk'
if not os.path.exists(filepath):
@@ -58,6 +53,7 @@ def read_autochecks_of(hostname, world="config"):
check_config = cmk_base.config.get_check_variables()
try:
+ cmk_base.console.vverbose("Loading autochecks from %s\n", filepath)
autochecks_raw = eval(file(filepath).read(), check_config, check_config)
except SyntaxError as e:
cmk_base.console.verbose("Syntax error in file %s: %s\n", filepath, e,
stream=sys.stderr)
diff --git a/cmk_base/check_table.py b/cmk_base/check_table.py
index 0e2a5f2..8df8934 100644
--- a/cmk_base/check_table.py
+++ b/cmk_base/check_table.py
@@ -46,7 +46,6 @@ import cmk_base.check_api_utils as check_api_utils
def get_check_table(hostname,
remove_duplicates=False,
use_cache=True,
- world='config',
skip_autochecks=False,
filter_mode=None,
skip_ignored=True):
@@ -162,7 +161,7 @@ def get_check_table(hostname,
# Now process all entries that are specific to the host
# in search (single host) or that might match the host.
if not skip_autochecks:
- for entry in config_cache.get_autochecks_of(hostname, world):
+ for entry in config_cache.get_autochecks_of(hostname):
handle_entry(entry)
for entry in single_host_checks.get(hostname, []):
@@ -178,7 +177,7 @@ def get_check_table(hostname,
for node in config.nodes_of(hostname):
node_checks = single_host_checks.get(node, [])
if not skip_autochecks:
- node_checks = node_checks + config_cache.get_autochecks_of(node, world)
+ node_checks = node_checks + config_cache.get_autochecks_of(node)
for entry in node_checks:
if len(entry) == 4:
entry = entry[1:] # drop hostname from single_host_checks
@@ -209,11 +208,10 @@ def get_check_table(hostname,
def get_precompiled_check_table(hostname,
remove_duplicates=True,
- world="config",
filter_mode=None,
skip_ignored=True):
host_checks = get_sorted_check_table(
- hostname, remove_duplicates, world, filter_mode=filter_mode,
skip_ignored=skip_ignored)
+ hostname, remove_duplicates, filter_mode=filter_mode, skip_ignored=skip_ignored)
precomp_table = []
for check_plugin_name, item, params, description, _unused_deps in host_checks:
# make these globals available to the precompile function
@@ -258,18 +256,13 @@ def remove_duplicate_checks(check_table):
# if there already is a TCP based one with the same
# description. E.g: df vs hr_fs.
# TODO: Clean this up!
-def get_sorted_check_table(hostname,
- remove_duplicates=False,
- world="config",
- filter_mode=None,
- skip_ignored=True):
+def get_sorted_check_table(hostname, remove_duplicates=False, filter_mode=None,
skip_ignored=True):
# Convert from dictionary into simple tuple list. Then sort
# it according to the service dependencies.
unsorted = [(checkname, item, params, descr, deps)
for ((checkname, item), (params, descr, deps)) in get_check_table(
hostname,
remove_duplicates=remove_duplicates,
- world=world,
filter_mode=filter_mode,
skip_ignored=skip_ignored).items()]
diff --git a/cmk_base/checking.py b/cmk_base/checking.py
index 6519db0..cc615ac 100644
--- a/cmk_base/checking.py
+++ b/cmk_base/checking.py
@@ -199,10 +199,7 @@ def _do_all_checks_on_host(sources, hostname, ipaddress,
only_check_plugin_names
filter_mode = "include_clustered"
table = check_table.get_precompiled_check_table(
- hostname,
- remove_duplicates=True,
- filter_mode=filter_mode,
- world="active" if _in_keepalive_mode() else "config")
+ hostname, remove_duplicates=True, filter_mode=filter_mode)
# When check types are specified via command line, enforce them. Otherwise use the
# list of checks defined by the check table.
@@ -424,10 +421,7 @@ def _evaluate_timespecific_entry(entry):
def is_manual_check(hostname, check_plugin_name, item):
manual_checks = check_table.get_check_table(
- hostname,
- remove_duplicates=True,
- world="active" if _in_keepalive_mode() else "config",
- skip_autochecks=True)
+ hostname, remove_duplicates=True, skip_autochecks=True)
return (check_plugin_name, item) in manual_checks
diff --git a/cmk_base/config.py b/cmk_base/config.py
index b2ed2b8..a8e606c 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3007,13 +3007,12 @@ class ConfigCache(object):
return hosts_in_folder
return self._folder_host_lookup[cache_id]
- def get_autochecks_of(self, hostname, world):
+ def get_autochecks_of(self, hostname):
try:
- return self._autochecks_cache[world][hostname]
+ return self._autochecks_cache[hostname]
except KeyError:
- self._autochecks_cache.setdefault(world, {})
- result = cmk_base.autochecks.read_autochecks_of(hostname, world)
- self._autochecks_cache[world][hostname] = result
+ result = cmk_base.autochecks.read_autochecks_of(hostname)
+ self._autochecks_cache[hostname] = result
return result
def section_name_of(self, section):
diff --git a/cmk_base/data_sources/__init__.py b/cmk_base/data_sources/__init__.py
index 896cd3e..36e9e88 100644
--- a/cmk_base/data_sources/__init__.py
+++ b/cmk_base/data_sources/__init__.py
@@ -259,10 +259,7 @@ class DataSources(object):
node_ipaddress = ip_lookup.lookup_ip_address(node_hostname)
table = check_table.get_precompiled_check_table(
- node_hostname,
- remove_duplicates=True,
- filter_mode="only_clustered",
- world="active" if _in_keepalive_mode() else
"config")
+ node_hostname, remove_duplicates=True,
filter_mode="only_clustered")
node_data_sources = DataSources(node_hostname, node_ipaddress)
node_data_sources.enforce_check_plugin_names(set([e[0] for e in table]))