Skip to content

Commit

Permalink
move plugin access up the call stack III
Browse files Browse the repository at this point in the history
This module is dying anyway, so we don't
put too much effort in it.

Change-Id: I9fba8a976dd913cb9f07fded6cf15bebac9d9814
  • Loading branch information
mo-ki committed Feb 21, 2025
1 parent 9d2b511 commit bda5d71
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions cmk/base/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,37 @@

from cmk.base import config
from cmk.base.api.agent_based.register import (
AgentBasedPlugins,
extract_known_discovery_rulesets,
get_previously_loaded_plugins,
)

_config_loaded = False
_checks_loaded = False
_config: config.LoadedConfigFragment | None = None
_plugins: AgentBasedPlugins | None = None


# TODO: This should be solved in the config module / ConfigCache object
def _load_config() -> None:
global _config_loaded
if not _config_loaded:
plugins = get_previously_loaded_plugins()
config.load(extract_known_discovery_rulesets(plugins), validate_hosts=False)
_config_loaded = True
global _config
if _config is None:
# not sure if we need the plugins here (probably not)
# but this whole module is soon to be removed anyway
plugins = _load_checks()
_config = config.load(extract_known_discovery_rulesets(plugins), validate_hosts=False)


# TODO: This should be solved in the config module / ConfigCache object
def _load_checks() -> None:
global _checks_loaded
if not _checks_loaded:
config.load_all_plugins(local_checks_dir=local_checks_dir, checks_dir=checks_dir)
_checks_loaded = True
def _load_checks() -> AgentBasedPlugins:
global _plugins
if _plugins is None:
_plugins, _errors = config.load_all_plugins(
local_checks_dir=local_checks_dir, checks_dir=checks_dir
)
return _plugins


def reset_config() -> None:
global _config_loaded
_config_loaded = False
global _config
_config = None


def logwatch_service_description(
Expand All @@ -58,9 +61,8 @@ def logwatch_service_description(
# (users might shadow/redefine the logwatch plug-in in unexpected places)
# Failing to load the right plug-in would result in a wrong service description,
# in turn leading to wrong service labels and ruleset matches.
_load_checks()
plugin_name = CheckPluginName("logwatch")
plugin = get_previously_loaded_plugins().check_plugins[plugin_name]
plugin = _load_checks().check_plugins[plugin_name]
return config.service_description(
get_ruleset_matcher(),
hostname,
Expand Down

0 comments on commit bda5d71

Please sign in to comment.