Skip to content

Commit fde8cbf

Browse files
committed
Add AC test 'Unknown check parameter rule sets'
CMK-22492 Change-Id: Ic26cb10be03c235a5aac490599900f581fdcbbf5
1 parent 584d144 commit fde8cbf

File tree

9 files changed

+107
-37
lines changed

9 files changed

+107
-37
lines changed

cmk/automations/results.py

+12
Original file line numberDiff line numberDiff line change
@@ -777,3 +777,15 @@ def automation_call() -> str:
777777

778778

779779
result_type_registry.register(BakeAgentsResult)
780+
781+
782+
@dataclass
783+
class UnknownCheckParameterRuleSetsResult(ABCAutomationResult):
784+
result: Sequence[str]
785+
786+
@staticmethod
787+
def automation_call() -> str:
788+
return "find-unknown-check-parameter-rule-sets"
789+
790+
791+
result_type_registry.register(UnknownCheckParameterRuleSetsResult)

cmk/base/automations/check_mk.py

+28
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
SetAutochecksTable,
109109
SetAutochecksV2Result,
110110
SpecialAgentResult,
111+
UnknownCheckParameterRuleSetsResult,
111112
UpdateDNSCacheResult,
112113
UpdateHostLabelsResult,
113114
UpdatePasswordsMergedFileResult,
@@ -3167,3 +3168,30 @@ def execute(
31673168

31683169

31693170
automations.register(AutomationCreateDiagnosticsDump())
3171+
3172+
3173+
class AutomationFindUnknownCheckParameterRuleSets(Automation):
3174+
cmd = "find-unknown-check-parameter-rule-sets"
3175+
needs_config = True
3176+
needs_checks = True
3177+
3178+
def execute(
3179+
self,
3180+
args: list[str],
3181+
called_from_automation_helper: bool,
3182+
) -> UnknownCheckParameterRuleSetsResult:
3183+
known_check_rule_sets = {
3184+
str(plugin.check_ruleset_name)
3185+
for plugin in agent_based_register.get_previously_loaded_plugins().check_plugins.values()
3186+
if plugin.check_ruleset_name
3187+
}
3188+
return UnknownCheckParameterRuleSetsResult(
3189+
[
3190+
rule_set
3191+
for rule_set in config.checkgroup_parameters
3192+
if rule_set not in known_check_rule_sets
3193+
]
3194+
)
3195+
3196+
3197+
automations.register(AutomationFindUnknownCheckParameterRuleSets())

cmk/base/core_config.py

-26
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
import cmk.base.api.agent_based.register as agent_based_register
3838
from cmk.base import config
39-
from cmk.base.api.agent_based.plugin_classes import CheckPlugin
4039
from cmk.base.config import ConfigCache, ObjectAttributes
4140
from cmk.base.nagios_utils import do_check_nagiosconfig
4241

@@ -392,7 +391,6 @@ def _create_core_config(
392391
config_warnings.initialize()
393392

394393
_verify_non_duplicate_hosts(duplicates)
395-
_verify_non_deprecated_checkgroups(plugins.check_plugins.values())
396394

397395
# recompute and save passwords, to ensure consistency:
398396
passwords = config_cache.collect_passwords()
@@ -414,30 +412,6 @@ def _create_core_config(
414412
)
415413

416414

417-
def _verify_non_deprecated_checkgroups(check_plugins: Iterable[CheckPlugin]) -> None:
418-
"""Verify that the user has no deprecated check groups configured."""
419-
# 'check_plugin.check_ruleset_name' is of type RuleSetName, which is an PluginName (good),
420-
# but config.checkgroup_parameters contains strings (todo)
421-
check_ruleset_names_with_plugin = {
422-
str(plugin.check_ruleset_name) for plugin in check_plugins if plugin.check_ruleset_name
423-
}
424-
425-
for checkgroup in config.checkgroup_parameters:
426-
if checkgroup not in check_ruleset_names_with_plugin:
427-
config_warnings.warn(
428-
'Found configured rules of deprecated check group "%s". These rules are not used '
429-
"by any check plug-in. Maybe this check group has been renamed during an update, "
430-
"in this case you will have to migrate your configuration to the new ruleset manually. "
431-
"Please check out the release notes of the involved versions. "
432-
'You may use the page "Deprecated rules" in the "Rule search" to view your rules '
433-
"and move them to the new rulesets. "
434-
"If this is not the case, the rules could be related to a disabled or removed "
435-
"extension package (mkp). You would have to enable/upload the corresponding package "
436-
"and remove the related rules before disabling/removing the package again."
437-
% checkgroup
438-
)
439-
440-
441415
def _verify_non_duplicate_hosts(duplicates: Collection[HostName]) -> None:
442416
if duplicates:
443417
config_warnings.warn(

cmk/gui/deprecations.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ def render(self, version: str) -> str:
212212
" by migrating or removing this plug-in."
213213
)
214214
case "unsorted":
215-
title = _("Unsorted")
216-
215+
title = self.ident
217216
info = ""
218217
recommendation = _(
219218
"We highly recommend solving this issue already in your installation."
@@ -300,8 +299,8 @@ def _find_ac_test_result_problems(
300299

301300
else:
302301
problem = problem_by_ident.setdefault(
303-
"unsorted",
304-
_ACTestResultProblem("unsorted", "unsorted"),
302+
ac_test_result.text,
303+
_ACTestResultProblem(ac_test_result.text, "unsorted"),
305304
)
306305

307306
problem.add_ac_test_result(site_id, ac_test_result)

cmk/gui/wato/_ac_tests.py

+46
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
ACTestCategories,
5656
ACTestRegistry,
5757
)
58+
from cmk.gui.watolib.check_mk_automations import find_unknown_check_parameter_rule_sets
5859
from cmk.gui.watolib.config_domain_name import ABCConfigDomain
5960
from cmk.gui.watolib.config_domains import ConfigDomainOMD
6061
from cmk.gui.watolib.rulesets import SingleRulesetRecursively
@@ -89,6 +90,7 @@ def register(ac_test_registry: ACTestRegistry) -> None:
8990
ac_test_registry.register(ACTestSizeOfExtensions)
9091
ac_test_registry.register(ACTestBrokenGUIExtension)
9192
ac_test_registry.register(ACTestESXDatasources)
93+
ac_test_registry.register(ACTestUnknownCheckParameterRuleSets)
9294
ac_test_registry.register(ACTestDeprecatedV1CheckPlugins)
9395
ac_test_registry.register(ACTestDeprecatedCheckPlugins)
9496
ac_test_registry.register(ACTestDeprecatedInventoryPlugins)
@@ -1332,6 +1334,50 @@ def _compute_deprecation_result(
13321334
)
13331335

13341336

1337+
class ACTestUnknownCheckParameterRuleSets(ACTest):
1338+
def category(self) -> str:
1339+
return ACTestCategories.deprecations
1340+
1341+
def title(self) -> str:
1342+
return _("Unknown check parameter rule sets")
1343+
1344+
def help(self) -> str:
1345+
return _(
1346+
"These rule sets are configured in your site, but not used by any check plug-in."
1347+
" There are two main reasons to have such rule sets configured:"
1348+
"<ol>"
1349+
"<li> Rule sets which were used by builtin check plugins that have been deprecated and"
1350+
" removed in the past. These can be cleaned up without any negative side effect.</li>"
1351+
"<li> Rule sets which belong to disabled or removed extension packages. If you plan to"
1352+
" keep it removed, you can safely clean them up. In case the extension package was"
1353+
" temporarily disabled, you may consider keeping the rule sets in place.</li>"
1354+
"</ol>"
1355+
)
1356+
1357+
def is_relevant(self) -> bool:
1358+
return True
1359+
1360+
def execute(self) -> Iterator[ACSingleResult]:
1361+
site_id = omd_site()
1362+
if rule_sets := find_unknown_check_parameter_rule_sets().result:
1363+
for rule_set in rule_sets:
1364+
yield ACSingleResult(
1365+
state=ACResultState.CRIT,
1366+
text=(
1367+
_("Found configured rules of unknown check parameter rule set %r.")
1368+
% rule_set
1369+
),
1370+
site_id=site_id,
1371+
)
1372+
return
1373+
1374+
yield ACSingleResult(
1375+
state=ACResultState.OK,
1376+
text=_("No unknown check parameter rule sets found."),
1377+
site_id=site_id,
1378+
)
1379+
1380+
13351381
class ACTestDeprecatedV1CheckPlugins(ACTest):
13361382
def category(self) -> str:
13371383
return ACTestCategories.deprecations

cmk/gui/watolib/check_mk_automations.py

+9
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,12 @@ def bake_agents(
559559
),
560560
results.BakeAgentsResult,
561561
)
562+
563+
564+
def find_unknown_check_parameter_rule_sets() -> results.UnknownCheckParameterRuleSetsResult:
565+
return _deserialize(
566+
_automation_serialized(
567+
"find-unknown-check-parameter-rule-sets",
568+
),
569+
results.UnknownCheckParameterRuleSetsResult,
570+
)

tests/unit/cmk/base/test_unit_automations.py

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_registered_automations() -> None:
5656
"update-dns-cache",
5757
"update-host-labels",
5858
"update-passwords-merged-file",
59+
"find-unknown-check-parameter-rule-sets",
5960
]
6061

6162
if cmk_version.edition(paths.omd_root) is not cmk_version.Edition.CRE:

tests/unit/cmk/gui/test_deprecations.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test__filter_non_ok_ac_test_results(
191191
{},
192192
[
193193
_ACTestResultProblem(
194-
ident="unsorted",
194+
ident="text",
195195
type="unsorted",
196196
_ac_test_results={
197197
SiteId("site_id_1"): [
@@ -477,13 +477,13 @@ def test__find_ac_test_result_problems(
477477
[
478478
pytest.param(
479479
_ACTestResultProblem(
480-
ident="ident",
480+
ident="A text",
481481
type="unsorted",
482482
_ac_test_results={
483483
SiteId("site_id"): [
484484
ACTestResult(
485485
ACResultState.WARN,
486-
"text",
486+
"A text",
487487
"test_id",
488488
"deprecations",
489489
"Title",
@@ -494,19 +494,19 @@ def test__find_ac_test_result_problems(
494494
],
495495
},
496496
),
497-
"Unsorted",
497+
"A text",
498498
"This may partially work in Checkmk 2.3.0 but will stop working from the next major version onwards.",
499499
id="unsorted-warn",
500500
),
501501
pytest.param(
502502
_ACTestResultProblem(
503-
ident="ident",
503+
ident="A text",
504504
type="unsorted",
505505
_ac_test_results={
506506
SiteId("site_id"): [
507507
ACTestResult(
508508
ACResultState.CRIT,
509-
"text",
509+
"A text",
510510
"test_id",
511511
"deprecations",
512512
"Title",
@@ -517,7 +517,7 @@ def test__find_ac_test_result_problems(
517517
],
518518
},
519519
),
520-
"Unsorted",
520+
"A text",
521521
"This does not work in Checkmk 2.3.0.",
522522
id="unsorted-crit",
523523
),

tests/unit/cmk/gui/watolib/test_analyze_configuration.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_registered_ac_tests() -> None:
3636
"ACTestCheckMKFetcherUsage",
3737
"ACTestCheckMKCheckerNumber",
3838
"ACTestCheckMKCheckerUsage",
39+
"ACTestUnknownCheckParameterRuleSets",
3940
"ACTestDeprecatedV1CheckPlugins",
4041
"ACTestDeprecatedCheckPlugins",
4142
"ACTestDeprecatedInventoryPlugins",

0 commit comments

Comments
 (0)