Module: check_mk
Branch: master
Commit: 2bac5f1e42dd802b79f5141f72966bd901c1a6d0
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2bac5f1e42dd80…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Tue Oct 24 16:05:48 2017 +0200
add function active_check_service_description
Add the function active_check_service_description to cmk_base/config.py
as the single point of truth to retreive service descriptions for
active checks. This makes it possible to define a renaming of service
descriptions for active checks later on.
Change-Id: I5d6a2cc84f3f19833b1d262e46ba435bb800470f
---
cmk_base/automations/check_mk.py | 5 ++---
cmk_base/config.py | 14 +++++++++++++-
cmk_base/core_config.py | 5 -----
cmk_base/core_nagios.py | 2 +-
cmk_base/discovery.py | 3 +--
5 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/cmk_base/automations/check_mk.py b/cmk_base/automations/check_mk.py
index 4abdd0a..ba87c1d 100644
--- a/cmk_base/automations/check_mk.py
+++ b/cmk_base/automations/check_mk.py
@@ -570,9 +570,8 @@ class AutomationAnalyseServices(Automation):
for acttype, rules in config.active_checks.items():
entries = rulesets.host_extra_conf(hostname, rules)
if entries:
- act_info = checks.active_check_info[acttype]
for params in entries:
- description = act_info["service_description"](params)
+ description = config.active_check_service_description(hostname, acttype, params)
if description == servicedesc:
return {
"origin" : "active",
@@ -1106,7 +1105,7 @@ class AutomationActiveCheck(Automation):
if entries:
act_info = checks.active_check_info[plugin]
for params in entries:
- description = act_info["service_description"](params).replace('$HOSTNAME$', hostname)
+ description = config.active_check_service_description(hostname, act_info, params)
if description == item:
args = core_config.active_check_arguments(hostname, description, act_info["argument_function"](params))
command_line = self._replace_core_macros(hostname, act_info["command_line"].replace("$ARG1$", args))
diff --git a/cmk_base/config.py b/cmk_base/config.py
index a8e37fb..cca564a 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -461,7 +461,7 @@ def all_configured_clusters():
return cache
-# This function should only be used during duplicate host check! It has to work like
+# This function should only be used during duplicate host check! It has to work like
# all_active_hosts() but with the difference that duplicates are not removed.
def all_active_hosts_with_duplicates():
# Only available with CEE
@@ -1050,6 +1050,18 @@ def service_description(hostname, check_type, item):
return get_final_service_description(hostname, descr)
+def active_check_service_description(hostname, active_check_type, params):
+ import cmk_base.checks as checks
+ if active_check_type not in checks.active_check_info:
+ return "Unimplemented check %s" % active_check_type
+
+ act_info = checks.active_check_info[active_check_type]
+ description = act_info["service_description"](params)
+ description = description.replace('$HOSTNAME$', hostname)
+
+ return get_final_service_description(hostname, description)
+
+
def get_final_service_description(hostname, description):
translations = get_service_translations(hostname)
if translations:
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 42a71d8..e9d20a2 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -311,11 +311,6 @@ def do_update(with_precompile):
# | Active check specific functions |
# '----------------------------------------------------------------------'
-def active_check_service_description(hostname, act_info, params):
- description = act_info["service_description"](params).replace('$HOSTNAME$', hostname)
- return config.get_final_service_description(hostname, description)
-
-
def active_check_arguments(hostname, description, args):
if type(args) in [ str, unicode ]:
return args
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 618c298..9493c91 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -403,7 +403,7 @@ define service {
checks.set_hostname(hostname)
has_perfdata = act_info.get('has_perfdata', False)
- description = core_config.active_check_service_description(hostname, act_info, params)
+ description = config.active_check_service_description(hostname, acttype, params)
if do_omit_service(hostname, description):
continue
diff --git a/cmk_base/discovery.py b/cmk_base/discovery.py
index f969b47..2f0bd71 100644
--- a/cmk_base/discovery.py
+++ b/cmk_base/discovery.py
@@ -1074,10 +1074,9 @@ def _merge_manual_services(services, hostname, on_error):
# Similar for 'active_checks', but here we have parameters
for acttype, rules in config.active_checks.items():
- act_info = checks.active_check_info[acttype]
entries = rulesets.host_extra_conf(hostname, rules)
for params in entries:
- descr = act_info["service_description"](params)
+ descr = config.active_check_service_description(hostname, acttype, params)
services[(acttype, descr)] = ('active', repr(params))
# Handle disabled services -> "ignored"