2 import cmk_base
.automations
3 import cmk_base
.automations
.check_mk
as automations
4 import cmk_base
.config
as config
7 def test_registered_automations(site
):
16 'get-check-information',
20 'get-real-time-checks',
21 'get-service-configurations',
23 'notification-analyse',
24 'notification-get-bulks',
25 'notification-replay',
35 if cmk
.is_enterprise_edition():
36 needed_automations
+= [
45 'remove-unpackaged-file',
48 registered_automations
= cmk_base
.automations
.automations
._automations
.keys()
50 assert sorted(needed_automations
) == sorted(registered_automations
)
53 def test_static_check_rules_of_host(monkeypatch
):
54 as_automation
= automations
.AutomationAnalyseServices()
55 assert as_automation
.static_check_rules_of("checkgroup_ding", "test-host") == []
57 monkeypatch
.setattr(config
, "all_hosts", ["test-host"])
58 monkeypatch
.setattr(config
, "host_paths", {"test-host": "/"})
60 config
, "static_checks", {
62 (("ding-check", "item"), [], config
.ALL_HOSTS
, {}),
63 (("ding-check", "item2"), [], config
.ALL_HOSTS
, {
66 (("dong-check", "item2", {
68 }), [], config
.ALL_HOSTS
, {}),
71 config
.get_config_cache().initialize()
73 assert as_automation
.static_check_rules_of("checkgroup_ding", "test-host") == [
74 ('ding-check', 'item'),
75 ('dong-check', 'item2', {
81 def test_get_labels_of_host(monkeypatch
):
82 automation
= automations
.AutomationGetLabelsOf()
84 monkeypatch
.setattr(config
, "all_hosts", ["test-host"])
85 monkeypatch
.setattr(config
, "host_paths", {"test-host": "/"})
86 monkeypatch
.setattr(config
, "host_labels", {
91 config
.get_config_cache().initialize()
93 assert automation
.execute(["host", "test-host"]) == {
98 "explicit": "explicit"
103 def test_get_labels_of_service(monkeypatch
):
104 automation
= automations
.AutomationGetLabelsOf()
106 monkeypatch
.setattr(config
, "all_hosts", ["test-host"])
107 monkeypatch
.setattr(config
, "host_paths", {"test-host": "/"})
112 }, [], config
.ALL_HOSTS
, ["CPU load$"], {}),
115 }, [], config
.ALL_HOSTS
, ["CPU load$"], {}),
117 monkeypatch
.setattr(config
, "service_label_rules", ruleset
)
119 config
.get_config_cache().initialize()
121 assert automation
.execute(["service", "test-host", "CPU load"]) == {
133 def test_analyse_host(monkeypatch
):
134 automation
= automations
.AutomationAnalyseHost()
136 monkeypatch
.setattr(config
, "all_hosts", ["test-host"])
137 monkeypatch
.setattr(config
, "host_paths", {"test-host": "/"})
138 monkeypatch
.setattr(config
, "host_labels", {
143 config
.get_config_cache().initialize()
145 assert automation
.execute(["test-host"]) == {
150 "explicit": "explicit"