Skip to content

Commit

Permalink
move standalone function to utils
Browse files Browse the repository at this point in the history
Change-Id: I1b990a37494717b55bd0a5cf21290a2da9a1a979
  • Loading branch information
mo-ki committed Feb 21, 2025
1 parent bda5d71 commit 268680b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
7 changes: 5 additions & 2 deletions cmk/base/api/agent_based/register/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

from ._config import (
AgentBasedPlugins,
extract_known_discovery_rulesets,
get_previously_loaded_plugins,
)
from ._discover import load_all_plugins, load_selected_plugins
from .check_plugins import get_check_plugin
from .utils import filter_relevant_raw_sections, sections_needing_redetection
from .utils import (
extract_known_discovery_rulesets,
filter_relevant_raw_sections,
sections_needing_redetection,
)

__all__ = [
"AgentBasedPlugins",
Expand Down
15 changes: 1 addition & 14 deletions cmk/base/api/agent_based/register/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from collections.abc import Collection, Mapping
from collections.abc import Mapping
from dataclasses import dataclass

from cmk.utils.rulesets import RuleSetName
from cmk.utils.sectionname import SectionName

from cmk.checkengine.checking import CheckPluginName
Expand Down Expand Up @@ -48,18 +47,6 @@ def get_previously_loaded_plugins() -> AgentBasedPlugins:
)


def extract_known_discovery_rulesets(plugins: AgentBasedPlugins) -> Collection[RuleSetName]:
return {
r
for r in (
*(p.discovery_ruleset_name for p in plugins.check_plugins.values()),
*(p.host_label_ruleset_name for p in plugins.agent_sections.values()),
*(p.host_label_ruleset_name for p in plugins.snmp_sections.values()),
)
if r is not None
}


def add_check_plugin(check_plugin: CheckPlugin) -> None:
registered_check_plugins[check_plugin.name] = check_plugin

Expand Down
17 changes: 16 additions & 1 deletion cmk/base/api/agent_based/register/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import inspect
import sys
from collections import defaultdict
from collections.abc import Callable, Iterable, Mapping, Sequence
from collections.abc import Callable, Collection, Iterable, Mapping, Sequence
from typing import Final, get_args, Literal, NoReturn, Union

from cmk.ccc.version import Edition

from cmk.utils.check_utils import ParametersTypeAlias
from cmk.utils.rulesets import RuleSetName
from cmk.utils.sectionname import SectionName

from cmk.checkengine.checking import CheckPluginName
Expand All @@ -28,6 +29,8 @@
from cmk.agent_based.v1.register import RuleSetType
from cmk.discover_plugins import PluginLocation

from ._config import AgentBasedPlugins

TypeLabel = Literal["check", "cluster_check", "discovery", "host_label", "inventory"]

ITEM_VARIABLE: Final = "%s"
Expand Down Expand Up @@ -245,3 +248,15 @@ def sections_needing_redetection(
if len(section_names) > 1
for section_name in section_names
}


def extract_known_discovery_rulesets(plugins: AgentBasedPlugins) -> Collection[RuleSetName]:
return {
r
for r in (
*(p.discovery_ruleset_name for p in plugins.check_plugins.values()),
*(p.host_label_ruleset_name for p in plugins.agent_sections.values()),
*(p.host_label_ruleset_name for p in plugins.snmp_sections.values()),
)
if r is not None
}

0 comments on commit 268680b

Please sign in to comment.