Skip to content

Commit

Permalink
Revert "config: skip invalid SSC configurations"
Browse files Browse the repository at this point in the history
Change-Id: Ia9e6b12154d69cfeab58b65c4336563da423f7dc
  • Loading branch information
schnetzzz authored and LarsMichelsen committed Feb 27, 2025
1 parent 189fac3 commit df9c593
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
28 changes: 6 additions & 22 deletions cmk/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
Literal,
NamedTuple,
overload,
TypeGuard,
TypeVar,
)

Expand Down Expand Up @@ -1448,19 +1447,6 @@ def load_and_convert_legacy_checks(
# '----------------------------------------------------------------------'


def _is_mapping_rulespec(rs: RuleSpec[object]) -> TypeGuard[RuleSpec[Mapping[str, object]]]:
return isinstance(rs["value"], dict) and all(isinstance(k, str) for k in rs["value"])


def _parsed_ssc_rules(
ssc_rules: Mapping[str, Sequence[RuleSpec[object]]],
) -> Sequence[tuple[str, Sequence[RuleSpec[Mapping[str, object]]]]]:
return [
(k, [rs for rs in rulespecs if _is_mapping_rulespec(rs)])
for k, rulespecs in ssc_rules.items()
]


def _make_compute_check_parameters_cb(
matcher: RulesetMatcher,
) -> Callable[
Expand Down Expand Up @@ -2462,9 +2448,7 @@ def active_checks(self, host_name: HostName) -> Sequence[SSCRules]:

def make_active_checks() -> Sequence[SSCRules]:
configured_checks: list[SSCRules] = []
for plugin_name, ruleset in sorted(
_parsed_ssc_rules(active_checks), key=lambda x: x[0]
):
for plugin_name, ruleset in sorted(active_checks.items(), key=lambda x: x[0]):
# Skip Check_MK HW/SW Inventory for all ping hosts, even when the
# user has enabled the inventory for ping only hosts
if plugin_name == "cmk_inv" and self.is_ping_host(host_name):
Expand Down Expand Up @@ -2591,7 +2575,7 @@ def special_agents_impl() -> Sequence[SSCRules]:
# over config.special_agents.
# We now sort the matching special agents by their name to at least get
# a deterministic order of the special agents.
for agentname, ruleset in sorted(_parsed_ssc_rules(special_agents)):
for agentname, ruleset in sorted(special_agents.items()):
params = self.ruleset_matcher.get_host_values(host_name, ruleset)
if params:
# we have match type first, so pick the first.
Expand Down Expand Up @@ -2654,18 +2638,18 @@ def collect_passwords(self) -> Mapping[str, str]:
# consider making the hosts an argument. Sometimes we only need one.

def _compose_filtered_ssc_rules(
ssc_config: Iterable[tuple[str, Sequence[RuleSpec[Mapping[str, object]]]]],
ssc_config: Mapping[str, Sequence[RuleSpec[Mapping[str, object]]]],
) -> Sequence[tuple[str, Sequence[Mapping[str, object]]]]:
"""Get _all_ configured rulesets (not only the ones matching any host)"""
return [(name, [r["value"] for r in ruleset]) for name, ruleset in ssc_config]
return [(name, [r["value"] for r in ruleset]) for name, ruleset in ssc_config.items()]

return {
**password_store.load(password_store.password_store_path()),
**PreprocessingResult.from_config(
_compose_filtered_ssc_rules(_parsed_ssc_rules(active_checks))
_compose_filtered_ssc_rules(active_checks)
).ad_hoc_secrets,
**PreprocessingResult.from_config(
_compose_filtered_ssc_rules(_parsed_ssc_rules(special_agents))
_compose_filtered_ssc_rules(special_agents)
).ad_hoc_secrets,
}

Expand Down
13 changes: 8 additions & 5 deletions cmk/base/default_config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from cmk.checkengine.discovery import RediscoveryParameters
from cmk.checkengine.exitspec import ExitSpec

from cmk.server_side_calls_backend import ConfigSet as SSCConfigSet

# This file contains the defaults settings for almost all configuration
# variables that can be overridden in main.mk. Some configuration
# variables are preset in checks/* as well.
Expand Down Expand Up @@ -188,11 +190,12 @@ class _PeriodicDiscovery(TypedDict):
inv_parameters: dict[str, list[RuleSpec[Mapping[str, object]]]] = {}


# WATO variant for fully formalized checks / special agents.
# We whould like to know this is of type Mapping[str, list[RuleSpec[SSCConfigSet]]], but we load this from files.
# There might be ancient configurations living there.
active_checks: dict[str, list[RuleSpec[object]]] = {}
special_agents: dict[str, list[RuleSpec[object]]] = {}
# WATO variant for fully formalized checks
# WATOs active check configurations are demanded to be Mapping[str, object] by the new ruleset API.
active_checks: dict[str, list[RuleSpec[SSCConfigSet]]] = {}
# WATO variant for datasource_programs
# WATOs special agent configurations are demanded to be Mapping[str, object] by the new ruleset API.
special_agents: dict[str, list[RuleSpec[SSCConfigSet]]] = {}


# WATO variant for free-form custom checks without formalization
Expand Down

0 comments on commit df9c593

Please sign in to comment.