Module: check_mk
Branch: master
Commit: 65dc62f5715b9d9b1e91d2c3de06672c0ec6b461
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=65dc62f5715b9d…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Apr 27 21:09:30 2018 +0200
6044 FIX Nagios: Fixed crash when discovered checks were disabled
When all services discovered by a single check were disabled a
"KeyError: 'logwatch'" exception occured while checking the host.
Change-Id: I74b2a5e41e25247889ddebef4a71bc4da7d85149
---
.werks/6044 | 12 ++++++++++++
cmk_base/check_table.py | 12 ++++++------
cmk_base/core_nagios.py | 15 ++++++++++-----
3 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/.werks/6044 b/.werks/6044
new file mode 100644
index 0000000..5bd84da
--- /dev/null
+++ b/.werks/6044
@@ -0,0 +1,12 @@
+Title: Nagios: Fixed crash when discovered checks were disabled
+Level: 1
+Component: core
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1524855837
+
+When all services discovered by a single check were disabled a
+"KeyError: 'logwatch'" exception occured while checking the host.
diff --git a/cmk_base/check_table.py b/cmk_base/check_table.py
index 58e3aa0..fedcfc3 100644
--- a/cmk_base/check_table.py
+++ b/cmk_base/check_table.py
@@ -45,7 +45,7 @@ import cmk_base.item_state as item_state
# filter_mode: "include_clustered" -> returns checks of own host, including
clustered checks
# filter_mode: "only_clustered" -> returns only checks belonging to
clusters
def get_check_table(hostname, remove_duplicates=False, use_cache=True,
- world='config', skip_autochecks=False, filter_mode=None):
+ world='config', skip_autochecks=False, filter_mode=None,
skip_ignored=True):
import cmk_base.discovery as discovery
if config.is_ping_host(hostname):
@@ -131,7 +131,7 @@ def get_check_table(hostname, remove_duplicates=False,
use_cache=True,
if rulesets.hosttags_match_taglist(hosttags, tags) and \
rulesets.in_extraconf_hostlist(hostlist, hostname):
descr = config.service_description(hostname, checkname, item)
- if config.service_ignored(hostname, checkname, descr):
+ if skip_ignored and config.service_ignored(hostname, checkname, descr):
return
svc_is_mine = hostname == config.host_of_clustered_service(hostname, descr)
@@ -192,8 +192,8 @@ def get_check_table(hostname, remove_duplicates=False,
use_cache=True,
return check_table
-def get_precompiled_check_table(hostname, remove_duplicates=True,
world="config", filter_mode=None):
- host_checks = get_sorted_check_table(hostname, remove_duplicates, world,
filter_mode=filter_mode)
+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)
precomp_table = []
for check_plugin_name, item, params, description, _unused_deps in host_checks:
# make these globals available to the precompile function
@@ -270,13 +270,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):
+def get_sorted_check_table(hostname, remove_duplicates=False, world="config",
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).items() ]
+ filter_mode=filter_mode, skip_ignored=skip_ignored).items() ]
def cmp(a, b):
if a[3] < b[3]:
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 62ebc25..9cfd5fe 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -951,7 +951,8 @@ def _precompile_hostcheck(hostname):
pass
# check table, enriched with addition precompiled information.
- host_check_table = check_table.get_precompiled_check_table(hostname,
filter_mode="include_clustered")
+ host_check_table = check_table.get_precompiled_check_table(hostname,
+ filter_mode="include_clustered",
skip_ignored=False)
if not host_check_table:
console.verbose("(no Check_MK checks)\n")
return
@@ -1009,10 +1010,9 @@ if '-d' in sys.argv:
""")
- # Do we need to load the SNMP module? This is the case, if the host
- # has at least one SNMP based check. Also collect the needed check
- # types and sections.
needed_check_plugin_names = set([])
+
+ # Collect the needed check plugin names using the host check table
for check_plugin_name, _unused_item, _unused_param, descr in host_check_table:
if check_plugin_name not in checks.check_info:
sys.stderr.write('Warning: Ignoring missing check %s.\n' %
check_plugin_name)
@@ -1029,7 +1029,7 @@ if '-d' in sys.argv:
# the autochecks of the nodes
if config.is_cluster(hostname):
for node in config.nodes_of(hostname):
- needed_check_plugin_names.update([ e[0] for e in
check_table.get_precompiled_check_table(node) ])
+ needed_check_plugin_names.update([ e[0] for e in
check_table.get_precompiled_check_table(node, skip_ignored=False) ])
# check info table
# We need to include all those plugins that are referenced in the host's
@@ -1061,6 +1061,11 @@ if '-d' in sys.argv:
for check_plugin_name in sorted(needed_check_plugin_names):
console.verbose(" %s%s%s", tty.green, check_plugin_name, tty.normal,
stream=sys.stderr)
+ # Disable this check. We don't have all check plugins loaded and have not all
possible
+ # check config variables known. These issues don't have to be validated by the
single
+ # precompiled checks.
+ output.write("config.verify_non_invalid_variables = lambda x: None\n")
+
output.write("config.load(validate_hosts=False)\n")
# handling of clusters