Esempio n. 1
0
def test_transform_mixed_ruleset():
    ruleset = [
        ("VAL1", ["HOSTLIST1"]),
        {
            "value": "VAL",
            "condition": {
                "host_name": ["HOSTLIST"],
            },
        },
    ]

    ruleset_matcher.RulesetToDictTransformer(
        tag_to_group_map={}).transform_in_place(ruleset,
                                                is_binary=False,
                                                is_service=False)

    assert ruleset == [
        {
            "value": "VAL1",
            "condition": {
                "host_name": ["HOSTLIST1"],
            },
        },
        {
            "value": "VAL",
            "condition": {
                "host_name": ["HOSTLIST"],
            },
        },
    ]
Esempio n. 2
0
def test_transform_tuple_ruleset():
    ruleset: Union[List[Tuple[str, List[str]]], List[Dict[str, List[str]]]] = [
        ("VAL1", ["HOSTLIST1"]),
        ("VAL2", ["HOSTLIST2"]),
    ]

    ruleset_matcher.RulesetToDictTransformer(
        tag_to_group_map={}).transform_in_place(ruleset,
                                                is_binary=False,
                                                is_service=False)

    assert ruleset == [
        {
            "value": "VAL1",
            "condition": {
                "host_name": ["HOSTLIST1"],
            },
        },
        {
            "value": "VAL2",
            "condition": {
                "host_name": ["HOSTLIST2"],
            },
        },
    ]
Esempio n. 3
0
def test_transform_cluster_hosts():
    with pytest.raises(MKGeneralException, match="CLUSTER_HOSTS"):
        ruleset_matcher.RulesetToDictTransformer(
            tag_to_group_map={}).transform_in_place([
                ("VAL1", tuple_rulesets.CLUSTER_HOSTS),
            ],
                                                    is_binary=False,
                                                    is_service=False)
Esempio n. 4
0
    def __init__(self, name, tag_to_group_map):
        super(Ruleset, self).__init__()
        self.name = name
        self.rulespec = rulespec_registry[name]()
        # Holds list of the rules. Using the folder paths as keys.
        self._rules = {}

        # Temporary needed during search result processing
        self.search_matching_rules = []

        # Converts pre 1.6 tuple rulesets in place to 1.6+ format
        self.tuple_transformer = ruleset_matcher.RulesetToDictTransformer(
            tag_to_group_map=tag_to_group_map)
Esempio n. 5
0
    def __init__(self, name: RulesetName, tag_to_group_map: TagIDToTaggroupID) -> None:
        super(Ruleset, self).__init__()
        self.name = name
        self.tag_to_group_map = tag_to_group_map
        self.rulespec = rulespec_registry[name]

        # Holds list of the rules. Using the folder paths as keys.
        self._rules: Dict[FolderPath, List[Rule]] = {}
        self._rules_by_id: Dict[str, Rule] = {}

        # Temporary needed during search result processing
        self.search_matching_rules: List[Rule] = []

        # Converts pre 1.6 tuple rulesets in place to 1.6+ format
        self.tuple_transformer = ruleset_matcher.RulesetToDictTransformer(
            tag_to_group_map=tag_to_group_map)
Esempio n. 6
0
    ],
)
@pytest.mark.parametrize(
    "case",
    NON_BINARY_HOST_RULESET + BINARY_HOST_RULESET +
    NON_BINARY_SERVICE_RULESET + BINARY_SERVICE_RULESET,
    ids=_generate_id,
)
def test_transform(case, rule_options):
    rule_spec = case.old
    if rule_options is not None:
        rule_spec = rule_spec + (rule_options, )

    ruleset = [rule_spec]
    ruleset_matcher.RulesetToDictTransformer(
        tag_to_group_map=TAG_TO_GROUP_MAP).transform_in_place(
            ruleset, is_service=case.is_service, is_binary=case.is_binary)

    expected = case.new.copy()
    if rule_options is not None:
        expected["options"] = rule_options

    assert ruleset[0] == expected


def test_get_tag_to_group_map(monkeypatch):
    tag_config = cmk.utils.tags.TagConfig.from_config({
        "aux_tags": [{
            "id": "bla",
            "title": "bl\xfcb"
        }],