Module: check_mk
Branch: master
Commit: aa4f1162ccd335354efab8a63e159c6436e2e716
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=aa4f1162ccd335…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 27 09:49:35 2019 +0100
7328 FIX Deprecate inventory_processes and inv_domino_tasks rulesets
If you have always used WATO to configure your Check_MK you are not affected
by this change.
There have been two rulesets for configuring process discovery rules for a long
time. The old one, <tt>inventory_processes</tt>, and the newer WATO compatible
ruleset <tt>inventory_processes_rules</tt>. The second one has replaced
inventory_processes a long time ago. The old ruleset was still working for
compatibility but has been removed now.
If you have configured such rules in your configuration, it will still load,
but print out a warning message like this: "WARNING: Found rules for deprecated
ruleset 'inventory_processes'. These rules are not applied anymore. In case you
still need them, you need to migrate them by hand. Otherwise you can remove
them from your configuration."
The same applies to the ruleset <tt>inv_domino_tasks</tt> and
<tt>inv_domino_tasks_rules</tt>.
Change-Id: I9217d85b7e7361f01243f20bf9d93ce67dcc6517
---
.werks/7328 | 26 ++++++++++++++++++++
checkman/domino_tasks | 39 +-----------------------------
checkman/ps | 56 ++++----------------------------------------
checks/domino_tasks | 5 +++-
checks/ps | 5 +++-
checks/ps.include | 49 +++-----------------------------------
cmk_base/config.py | 2 ++
tests/unit/checks/test_ps.py | 4 ++--
8 files changed, 46 insertions(+), 140 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=aa4f1162cc…
Module: check_mk
Branch: master
Commit: 2e09cbbefab998a28eb19fb77706a4d97bfa9d70
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2e09cbbefab998…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 27 09:55:39 2019 +0100
7329 FIX Deprecate logwatch_patterns configuration option
If you have always used WATO to configure your Check_MK you are not affected
by this change.
There have been two configuration options for configuring logwatch pattern on
Check_MK server side rules for a long time. The old one,
<tt>logwatch_patterns</tt>, and the newer WATO compatible ruleset
<tt>logwatch_rules</tt>. The second one has replaced the first one a long time
ago. The old config optionswas still working for compatibility but has been
removed now.
If you have configured such rules in your configuration, it will still load,
but print out a warning message like this: "WARNING: Found rules for deprecated
ruleset 'logwatch_patterns'. These rules are not applied anymore. In case you
still need them, you need to migrate them by hand. Otherwise you can remove
them from your configuration."
Change-Id: Iaa97c79745cbf1014cca025582757c5700ba8029
---
.werks/7329 | 24 ++++++++++++++++++++++++
checks/logwatch | 46 +++++-----------------------------------------
cmk_base/check_api.py | 9 +++++++--
cmk_base/config.py | 1 +
4 files changed, 37 insertions(+), 43 deletions(-)
diff --git a/.werks/7329 b/.werks/7329
new file mode 100644
index 0000000..ecd0e05
--- /dev/null
+++ b/.werks/7329
@@ -0,0 +1,24 @@
+Title: Deprecate logwatch_patterns configuration option
+Level: 1
+Component: checks
+Compatible: incomp
+Edition: cre
+Version: 1.6.0i1
+Date: 1553676821
+Class: fix
+
+If you have always used WATO to configure your Check_MK you are not affected
+by this change.
+
+There have been two configuration options for configuring logwatch pattern on
+Check_MK server side rules for a long time. The old one,
+<tt>logwatch_patterns</tt>, and the newer WATO compatible ruleset
+<tt>logwatch_rules</tt>. The second one has replaced the first one a long time
+ago. The old config optionswas still working for compatibility but has been
+removed now.
+
+If you have configured such rules in your configuration, it will still load,
+but print out a warning message like this: "WARNING: Found rules for deprecated
+ruleset 'logwatch_patterns'. These rules are not applied anymore. In case you
+still need them, you need to migrate them by hand. Otherwise you can remove
+them from your configuration."
diff --git a/checks/logwatch b/checks/logwatch
index a9b9c26..7c4adbd 100644
--- a/checks/logwatch
+++ b/checks/logwatch
@@ -30,12 +30,15 @@ import cmk.utils.debug
# Configuration variables in main.mk needed during the actual check
logwatch_dir = cmk.utils.paths.var_dir + '/logwatch'
-logwatch_patterns = {}
logwatch_rules = []
logwatch_max_filesize = 500000 # do not save more than 500k of message (configurable)
logwatch_service_output = "default"
logwatch_groups = []
+# Deprecated option since 1.6. cmk_base creates a config warning when finding rules
+# for this ruleset. Can be dropped with 1.7.
+logwatch_patterns = {}
+
# Variables embedded in precompiled checks
check_config_variables += ["logwatch_dir", "logwatch_max_filesize", "logwatch_service_output"]
@@ -95,20 +98,6 @@ def logwatch_select_forwarded(info):
return forwarded_logs, not_forwarded_logs
-# logwatch_patterns = {
-# 'System': [
-# ( 'W', 'sshd' ),
-# ( ['host1', 'host2'], 'C', 'ssh' ), # only applies to certain hosts
-# ( ['lnx', 'dmz'], ALL_HOSTS, 'C', 'ssh' ), # only applies to host having certain tags
-# ( ALL_HOSTS, (10, 20), 'x' ), # at 10 messages per interval warn, at 20 crit
-# ( 'I', '0' )
-# ],
-# 'Application': [
-# ( 'W', 'crash.exe' ),
-# ( 'E', 'ssh' )
-# ]
-# }
-
# New rule-stule logwatch_rules in WATO friendly consistent rule notation:
#
# logwatch_rules = [
@@ -179,31 +168,6 @@ def logwatch_precompile(hostname, item, _unused):
else:
params["reclassify_patterns"].extend(x for x in rule)
- # Now load the old logwatch_patterns var
- patterns = logwatch_patterns.get(item)
- if patterns:
- for entry in patterns:
- hostlist = None
- tags = []
-
- pattern = entry[-1]
- level = entry[-2]
-
- if len(entry) >= 3: # found optional host list
- hostlist = entry[-3]
- if len(entry) >= 4: # found optional host tags
- tags = entry[-4]
-
- if hostlist and not \
- (hosttags_match_taglist(tags_of_host(hostname), tags) and \
- in_extraconf_hostlist(hostlist, hostname)):
- continue
-
- # All entries need to be 3-Tuples to be compatible with the wato rule.
- # The third entry is a comment not used in the check anyway, so we just
- # fill it with None here.
- params["reclassify_patterns"].append((level, pattern, None))
-
return params
@@ -286,7 +250,7 @@ def inventory_logwatch(info):
# In case of a precompiled check, params contains the precompiled
-# logwatch_patterns for the logfile we deal with. If using check_mk
+# logwatch patterns for the logfile we deal with. If using check_mk
# without precompiled checks, the params must be None an will be
# ignored.
def check_logwatch(item, params, info):
diff --git a/cmk_base/check_api.py b/cmk_base/check_api.py
index 1083d5c..7b86370 100644
--- a/cmk_base/check_api.py
+++ b/cmk_base/check_api.py
@@ -214,13 +214,18 @@ no_discovery_possible = _check_api_utils.no_discovery_possible
service_extra_conf = _config.service_extra_conf
host_extra_conf = _config.host_extra_conf
in_binary_hostlist = _config.in_binary_hostlist
-in_extraconf_hostlist = _config.in_extraconf_hostlist
-hosttags_match_taglist = _config.hosttags_match_taglist
host_extra_conf_merged = _config.host_extra_conf_merged
+
+# TODO: Only used by logwatch check. Can we clean this up?
get_rule_options = _config.get_rule_options
all_matching_hosts = _config.all_matching_hosts
+# These functions were used in some specific checks until 1.6. Don't add it to
+# the future check API. It's kept here for compatibility reasons for now.
+in_extraconf_hostlist = _config.in_extraconf_hostlist
+hosttags_match_taglist = _config.hosttags_match_taglist
tags_of_host = _config.tags_of_host
+
nagios_illegal_chars = _config.nagios_illegal_chars
is_ipv6_primary = _config.is_ipv6_primary
is_cmc = _config.is_cmc
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 155b419..ec99a5c 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -416,6 +416,7 @@ def _verify_no_deprecated_check_rulesets():
("services", "inventory_services"),
("domino_tasks", "inv_domino_tasks"),
("ps", "inventory_processes"),
+ ("logwatch", "logwatch_patterns"),
]
for check_plugin_name, varname in deprecated_rulesets:
check_context = get_check_context(check_plugin_name)
Module: check_mk
Branch: master
Commit: 6123e226bbdce7619da8016017989108d58ba781
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6123e226bbdce7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 27 08:39:12 2019 +0100
Refactor hand crafted rule matching out of several checks
These checks discover services based on service discovery rulesets, which
are regular host rulesets and don't need specific matching code in the
checks. They can simply use the generic host_extra_conf() function
instead of hand individual matching.
Change-Id: Ia5373ecfc877ed67b9e39e3b0a581b45683e1892
---
checks/ps.include | 19 ++++---------------
checks/sap | 11 ++---------
checks/services | 18 +++---------------
tests/unit/checks/conftest.py | 5 +++++
4 files changed, 14 insertions(+), 39 deletions(-)
diff --git a/checks/ps.include b/checks/ps.include
index b023c77..4b27153 100644
--- a/checks/ps.include
+++ b/checks/ps.include
@@ -89,24 +89,13 @@ def ps_data_configured_inventory_rules(invdata):
def ps_wato_configured_inventory_rules(invrules):
inventory_specs = []
- for rule in invrules:
- taglist, hostlist = rule[1:3]
- if len(rule) >= 4:
- options = rule[3]
- if options.get("disabled"):
- continue
-
- # Filter out entries with do not match our current host
- if not hosttags_match_taglist(tags_of_host(host_name()), taglist) \
- or not in_extraconf_hostlist(hostlist, host_name()):
- continue # TODO Test this jump
-
- v = rule[0]
- default_params = v.get('default_params', v)
+ for value in host_extra_conf(host_name(), invrules):
+ default_params = value.get('default_params', value)
if "cpu_rescale_max" not in default_params:
default_params["cpu_rescale_max"] = None
- inventory_specs.append((v['descr'], v.get('match'), v.get('user'), default_params))
+ inventory_specs.append((value['descr'], value.get('match'), value.get('user'),
+ default_params))
return inventory_specs
diff --git a/checks/sap b/checks/sap
index e12f7de..b845912 100644
--- a/checks/sap
+++ b/checks/sap
@@ -118,15 +118,8 @@ def inventory_sap_value(info):
inv = []
patterns = []
- for rule in inventory_sap_values:
- taglist, hostlist = rule[1:3]
- # Filter out entries with do not match our current host
- if not hosttags_match_taglist(tags_of_host(host_name()), taglist) \
- or not in_extraconf_hostlist(hostlist, host_name()):
- continue
-
- v = rule[0]
- patterns.append((v['match'], v.get('limit_item_levels')))
+ for value in host_extra_conf(host_name(), inventory_sap_values):
+ patterns.append((value['match'], value.get('limit_item_levels')))
for line in info:
for pattern, limit_item_levels in patterns:
diff --git a/checks/services b/checks/services
index 193ed60..26bc7a1 100644
--- a/checks/services
+++ b/checks/services
@@ -114,22 +114,10 @@ def inventory_windows_services(info):
matching += add_matching_services(name, description, state, start_type, svc)
return matching
- # Filter WATO compatible rules by tags/hostlist
+ # Extract the WATO compatible rules for the current host
rules = []
- for rule in inventory_services_rules:
- if len(rule) >= 4:
- options = rule[3]
- if options.get("disabled"):
- continue
-
- # 1. Get all rules matching the current host
- taglist, hostlist = rule[1:3]
- if not hosttags_match_taglist(tags_of_host(host_name()), taglist) \
- or not in_extraconf_hostlist(hostlist, host_name()):
- continue
-
- # 2. Now extract the list of service regexes
- value = rule[0]
+ for value in host_extra_conf(host_name(), inventory_services_rules):
+ # Now extract the list of service regexes
svcs = value.get('services', [])
state = value.get('state', None)
start_mode = value.get('start_mode', None)
diff --git a/tests/unit/checks/conftest.py b/tests/unit/checks/conftest.py
index 73b8e6c..b559259 100644
--- a/tests/unit/checks/conftest.py
+++ b/tests/unit/checks/conftest.py
@@ -14,5 +14,10 @@ def check_manager():
def clear_config_caches(monkeypatch):
import cmk_base
import cmk_base.caching
+ import cmk_base.config
monkeypatch.setattr(cmk_base, "config_cache", cmk_base.caching.CacheManager())
monkeypatch.setattr(cmk_base, "runtime_cache", cmk_base.caching.CacheManager())
+
+ monkeypatch.setattr(cmk_base.config, "all_hosts", ["non-existent-testhost"])
+ monkeypatch.setattr(cmk_base.config, "host_paths", {"non-existent-testhost": "/"})
+ cmk_base.config.get_config_cache().initialize()
Module: check_mk
Branch: master
Commit: 52d6cd043b2309176566fedaa723f972e505c65c
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=52d6cd043b2309…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 27 10:59:36 2019 +0100
logwatch.ec: Start cleaning up precompile rule match logic
The host matching has been untied from the later item matching. This
makes it possible to replace the individual rule matching implementation
by generic functions in the next step.
Change-Id: I8804f0b6d2d41700d80bdb6ca5cf0bc286c48f36
---
checks/logwatch | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/checks/logwatch b/checks/logwatch
index 7c4adbd..5790ff7 100644
--- a/checks/logwatch
+++ b/checks/logwatch
@@ -1169,23 +1169,23 @@ def logwatch_ec_precompile(hostname, item, params):
# Directly compute set of all matching hosts here, this
# will avoid recomputation later
hosts = all_matching_hosts(tags, hostlist, with_foreign_hosts=False)
- ruleset.append((settings, hosts, servlist))
+ if hostname not in hosts:
+ continue
+
+ ruleset.append((settings, servlist))
- # Filter out any logwatch_rules which do apply to to this host
- # 1st filter: Do not use rules where the hostname does not match
- # 2nd filter: Do not use rules with configured items where no item matches the
- # "restrict_logfiles" condition (if applicable)
+ # Do not use rules with configured items where no item matches the
+ # "restrict_logfiles" condition (if applicable)
logwatch_settings = []
for rule in ruleset:
- settings, hosts, rule_items = rule
- if hostname in hosts:
- if params.get("restrict_logfiles"):
- for rule_item in rule_items:
- if rule_item == "" or logwatch_ec_forwarding_enabled(params, rule_item):
- logwatch_settings.append((settings, rule_items))
- break
- else:
- logwatch_settings.append((settings, rule_items))
+ settings, rule_items = rule
+ if params.get("restrict_logfiles"):
+ for rule_item in rule_items:
+ if rule_item == "" or logwatch_ec_forwarding_enabled(params, rule_item):
+ logwatch_settings.append((settings, rule_items))
+ break
+ else:
+ logwatch_settings.append((settings, rule_items))
params.update({"logwatch_settings": logwatch_settings})
Module: check_mk
Branch: master
Commit: 1628b25717beded326d1b929967bcd49b361843b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1628b25717bede…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 27 09:16:03 2019 +0100
7327 FIX Deprecate inventory_services ruleset
If you have always used WATO to configure your Check_MK you are not affected
by this change.
There have been two rulesets for configuring windows service discovery rules
for a long time. The old one, <tt>inventory_services</tt>, and the newer WATO compatible
ruleset <tt>inventory_services_rules</tt>. The second one has replaced inventory_services_rules
in version 1.2.2 of Check_MK. The old ruleset was still working for compatibility
but has been removed now.
If you have configured such rules in your configuration, it will still load,
but print out a warning message like this: "WARNING: Found rules for deprecated
ruleset 'inventory_services'. These rules are not applied anymore. In case you
still need them, you need to migrate them by hand. Otherwise you can remove
them from your configuration."
Change-Id: I3312c82f7400061eaf17ab22030589f27a7401dd
---
.werks/7327 | 23 +++++++++++++++++++++++
checkman/services | 50 ++++----------------------------------------------
checks/services | 40 ++--------------------------------------
cmk_base/config.py | 14 ++++++++++++++
4 files changed, 43 insertions(+), 84 deletions(-)
diff --git a/.werks/7327 b/.werks/7327
new file mode 100644
index 0000000..07a7ab9
--- /dev/null
+++ b/.werks/7327
@@ -0,0 +1,23 @@
+Title: Deprecate inventory_services ruleset
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1553673436
+Class: fix
+
+If you have always used WATO to configure your Check_MK you are not affected
+by this change.
+
+There have been two rulesets for configuring windows service discovery rules
+for a long time. The old one, <tt>inventory_services</tt>, and the newer WATO compatible
+ruleset <tt>inventory_services_rules</tt>. The second one has replaced inventory_services_rules
+in version 1.2.2 of Check_MK. The old ruleset was still working for compatibility
+but has been removed now.
+
+If you have configured such rules in your configuration, it will still load,
+but print out a warning message like this: "WARNING: Found rules for deprecated
+ruleset 'inventory_services'. These rules are not applied anymore. In case you
+still need them, you need to migrate them by hand. Otherwise you can remove
+them from your configuration."
diff --git a/checkman/services b/checkman/services
index da764ba..f103cc9 100644
--- a/checkman/services
+++ b/checkman/services
@@ -11,15 +11,12 @@ description:
If you have just a small number of Windows hosts to monitor,
manual check configuration with {checks +=} will probably do.
- With a larger number of hosts we propose using {inventory_services}.
+ With a larger number of hosts we propose using {inventory_services_rules}.
This allows auto-detection of services according to their names,
current states and start types. The auto-detection can also make use
of host tags in order to use different rules on different sets of
hosts (for example for monitoring certain services only on production
servers). Inventory and manual checks can be used in parallel.
- Since version 1.2.1i2 there is a new option {inventory_services_rules}
- available, which is used to configure same options as the {inventory_services}
- option but in a standardized format which is configurable via WATO.
item:
The name of the service as string. Please note, that the agent replaces
@@ -35,45 +32,6 @@ inventory:
that should be monitored on your hosts. Because Check_MK cannot know, which
services are important for you, you have to configure some rules.
- As of version 1.1.10i2 it is very flexible, while still being compatible
- with the old simple-style format.
- In the variable {inventory_services} you specify a list of inventory
- declarations. In the easiest form, such a declaration is simply
- a string: the name of a service. On every host that service is found
- {running}, a check for that service will be created during inventory.
-
- If you prefix the name with a tilde {~}, then the string is interpreted
- as a regular expression matching the {beginning} of the service name.
- So the declaration {"~Audio"} will mach {AudioSrv}, and {".*Mobile"}
- will match all services containing the work {Mobile}. All patterns
- are case sensitive. Please note: the check being created will
- {not} contain the regular expression but the precise spelling of the
- service. One rule with a regular expression can create several checks.
-
- It is also possible to depend on the current state and/or the start
- type of the service when deciding whether to create a check. States
- and start types are appended and separated by a space. For example
- {"LanmanServer auto"} will match all services with the name {LanmanServer}
- which have the start type {auto}. Other possible start types are
- {boot}, {demand}, {disabled} and {system}. Please look at the agent output
- if you want to know, which kind of start types exist in your
- environment. The declaration {"Browser running"} means the same as
- just ommitting { running}, since that is the default. If you want
- to combine a state and start type, do this like the agent does,
- by using a slash: {"LmHosts running/auto"} will create a check for
- the service {LmHosts}, if that service if found running {and} has
- the start type auto.
-
- If you need your inventory rules to depend on properties of the host
- or just apply on some selected hosts, you can use "tuple"-entries
- instead of strings. Such an entries consist of an optional list of
- host tags, the keyword {ALL_HOSTS} or an explicit list of hosts and
- a {list} of service declarations like the one discussed above. Please
- consult the examples for details.
-
- Since version 1.2.1i2 there is a new option {inventory_services_rules}
- available, which is used to configure same options as the {inventory_services}
- option but in a standardized format. The option holds a list of rules
- where each rule contains one entry matching a list of service matching
- strings (regexes) state/start mode.
-
+ The option {inventory_services_rules} holds a list of rules where each rule
+ contains one entry matching a list of service matching strings (regexes)
+ state/start mode.
diff --git a/checks/services b/checks/services
index 26bc7a1..6943804 100644
--- a/checks/services
+++ b/checks/services
@@ -40,19 +40,10 @@
# BITS running/demand Intelligenter Hintergrund<FC>bertragungsdienst
# Bonjour_Service running/auto Dienst "Bonjour"
+# Deprecated option since 1.6. cmk_base creates a config warning when finding rules
+# for this ruleset. Can be dropped with 1.7.
inventory_services = []
-# Examples for inventory_services:
-# inventory_services = [
-# "HirnTest", # add service, if currently running
-# "TapiSrv running", # the same
-# "TermService auto", # add service, if start type is auto (regardless if running)
-# "BackupSrv running/auto", # add, if start type is auto and it's running
-# "~Backup.* running/auto", # same, but add all services matching a regex
-# ( [ "termserver" ] , ALL_HOSTS, [ "HirnTest running", "Sppoller auto" ] ), # same with tags..
-# ( ALL_HOSTS, [ "!Backup.*", "FooBar auto" ] ),
-# ]
-
# Implemented in 1.2.1i2:
# New rule-style (WATO compatible) notation:
# [({'start_mode': 'demand', 'service': ['Netman']}, [], ['@all'], {'docu_url': ''})]
@@ -102,18 +93,6 @@ def inventory_windows_services(info):
return [(name, {})]
- # Handle entries like ( [ "term" ], ALL_HOSTS, [ "FooBar auto", ".*TEST running" ] )
- def add_services_with_tags(name, description, state, start_type, entry):
- matching = []
- if len(entry) == 2:
- entry = ([],) + entry
- taglist, hostlist, svclist = entry
- if hosttags_match_taglist(tags_of_host(host_name()), taglist):
- if in_extraconf_hostlist(hostlist, host_name()):
- for svc in svclist:
- matching += add_matching_services(name, description, state, start_type, svc)
- return matching
-
# Extract the WATO compatible rules for the current host
rules = []
for value in host_extra_conf(host_name(), inventory_services_rules):
@@ -137,21 +116,6 @@ def inventory_windows_services(info):
state = line[2]
start_type = "unknown"
- #
- # Handle "old" inventory_services notation
- #
- for entry in inventory_services:
- if isinstance(entry, str):
- inventory += add_matching_services(name, description, state, start_type, entry)
- elif isinstance(entry, tuple):
- inventory += add_services_with_tags(name, description, state, start_type, entry)
- else:
- raise MKGeneralException("Invalid entry %r in inventory_services" % entry)
-
- #
- # New WATO compatible rule matching
- #
-
for rule in rules:
inventory += add_matching_services(name, description, state, start_type, rule)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 9aea948..7cdb3de 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -160,6 +160,7 @@ def load(with_conf_d=True, validate_hosts=True, exclude_parents_mk=False):
# Such validation only makes sense when all checks have been loaded
if all_checks_loaded():
verify_non_invalid_variables(vars_before_config)
+ _verify_no_deprecated_check_rulesets()
verify_snmp_communities_type()
@@ -410,6 +411,19 @@ def verify_snmp_communities_type():
sys.exit(1)
+def _verify_no_deprecated_check_rulesets():
+ deprecated_rulesets = [
+ ("services", "inventory_services"),
+ ]
+ for check_plugin_name, varname in deprecated_rulesets:
+ check_context = get_check_context(check_plugin_name)
+ if check_context[varname]:
+ console.warning(
+ "Found rules for deprecated ruleset %r. These rules are not applied "
+ "anymore. In case you still need them, you need to migrate them by hand. "
+ "Otherwise you can remove them from your configuration." % varname)
+
+
def all_nonfunction_vars():
return set(
[name for name, value in globals().items() if name[0] != '_' and not callable(value)])
Module: check_mk
Branch: master
Commit: 30c3fead2e9ed3dad3892bc00072165c1fab6dbc
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=30c3fead2e9ed3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 27 12:49:33 2019 +0100
Use generic host_extra_conf() for filtering host related rules
This is the only check left that uses all_matching_hosts(). We can avoid
this by bringing the logwatch_rules ruleset in the format of a host
ruleset and use the more common host_extra_conf() function.
Change-Id: I745d1d1aac76ebaca5f0b7a5da72f7d7f2e7778e
---
checks/logwatch | 15 ++++++---------
cmk_base/check_api.py | 2 +-
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/checks/logwatch b/checks/logwatch
index 116891a..a344fe1 100644
--- a/checks/logwatch
+++ b/checks/logwatch
@@ -1158,11 +1158,12 @@ def _precompile_ec_logwatch_settings(hostname, params, logwatch_rules):
"""The following code is used for creating the params of precompiled checks
and when Check_MK is called on the command line.
Check_MK in keepalive mode (in a running cmc) should never reach this code..."""
- ruleset = []
+
+ # Bring the logwatch_rules structure in a host ruleset structure to be able
+ # to use the generic host_extra_conf rule matching function
+ host_rules = []
for rule in logwatch_rules:
rule, rule_options = get_rule_options(rule)
- if rule_options.get("disabled"):
- continue
if len(rule) == 3:
settings, hostlist, servlist = rule
@@ -1172,13 +1173,9 @@ def _precompile_ec_logwatch_settings(hostname, params, logwatch_rules):
else:
continue
- # Directly compute set of all matching hosts here, this
- # will avoid recomputation later
- hosts = all_matching_hosts(tags, hostlist, with_foreign_hosts=False)
- if hostname not in hosts:
- continue
+ host_rules.append(((settings, servlist), tags, hostlist, rule_options))
- ruleset.append((settings, servlist))
+ ruleset = host_extra_conf(hostname, host_rules)
# Do not use rules with configured items where no item matches the
# "restrict_logfiles" condition (if applicable)
diff --git a/cmk_base/check_api.py b/cmk_base/check_api.py
index 7b86370..075f8dc 100644
--- a/cmk_base/check_api.py
+++ b/cmk_base/check_api.py
@@ -218,13 +218,13 @@ host_extra_conf_merged = _config.host_extra_conf_merged
# TODO: Only used by logwatch check. Can we clean this up?
get_rule_options = _config.get_rule_options
-all_matching_hosts = _config.all_matching_hosts
# These functions were used in some specific checks until 1.6. Don't add it to
# the future check API. It's kept here for compatibility reasons for now.
in_extraconf_hostlist = _config.in_extraconf_hostlist
hosttags_match_taglist = _config.hosttags_match_taglist
tags_of_host = _config.tags_of_host
+all_matching_hosts = _config.all_matching_hosts
nagios_illegal_chars = _config.nagios_illegal_chars
is_ipv6_primary = _config.is_ipv6_primary