Module: check_mk
Branch: master
Commit: 28e109f51652ee284c89be2b14a489153632ee75
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=28e109f51652ee…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Apr 12 18:13:01 2019 +0200
Centralize tuple ruleset defines
Change-Id: I108b8ffb13da59ef666cb571519dadfe5cfb2d36
---
cmk/gui/watolib/utils.py | 10 ++++++----
cmk/utils/rulesets/tuple_rulesets.py | 32 ++++++++++++++++++++++++++++++++
cmk_base/config.py | 14 ++++++++------
3 files changed, 46 insertions(+), 10 deletions(-)
diff --git a/cmk/gui/watolib/utils.py b/cmk/gui/watolib/utils.py
index 77099b8..be9f397 100644
--- a/cmk/gui/watolib/utils.py
+++ b/cmk/gui/watolib/utils.py
@@ -33,6 +33,7 @@ from contextlib import contextmanager
import cmk
import cmk.utils.paths
+import cmk.utils.rulesets.tuple_rulesets
import cmk.utils.store as store
import cmk.gui.config as config
@@ -40,10 +41,11 @@ from cmk.gui.globals import html
from cmk.gui.i18n import _
from cmk.gui.exceptions import MKGeneralException
-# Constants used in configuration files
-ALL_HOSTS = ['@all']
-ALL_SERVICES = [""]
-NEGATE = '@negate'
+# TODO: Clean up all call sites in the GUI and only use them in WATO config file loading code
+ALL_HOSTS = cmk.utils.rulesets.tuple_rulesets.ALL_HOSTS
+ALL_SERVICES = cmk.utils.rulesets.tuple_rulesets.ALL_SERVICES
+NEGATE = cmk.utils.rulesets.tuple_rulesets.NEGATE
+
NO_ITEM = {} # Just an arbitrary unique thing
ENTRY_NEGATE_CHAR = "!"
diff --git a/cmk/utils/rulesets/tuple_rulesets.py b/cmk/utils/rulesets/tuple_rulesets.py
new file mode 100644
index 0000000..d6929fb
--- /dev/null
+++ b/cmk/utils/rulesets/tuple_rulesets.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2019 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+# Conveniance macros for legacy tuple based host and service rules
+PHYSICAL_HOSTS = ['@physical'] # all hosts but not clusters
+CLUSTER_HOSTS = ['@cluster'] # all cluster hosts
+ALL_HOSTS = ['@all'] # physical and cluster hosts
+ALL_SERVICES = [""] # optical replacement"
+NEGATE = '@negate' # negation in boolean lists
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 2d77fb2..bea4422 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -42,6 +42,7 @@ import cmk.utils.debug
import cmk.utils.paths
from cmk.utils.regex import regex, is_regex
import cmk.utils.translations
+import cmk.utils.rulesets.tuple_rulesets
import cmk.utils.store as store
import cmk.utils
from cmk.utils.exceptions import MKGeneralException, MKTerminate
@@ -1805,12 +1806,13 @@ def _in_servicematcher_list(service_matchers, item):
# | Some constants to be used in the configuration and at other places |
# '----------------------------------------------------------------------'
-# Conveniance macros for host and service rules
-PHYSICAL_HOSTS = ['@physical'] # all hosts but not clusters
-CLUSTER_HOSTS = ['@cluster'] # all cluster hosts
-ALL_HOSTS = ['@all'] # physical and cluster hosts
-ALL_SERVICES = [""] # optical replacement"
-NEGATE = '@negate' # negation in boolean lists
+# Conveniance macros for legacy tuple based host and service rules
+# TODO: Deprecate these in a gentle way
+PHYSICAL_HOSTS = cmk.utils.rulesets.tuple_rulesets.PHYSICAL_HOSTS
+CLUSTER_HOSTS = cmk.utils.rulesets.tuple_rulesets.CLUSTER_HOSTS
+ALL_HOSTS = cmk.utils.rulesets.tuple_rulesets.ALL_HOSTS
+ALL_SERVICES = cmk.utils.rulesets.tuple_rulesets.ALL_SERVICES
+NEGATE = cmk.utils.rulesets.tuple_rulesets.NEGATE
# TODO: Cleanup access to check_info[] -> replace it by different function calls
# like for example check_exists(...)
Module: check_mk
Branch: master
Commit: 5cdc5c5fe25ea7bdef717a19599dae4696eed986
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5cdc5c5fe25ea7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sun Apr 14 17:01:21 2019 +0200
RuleMatcher: Implement ability to query fields of nested documents
Change-Id: I17c6e08a60ebcfc4759f163ab8de82e0facb4d17
---
cmk/utils/rulesets/rule_matcher.py | 19 +++++++++++++++++--
tests/unit/cmk/utils/rulesets/test_rule_matcher.py | 10 +++++++++-
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/cmk/utils/rulesets/rule_matcher.py b/cmk/utils/rulesets/rule_matcher.py
index 2c11da8..098affd 100644
--- a/cmk/utils/rulesets/rule_matcher.py
+++ b/cmk/utils/rulesets/rule_matcher.py
@@ -96,15 +96,30 @@ class RuleMatcher(object):
yield self._match_leaf_clause(document, field_or_op, cond)
def _match_leaf_clause(self, document, field, condition):
+ field_exists, value = True, None
+ try:
+ value = self._get_value(document, field)
+ except KeyError:
+ field_exists = False
+
if isinstance(condition, collections.Mapping):
# There are two options for dicts. It's either a operator object or
# a nested document match (which is only possible as full document
# equal comparison). In case of an operator object all keys are operators.
if self._is_operator_object(condition):
- return all(self._match_operator_object(document[field], condition))
+ return all(self._match_operator_object(value, condition))
# Realize the leaf equal comparison
- return field in document and document[field] == condition
+ return field_exists and value == condition
+
+ def _get_value(self, document, field):
+ """Returns either the value or raises a KeyError in case the field does not exist
+ This method implements the ability to query fields of nested documents.
+ """
+ if not isinstance(field, six.string_types) or "." not in field:
+ return document[field]
+
+ return reduce(operator.getitem, field.split("."), document)
def _is_operator_object(self, condition):
"""Once one operator field is found in the expression"""
diff --git a/tests/unit/cmk/utils/rulesets/test_rule_matcher.py b/tests/unit/cmk/utils/rulesets/test_rule_matcher.py
index a14c215..1f988ce 100644
--- a/tests/unit/cmk/utils/rulesets/test_rule_matcher.py
+++ b/tests/unit/cmk/utils/rulesets/test_rule_matcher.py
@@ -70,10 +70,18 @@ SIMPLE_MATCHES = [
}, []),
Case({u"düng": u"däng"}, [HOST_TEST]),
Case({1: 2}, [HOST_PROD]),
+ Case({"not_existing": "bla"}, []),
]
NESTED_FIELD_MATCHES = [
- # Case({"tags.crit": "test"}, [HOST_TEST]),
+ Case({"tags.crit": "test"}, [HOST_TEST]),
+ Case({"tags.crit": {
+ "$eq": "test"
+ }}, [HOST_TEST]),
+ Case({"tags.crit": {
+ "$ne": "test"
+ }}, [HOST_PROD]),
+ Case({"tags.not_existing": "test"}, []),
]
COMPARISON_MATCHES = [
Module: check_mk
Branch: master
Commit: 57960ee59a82b22146ce74ef92b043580c497053
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=57960ee59a82b2…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Apr 15 13:05:05 2019 +0200
Started implementing ruleset to dict transformer
* It receives a complete ruleset, scans the rules and transforms all
found tuple rules to the new dict based structure
* The rules are updated in-place
CMK-1941
Change-Id: I20b7a53683181eb37f7f00003805894a3273e64a
---
cmk/utils/rulesets/tuple_rulesets.py | 211 +++++++++
.../cmk/utils/rulesets/test_ruleset_transformer.py | 517 +++++++++++++++++++++
2 files changed, 728 insertions(+)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=57960ee59a…
Module: check_mk
Branch: master
Commit: dc5d282a79bdcc495ed43958bc8452ff75737067
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dc5d282a79bdcc…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Mon Apr 15 11:32:47 2019 +0200
werk 7336: fix html
Change-Id: I2132ae0463e6a5593453fa3eac06a66a6157e4f6
---
.werks/7336 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.werks/7336 b/.werks/7336
index 1c2c562..534dcea 100644
--- a/.werks/7336
+++ b/.werks/7336
@@ -7,7 +7,7 @@ Version: 1.6.0i1
Date: 1554819594
Class: feature
-A new HW/SW inventory script has been added that works on a generic "<<<labels>>>" section.
+A new HW/SW inventory script has been added that works on a generic "<<<labels>>>" section.
It is used to discover host labels from this section.
The first agent that produces this section is the Kubernetes special agent. It creates the
Module: check_mk
Branch: master
Commit: 864aa5b6dc3323d2979e7a4c09f9c2fdd3b994af
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=864aa5b6dc3323…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Mon Apr 15 10:46:23 2019 +0200
agent_azure: remove unused attribute
Change-Id: I90018cb571ec1ad3abf2c3825b5acf8622f3c72a
---
agents/special/agent_azure | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/agents/special/agent_azure b/agents/special/agent_azure
index 607b853..a75cbfb 100755
--- a/agents/special/agent_azure
+++ b/agents/special/agent_azure
@@ -182,17 +182,16 @@ def parse_arguments(argv):
default=[],
metavar='TAG',
action='append',
- help='''Only monitor resources that have the specified TAG. To require multiple tags,
- provide the option more than once.''')
+ help='''Only monitor resources that have the specified TAG.
+ To require multiple tags, provide the option more than once.''')
parser.add_argument(
"--require-tag-value",
default=[],
metavar=("TAG", "VALUE"),
nargs=2,
action='append',
- help=
- '''Only monitor resources that have the specified TAG set to VALUE. To require multiple tags,
- provide the option more than once.''')
+ help='''Only monitor resources that have the specified TAG set to VALUE.
+ To require multiple tags, provide the option more than once.''')
parser.add_argument(
"--explicit-config",
default=[],
@@ -510,7 +509,6 @@ class AzureClient(object): # pylint: disable=too-many-instance-attributes
self.timespans = self._get_timespans()
self.resources_cache = None
- self.metrics_cache = {}
@staticmethod
def _get_timespans():
Module: check_mk
Branch: master
Commit: 35524d07966cf82bbc94b6376a0a38afb596778f
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=35524d07966cf8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Sun Apr 14 19:38:47 2019 +0200
Cleanup ancient discovery function handling
Change-Id: I89827e18312a708bbf184bbf65aa7315913ab7d5
---
cmk_base/discovery.py | 11 +----------
1 file changed, 1 insertion(+), 10 deletions(-)
diff --git a/cmk_base/discovery.py b/cmk_base/discovery.py
index d3e5298..6b36a98 100644
--- a/cmk_base/discovery.py
+++ b/cmk_base/discovery.py
@@ -27,7 +27,6 @@
import os
import socket
import time
-import inspect
import signal
from cmk.utils.regex import regex
@@ -842,15 +841,7 @@ def _execute_discovery(multi_host_sections, hostname, ipaddress, check_plugin_na
and not config.check_info[check_plugin_name]["handle_empty_info"]:
return []
- # Check number of arguments of discovery function. Note: This
- # check for the legacy API will be removed after 1.2.6.
- if len(inspect.getargspec(discovery_function).args) == 2:
- discovered_items = discovery_function(
- check_plugin_name,
- section_content) # discovery is a list of pairs (item, current_value)
- else:
- # New preferred style since 1.1.11i3: only one argument: section_content
- discovered_items = discovery_function(section_content)
+ discovered_items = discovery_function(section_content)
# tolerate function not explicitely returning []
if discovered_items is None: