Module: check_mk
Branch: master
Commit: 17ed27908d97d85d04f71bc6faa6b57ef3f7f5dc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=17ed27908d97d8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Mar 27 11:08:02 2019 +0100
Add tests for computation of precompiled logwatch settings
Needed to extract compitation to make it easier to test this
Change-Id: I037dfc22e9804931078ea0ea4857d3291ec1dc01
---
checks/logwatch | 16 ++++++++++------
tests/unit/checks/test_logwatch.py | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/checks/logwatch b/checks/logwatch
index 5790ff7..116891a 100644
--- a/checks/logwatch
+++ b/checks/logwatch
@@ -1149,9 +1149,15 @@ def logwatch_ec_precompile(hostname, item, params):
params.update({"logwatch_settings": []})
return params
- # 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...
+ params.update(
+ {"logwatch_settings": _precompile_ec_logwatch_settings(hostname,
params, logwatch_rules)})
+ return params
+
+
+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 = []
for rule in logwatch_rules:
rule, rule_options = get_rule_options(rule)
@@ -1187,9 +1193,7 @@ def logwatch_ec_precompile(hostname, item, params):
else:
logwatch_settings.append((settings, rule_items))
- params.update({"logwatch_settings": logwatch_settings})
-
- return params
+ return logwatch_settings
precompile_params['logwatch.ec'] = logwatch_ec_precompile
diff --git a/tests/unit/checks/test_logwatch.py b/tests/unit/checks/test_logwatch.py
new file mode 100644
index 0000000..d2ebc64
--- /dev/null
+++ b/tests/unit/checks/test_logwatch.py
@@ -0,0 +1,34 @@
+import cmk_base.config as config
+
+
+def test_precompile_ec_logwatch_settings_no_rules(check_manager, monkeypatch):
+ check = check_manager.get_check("logwatch.ec")
+ assert
check.context["_precompile_ec_logwatch_settings"]("unknown-host", {},
[]) == []
+
+
+def test_precompile_ec_logwatch_settings(check_manager, monkeypatch):
+ check = check_manager.get_check("logwatch.ec")
+
+ rules = [
+ ({
+ 'reclassify_patterns': [('C', u'abc',
u'xyz')]
+ }, [], config.ALL_HOSTS, config.ALL_SERVICES),
+ ({
+ 'reclassify_patterns': [('C', u'abc',
u'xyz'), ('C', u'heute', u'heute')]
+ }, [], ['~non-existent-.*$'], config.ALL_SERVICES),
+ ({
+ 'reclassify_patterns': [('C', u'nene', u'')]
+ }, [], ['nene'], config.ALL_SERVICES),
+ ]
+
+ expected_settings = [
+ ({
+ 'reclassify_patterns': [('C', u'abc',
u'xyz')]
+ }, ['']),
+ ({
+ 'reclassify_patterns': [('C', u'abc',
u'xyz'), ('C', u'heute', u'heute')]
+ }, ['']),
+ ]
+
+ assert
check.context["_precompile_ec_logwatch_settings"]("non-existent-testhost",
{},
+ rules) == expected_settings