Skip to content

Commit

Permalink
Use rule new automation for rule analysis
Browse files Browse the repository at this point in the history
Remove 1st of 3 dependencies on cmk.base.export.

Change-Id: I7500a8774fcdaa130153f8e2aec68016e4e9c282
  • Loading branch information
LarsMichelsen committed Feb 28, 2025
1 parent bb308ba commit 1a9ae62
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions cmk/gui/wato/pages/rulesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@
from cmk.gui.valuespec import LabelGroups as VSLabelGroups
from cmk.gui.view_utils import render_label_groups
from cmk.gui.watolib.audit_log_url import make_object_audit_log_url
from cmk.gui.watolib.check_mk_automations import analyse_service, get_check_information
from cmk.gui.watolib.check_mk_automations import (
analyse_service,
analyze_host_rule_matches,
analyze_service_rule_matches,
get_check_information,
)
from cmk.gui.watolib.config_hostname import ConfigHostname
from cmk.gui.watolib.host_label_sync import execute_host_label_sync
from cmk.gui.watolib.hosts_and_folders import (
Expand Down Expand Up @@ -1175,6 +1180,7 @@ def _rule_listing(self, ruleset: Ruleset) -> None:
self._hostname,
self._item,
self._service,
ruleset.rulespec,
[e[2] for e in rules],
)
if self._hostname and self._host
Expand Down Expand Up @@ -1316,6 +1322,7 @@ def _analyze_rule_matching(
host_name: HostName,
item: Item,
service_name: ServiceName | None,
rulespec: Rulespec,
rules: Sequence[Rule],
) -> dict[str, RuleMatchResult]:
with tracer.span(
Expand All @@ -1339,16 +1346,25 @@ def _analyze_rule_matching(
span.set_attribute("cmk.service_labels", repr(service_labels))
self._get_host_labels_from_remote_site()

rule_matches = {
rule.id: rule.matches(
host_name,
item,
service_name,
only_host_conditions=False,
service_labels=service_labels,
)
for rule in rules
}
if rulespec.is_for_services:
rule_matches = {
rule_id: bool(matches)
for rule_id, matches in analyze_service_rule_matches(
host_name,
(service_name if rulespec.item_type == "service" else item) or "",
service_labels,
[r.to_single_base_ruleset() for r in rules],
).results.items()
}
else:
rule_matches = {
rule_id: bool(matches)
for rule_id, matches in analyze_host_rule_matches(
host_name,
[r.to_single_base_ruleset() for r in rules],
).results.items()
}

span.set_attribute("cmk.gui.rule_matches", repr(rule_matches))

match_state = MatchState({"matched": False, "keys": set()})
Expand Down

0 comments on commit 1a9ae62

Please sign in to comment.