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)])