Module: check_mk
Branch: master
Commit: b27a278d1aa13cdfdc812b00b1d80d5a024f2b56
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b27a278d1aa13c…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jun 7 10:56:58 2018 +0200
Fix dependencies of core-related modules, part 4.
Unified the interfaces for config generation. The price for now is a
slightly ugly interface (the Nagios implementation receives an argument it
doesn't care about), but this will improve when we have real classes instead
of abused modules.
Change-Id: Ic457a39e28bc3abc67b2363ebd7c2c61d0da15db
---
cmk_base/core_config.py | 3 +--
cmk_base/core_nagios.py | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index d23e371..f71e7ff 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -246,10 +246,9 @@ def create_core_config(cmc_file="config"):
def _create_config(cmc_file):
if config.monitoring_core == "cmc":
from cmk_base.cee.core_cmc import create_config_hook
- create_config_hook(cmc_file)
else:
from cmk_base.core_nagios import create_config_hook
- create_config_hook()
+ create_config_hook(cmc_file)
# Verify that the user has no deprecated check groups configured.
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 8f58446..0261f1b 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -57,7 +57,7 @@ import cmk_base.check_utils
# | Create a configuration file for Nagios core with hosts + services |
# '----------------------------------------------------------------------'
-def create_config_hook():
+def create_config_hook(_cmc_file):
with file(cmk.paths.nagios_objects_file, "w") as out:
create_config(out, None)
Module: check_mk
Branch: master
Commit: 874e0b9a6bee863d5d8edaf5b1723609909ad712
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=874e0b9a6bee86…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jun 7 08:55:21 2018 +0200
Fix dependencies of core-related modules, part 1.
We are doing two things wrong here:
First of all, we abuse modules as "normal" data structures, mixing up the
concepts of a class and its instances into a single concept (the module).
What we really want is a class definition and the explicit usage of its
instances.
This is already bad, but things get worse: In this pseudo-OO world, the
"superclass" knows its "subclasses", which violates two fundamental design
principles:
* the Liskov substitution principle
(see https://en.wikipedia.org/wiki/Liskov_substitution_principle)
* the open/closed principle
(see https://en.wikipedia.org/wiki/Open/closed_principle)
In our concrete example, the more general core_config module knows about the
more concrete core_nagios and core_cmc modules. Apart from violating the
two principles above, this is the root cause of several import cycles.
As a first tiny step, this commit unified the interface for precompilation.
More to come...
Change-Id: I5f39b88afff07c29643b5cd3926874c7b2a8bc08
---
cmk_base/core_config.py | 7 +++----
cmk_base/core_nagios.py | 2 +-
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 4d8d812..087a35a 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -284,11 +284,10 @@ def _verify_non_duplicate_hosts():
def precompile():
if config.monitoring_core == "cmc":
- import cmk_base.cee.core_cmc as core_cmc
- core_cmc.do_pack_config()
+ from cmk_base.cee.core_cmc import precompile_hook
else:
- import cmk_base.core_nagios as core_nagios
- core_nagios.do_precompile_hostchecks()
+ from cmk_base.core_nagios import precompile_hook
+ precompile_hook()
def do_update(with_precompile):
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 414fab7..74f1321 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -865,7 +865,7 @@ def _extra_conf_of(confdict, hostname, service, exclude=None):
# '----------------------------------------------------------------------'
# TODO: Move to modes
-def do_precompile_hostchecks():
+def precompile_hook():
console.output("Precompiling host checks...")
precompile_hostchecks()
console.output(tty.ok + "\n")