Skip to content

Commit

Permalink
7487 FIX mk_logwatch: Consider 'Do not deploy' in bakery
Browse files Browse the repository at this point in the history
When setting up a logwatch rule in the agent bakery, you can choose 'Do not deploy the Logwatch plugin'.
This option has not been effective so far.

Now, when creating the logwatch sections, all configured sections in the hierarchy used, until a 'Do not deploy the Logwatch plugin' or 'Deploy the Logwatch plugin without configuration' rule is met, at which point all sections defined upwards in the folder hierarchy are ignored.

This also fixes FEED-3726

Change-Id: I3bf59655d5666a5f261104c891bba79184d33521
  • Loading branch information
mo-ki committed Jun 17, 2019
1 parent 554082d commit 65dbc67
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
13 changes: 13 additions & 0 deletions .werks/7487
@@ -0,0 +1,13 @@
Title: mk_logwatch: Consider 'Do not deploy' in bakery
Level: 1
Component: checks
Compatible: incomp
Edition: cre
Version: 1.6.0b2
Date: 1560507086
Class: fix

When setting up a logwatch rule in the agent bakery, you can choose 'Do not deploy the Logwatch plugin'.
This option has not been effective so far.

Now, when creating the logwatch sections, all configured sections in the hierarchy used, until a 'Do not deploy the Logwatch plugin' or 'Deploy the Logwatch plugin without configuration' rule is met, at which point all sections defined upwards in the folder hierarchy are ignored.
55 changes: 39 additions & 16 deletions tests/unit/agents/plugins/test_mk_logwatch_bakery.py
@@ -1,23 +1,46 @@
# pylint: disable=redefined-outer-name,protected-access
import imp
import importlib
import os
import sys

import pytest

from testlib import cmk_path, repo_path
from testlib import cmk_path

DICT1 = {'id': 1}

def test_get_logfiles_config_lines():
# Workaround to make bakelet available in the test, needs to be executed in the test scope.
bakelet = 'mk_logwatch'
path = os.path.join(cmk_path(), 'enterprise', 'agents', 'bakery', bakelet)
with open(path, "r") as f:
source = f.read()
DICT2 = {'id': 1}


@pytest.fixture(scope="module")
def bakelet(request):
"""
Fixture to inject bakelet as module
"""
path = os.path.join(cmk_path(), 'enterprise', 'agents', 'bakery', 'mk_logwatch')
with open(path, "r") as handle:
source = handle.read()
extended_source = 'from cmk_base.cee.agent_bakery_plugins import bakery_info' + '\n' + source
exec (extended_source)

config = [
bakelet = imp.new_module('bakelet')
exec extended_source in bakelet.__dict__
yield bakelet


@pytest.mark.parametrize('configs, applicable', [
([], (False, [])),
([True, DICT1], (True, [])),
([None, DICT1], (False, [])),
([DICT1, True], (True, [DICT1])),
([DICT1, None, DICT2], (True, [DICT1])),
([DICT1, True, DICT2], (True, [DICT1])),
([DICT1, DICT2], (True, [DICT1, DICT2])),
])
def test_get_applicable_configs(bakelet, configs, applicable):
assert applicable == bakelet._get_applicable_rule_values(configs)


@pytest.mark.parametrize('config, expected', [
([
{
'context': True,
'logfiles': ['/var/log/*.log', '/omd/sites/*/var/log/*.log'],
Expand All @@ -44,10 +67,7 @@ def test_get_logfiles_config_lines():
},
]
},
]

actual_result = _get_logfiles_config_lines(config)
assert actual_result == [
], [
'',
'/var/log/*.log /omd/sites/*/var/log/*.log overflow=C',
' C foo',
Expand All @@ -66,4 +86,7 @@ def test_get_logfiles_config_lines():
' 192.168.1.2',
' 192.168.1.3',
' 192.168.1.4',
]
]),
])
def test_get_logfiles_config_lines(bakelet, config, expected):
assert bakelet._get_logfiles_config_lines(config) == expected

0 comments on commit 65dbc67

Please sign in to comment.