Module: check_mk
Branch: master
Commit: 4127cde9e94526156a4da1e297dc65ea0688dee8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4127cde9e94526…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Sep 7 11:48:08 2018 +0200
Introduced automation call get-service-configurations and
explicit setting of service custom variables and one integration test
Change-Id: I35e76ddda7dcfb287cf4841dbb14a1b183b23544
---
cmk_base/automations/check_mk.py | 40 ++++++++++++++++++++++++++
cmk_base/config.py | 9 ++++++
cmk_base/default_config/base.py | 3 ++
tests/integration/cmk_base/test_automations.py | 9 ++++++
4 files changed, 61 insertions(+)
diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py
index 8c2536f..2fd244f 100644
--- a/cmk_base/automations/check_mk.py
+++ b/cmk_base/automations/check_mk.py
@@ -40,6 +40,7 @@ import cmk_base.core
import cmk_base.core_config as core_config
import cmk_base.snmp as snmp
import cmk_base.discovery as discovery
+import cmk_base.check_table as check_table
from cmk_base.automations import automations, Automation, MKAutomationError
import cmk_base.check_utils
import cmk_base.autochecks
@@ -1404,3 +1405,42 @@ class AutomationGetBulks(Automation):
automations.register(AutomationGetBulks())
+
+
+class AutomationGetServiceConfigurations(Automation):
+ cmd = "get-service-configurations"
+ needs_config = True
+ needs_checks = True
+
+ def execute(self, args):
+ result = {"hosts": {}}
+ for hostname in config.all_active_hosts():
+ result["hosts"][hostname] = self._get_config_for_host(hostname)
+
+ result["checkgroup_of_checks"] = self._get_checkgroup_of_checks()
+ return result
+
+
+ def _get_config_for_host(self, hostname):
+ return {"checks": check_table.get_check_table(hostname,
remove_duplicates = True),
+ "active_checks": self._get_active_checks(hostname)}
+
+
+ def _get_active_checks(self, hostname):
+ # legacy checks via active_checks
+ actchecks = []
+ for acttype, rules in config.active_checks.iteritems():
+ entries = rulesets.host_extra_conf(hostname, rules)
+ for params in entries:
+ description = config.active_check_service_description(hostname, acttype,
params)
+ actchecks.append((acttype, description, params))
+ return actchecks
+
+ def _get_checkgroup_of_checks(self):
+ checkgroup_of_checks = {}
+ for check_plugin_name, check in checks.check_info.items():
+ checkgroup_of_checks[check_plugin_name] = check.get("group")
+ return checkgroup_of_checks
+
+automations.register(AutomationGetServiceConfigurations())
+
diff --git a/cmk_base/config.py b/cmk_base/config.py
index bc05f0e..5ec77f9 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -1010,6 +1010,15 @@ def agent_target_version(hostname):
#
+# Explicit custom variables
+#
+def get_explicit_service_custom_variables(hostname, service_description):
+ try:
+ return explicit_service_custom_variables[(hostname, service_description)]
+ except KeyError:
+ return {}
+
+#
# SNMP
#
diff --git a/cmk_base/default_config/base.py b/cmk_base/default_config/base.py
index 1220494..fdde9dc 100644
--- a/cmk_base/default_config/base.py
+++ b/cmk_base/default_config/base.py
@@ -82,6 +82,9 @@ explicit_snmp_communities = {} # override the rule based
configuration
snmp_timing = []
snmp_character_encodings = []
+# Custom variables
+explicit_service_custom_variables = {}
+
# Management board settings
management_board_config = [] # Ruleset to specify management board settings
management_protocol = {} # Mapping from hostname to management board
protocol
diff --git a/tests/integration/cmk_base/test_automations.py
b/tests/integration/cmk_base/test_automations.py
index e7c1594..d70dd47 100644
--- a/tests/integration/cmk_base/test_automations.py
+++ b/tests/integration/cmk_base/test_automations.py
@@ -478,6 +478,15 @@ def test_automation_get_configuration(test_cfg, site):
site.write_file("etc/check_mk/main.mk", "")
+def test_automation_get_service_configurations(test_cfg, site):
+ data = _execute_automation(site, "get-service-configurations")
+ assert type(data) == dict
+ assert data["checkgroup_of_checks"]
+ assert data["hosts"]["modes-test-host"]
+ print data["hosts"]["modes-test-host"]
+ assert
data["hosts"]["modes-test-host"]["checks"][("cpu.loads",
None)][1] == "CPU load"
+
+
# TODO: rename-hosts
# TODO: delete-hosts
# TODO: scan-parents