Module: check_mk
Branch: master
Commit: 74aeebe21362bc8f32c8549edbe7228a9d5edd15
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=74aeebe21362bc…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jul 24 11:50:49 2017 +0200
cmk: Prepare to support modes that do not load the checks
Change-Id: I1f3720a1ea146223c8fdb8af0e884938bfe64790
---
bin/check_mk | 7 ++++---
cmk_base/modes/__init__.py | 11 ++++++++++-
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/bin/check_mk b/bin/check_mk
index dfc73e7..9af3b38 100755
--- a/bin/check_mk
+++ b/bin/check_mk
@@ -75,10 +75,11 @@ except getopt.GetoptError, err:
# First load the general modifying options
modes.process_general_options(opts)
-# TODO: Why are we loading the checks in all modes? This is useless in some modes!
-# But at least in case the config is needed, the checks are needed too, because
+# At least in case the config is needed, the checks are needed too, because
# the configuration may refer to check config variable names.
-checks.load()
+if len(set.intersection(set(modes.non_config_options()),
+ [o[0] for o in opts])) == 0:
+ checks.load()
# Read the configuration files (main.mk, autochecks, etc.), but not for
# certain operation modes that does not need them and should not be harmed
diff --git a/cmk_base/modes/__init__.py b/cmk_base/modes/__init__.py
index ba1cdae..727f6af 100644
--- a/cmk_base/modes/__init__.py
+++ b/cmk_base/modes/__init__.py
@@ -141,6 +141,14 @@ class Modes(object):
return options
+ def non_checks_options(self):
+ options = []
+ for mode in self._modes:
+ if not mode.needs_checks:
+ options += mode.options()
+ return options
+
+
def parse_hostname_list(self, args, with_clusters=True, with_foreign_hosts=False):
if with_foreign_hosts:
valid_hosts = config.all_configured_realhosts()
@@ -293,13 +301,14 @@ class Option(object):
class Mode(Option):
def __init__(self, long_option, handler_function, short_help, short_option=None,
argument=False, argument_descr=None, argument_conv=None,
argument_optional=False,
- long_help=None, needs_config=True, sub_options=None):
+ long_help=None, needs_config=True, needs_checks=True,
sub_options=None):
# pylint: disable=bad-super-call
super(Mode, self).__init__(long_option, short_help, short_option, argument,
argument_descr, argument_conv, argument_optional,
handler_function=handler_function)
self.long_help = long_help
self.needs_config = needs_config
+ self.needs_checks = needs_checks
self.sub_options = sub_options or []