Module: check_mk
Branch: master
Commit: 4ced77f86893ef547a02c3e9e092ef25527ed79a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4ced77f86893ef…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 27 17:36:59 2019 +0100
Cleanup: Synchronous Rule.to_dict_config and Rule.parse_dict_rule()
Both function now deal with optional and mandatory attributes in the
same way.
These dicts will be used as rule representation in the configuration
files in the future. Therefore we need to skip the attributes that are at
their default values to reduce the footprint of individual rule entries
which can be many in larger installations.
Change-Id: I866c79af9a5abe8719ead5b98e19a08c3cb7f647
---
cmk/gui/watolib/rulesets.py | 26 +++++++++++++++----------
tests/unit/cmk/gui/watolib/test_gui_rulesets.py | 3 +++
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/cmk/gui/watolib/rulesets.py b/cmk/gui/watolib/rulesets.py
index 1caa08f..264b05f 100644
--- a/cmk/gui/watolib/rulesets.py
+++ b/cmk/gui/watolib/rulesets.py
@@ -600,6 +600,8 @@ class Rule(object):
else:
raise NotImplementedError()
+ # TODO: Would make sense to implement independent parsing for the different
+ # ruleset types
def _parse_dict_rule(self, rule_config):
self.rule_options = rule_config.get("options", {})
@@ -612,9 +614,11 @@ class Rule(object):
else:
self.value = True
- conditions = rule_config.get("conditions", {})
+ conditions = rule_config["conditions"]
self.host_list = conditions.get("host_specs", [])
- self.item_list = conditions.get("service_specs")
+
+ if self.ruleset.item_type():
+ self.item_list = conditions.get("service_specs")
# Remove folder tag from tag list
tag_specs = conditions.get("host_tags", [])
@@ -705,20 +709,22 @@ class Rule(object):
return content
def to_dict_config(self):
- result = {"conditions": {}}
+ result = {
+ "conditions": {},
+ }
- result["options"] = self._rule_options_to_config()
+ rule_options = self._rule_options_to_config()
+ if rule_options:
+ result["options"] = rule_options
if self.ruleset.valuespec():
result["value"] = self.value
- else:
- if self.value:
- result["negate"] = False
- else:
- result["negate"] = True
+ elif self.value is False:
+ result["negate"] = True
result["conditions"]["host_specs"] = self.host_list
- result["conditions"]["host_tags"] = self.tag_specs
+ if self.tag_specs:
+ result["conditions"]["host_tags"] = self.tag_specs
if self.ruleset.item_type():
result["conditions"]["service_specs"] = self.item_list
diff --git a/tests/unit/cmk/gui/watolib/test_gui_rulesets.py b/tests/unit/cmk/gui/watolib/test_gui_rulesets.py
index 8607401..37b42ef 100644
--- a/tests/unit/cmk/gui/watolib/test_gui_rulesets.py
+++ b/tests/unit/cmk/gui/watolib/test_gui_rulesets.py
@@ -249,6 +249,9 @@ def test_rule_from_config_dict(ruleset_name, rule_spec, expected_attributes, rul
else:
assert rule.rule_options == {}
+ # test for synchronous to_dict on the way
+ assert rule.to_dict_config() == rule_spec
+
def test_rule_clone():
rule = _rule("clustered_services")
Module: check_mk
Branch: master
Commit: f21a576590f131e80848767a115d635982e3b8ce
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f21a576590f131…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Mar 28 11:59:24 2019 +0100
7330 FIX Fix confusions when working with localized shell environments
When switching to the site user context we now enforce a non localized
environment. The reason for this configuration is that the parameters and
outputs of the monitoring plug-ins are localized. If they are called from the
core, they are always language-neutral. During manual testing, the plugins may
behave differently depending on the localization of the user's environment
variables. This can lead to confusion during tests.
CMK-1832
Change-Id: Ia7b677b0daa5f7945db64b835e6a58cc70c36ee4
---
.werks/7330 | 15 +++++++++++++++
omd/packages/omd/skel/.profile | 8 ++++++++
2 files changed, 23 insertions(+)
diff --git a/.werks/7330 b/.werks/7330
new file mode 100644
index 0000000..389efb5
--- /dev/null
+++ b/.werks/7330
@@ -0,0 +1,15 @@
+Title: Fix confusions when working with localized shell environments
+Level: 1
+Component: omd
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1553770690
+Class: fix
+
+When switching to the site user context we now enforce a non localized
+environment. The reason for this configuration is that the parameters and
+outputs of the monitoring plug-ins are localized. If they are called from the
+core, they are always language-neutral. During manual testing, the plugins may
+behave differently depending on the localization of the user's environment
+variables. This can lead to confusion during tests.
diff --git a/omd/packages/omd/skel/.profile b/omd/packages/omd/skel/.profile
index 18204c1..2af7294 100644
--- a/omd/packages/omd/skel/.profile
+++ b/omd/packages/omd/skel/.profile
@@ -19,6 +19,14 @@ export MAILRC="$OMD_ROOT/etc/mail.rc"
# Make the python requests module trust the CAs configured in Check_MK
export REQUESTS_CA_BUNDLE=$OMD_ROOT/var/ssl/ca-certificates.crt
+# Enforce a non localized environment. The reason for this configuration is
+# that the parameters and outputs of the monitoring plug-ins are localized. If
+# they are called from the core, they are always language-neutral. During
+# manual testing, the plugins may behave differently depending on the
+# localization of the user's environment variables. This can lead to confusion
+# during tests.
+export LANG=C LC_ALL=C
+
# Set environment for the monitoring plugins that use state retention (like check_snmp).
export NAGIOS_PLUGIN_STATE_DIRECTORY="$OMD_ROOT/var/monitoring-plugins"
export MP_STATE_DIRECTORY=$NAGIOS_PLUGIN_STATE_DIRECTORY
Module: check_mk
Branch: master
Commit: 69c7110c382384d4b2f5cb4d25d1045563fbc171
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=69c7110c382384…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 27 17:04:57 2019 +0100
Cleanup: Use Rule dict representation for cloning
Change-Id: Id6b49641b98107a024c8782925a288cb6c9d90d0
---
cmk/gui/watolib/rulesets.py | 24 +-----------------------
1 file changed, 1 insertion(+), 23 deletions(-)
diff --git a/cmk/gui/watolib/rulesets.py b/cmk/gui/watolib/rulesets.py
index 28834e0..1caa08f 100644
--- a/cmk/gui/watolib/rulesets.py
+++ b/cmk/gui/watolib/rulesets.py
@@ -571,7 +571,7 @@ class Rule(object):
def clone(self):
cloned = Rule(self.folder, self.ruleset)
- cloned.from_config(self._format_rule())
+ cloned.from_config(self.to_dict_config())
return cloned
def _initialize(self):
@@ -725,28 +725,6 @@ class Rule(object):
return result
- def _format_rule(self):
- if self.ruleset.valuespec():
- rule = [self.value]
- elif not self.value:
- rule = [NEGATE]
- else:
- rule = []
-
- if self.tag_specs != []:
- rule.append(self.tag_specs)
-
- rule.append(self.host_list)
- if self.item_list is not None:
- rule.append(self.item_list)
-
- ro = self._rule_options_to_config()
-
- if ro:
- rule.append(ro)
-
- return tuple(rule)
-
# Append rule options, but only if they are not trivial. That way we
# keep as close as possible to the original Check_MK in rules.mk so that
# command line users will feel at home...