예제 #1
0
def test_ruleset_matcher_get_host_ruleset_values_tags_duplicate_ids(
    monkeypatch: MonkeyPatch,
    rule_spec: RuleSpec,
    expected_result: Sequence[RuleValue],
) -> None:
    ts = Scenario()
    add_tag_config = TagConfig()
    add_tag_config.parse_config({
        'aux_tags': [],
        'tag_groups': [
            {
                'id': 'grp1',
                'tags': [
                    {
                        'aux_tags': [],
                        'id': 'v1',
                        'title': 'Value1',
                    },
                ],
                'title': 'Group 1'
            },
            {
                'id': 'grp2',
                'tags': [
                    {
                        'aux_tags': [],
                        'id': 'v1',
                        'title': 'Value1',
                    },
                ],
                'title': 'Group 2'
            },
        ],
    })
    ts.tags += add_tag_config
    ts.add_host(
        "host",
        tags={
            "grp1": "v1",
        },
    )
    config_cache = ts.apply(monkeypatch)
    matcher = config_cache.ruleset_matcher

    assert list(
        matcher.get_host_ruleset_values(
            RulesetMatchObject(
                host_name="host",
                service_description=None,
            ),
            ruleset=[rule_spec],
            is_binary=False,
        )) == expected_result
예제 #2
0
def test_ruleset_matcher_get_host_ruleset_values_tags_duplicate_ids(
    monkeypatch: MonkeyPatch,
    rule_spec: RuleConditionsSpec,
    expected_result: Sequence[RuleValue],
) -> None:
    ts = Scenario()
    add_tag_config = TagConfig()
    add_tag_config.parse_config({
        "aux_tags": [],
        "tag_groups": [
            {
                "id": "grp1",
                "tags": [
                    {
                        "aux_tags": [],
                        "id": "v1",
                        "title": "Value1",
                    },
                ],
                "title": "Group 1",
            },
            {
                "id": "grp2",
                "tags": [
                    {
                        "aux_tags": [],
                        "id": "v1",
                        "title": "Value1",
                    },
                ],
                "title": "Group 2",
            },
        ],
    })
    ts.tags += add_tag_config
    ts.add_host(
        "host",
        tags={
            "grp1": "v1",
        },
    )
    config_cache = ts.apply(monkeypatch)
    matcher = config_cache.ruleset_matcher

    assert (list(
        matcher.get_host_ruleset_values(
            RulesetMatchObject(
                host_name=HostName("host"),
                service_description=None,
            ),
            ruleset=[rule_spec],
            is_binary=False,
        )) == expected_result)
예제 #3
0
def fixture_tag_config():
    tag_config = TagConfig()
    tag_config.parse_config({
        "aux_tags": [{
            "id": "aux_tag_1",
            "topic": "Auxiliary tags",
            "title": "Auxiliary tag 1",
        }],
        "tag_groups": [
            {
                "id":
                "tag_grp_1",
                "topic":
                "Topic 1",
                "title":
                "Tag group 1",
                "tags": [
                    {
                        "aux_tags": [],
                        "id": "grp_1_tg_1",
                        "title": "Tag 1.1",
                    },
                    {
                        "aux_tags": [],
                        "id": "grp_1_tg_2",
                        "title": "Tag 1.2",
                    },
                ],
            },
            {
                "id":
                "tag_grp_2",
                "topic":
                "Topic 2",
                "title":
                "Tag group 2",
                "tags": [
                    {
                        "aux_tags": [],
                        "id": "grp_2_tg_1",
                        "title": "Tag 2.1",
                    },
                    {
                        "aux_tags": [],
                        "id": "grp_2_tg_2",
                        "title": "Tag 2.2",
                    },
                ],
            },
            {
                "id":
                "tag_grp_3",
                "topic":
                "Topic 3",
                "title":
                "Tag group 3",
                "tags": [
                    {
                        "aux_tags": [],
                        "id": "grp_3_tg_1",
                        "title": "Tag 3.1",
                    },
                ],
            },
        ],
    })
    return tag_config
예제 #4
0
 def _initialize_tag_config(self):
     tag_config = TagConfig()
     tag_config.parse_config(sample_tag_config())
     TagConfigFile().save(tag_config.get_dict_format())
     # Make sure the host tag attributes are immediately declared!
     config.tags = tag_config
예제 #5
0
 def _initialize_tag_config(self) -> None:
     tag_config = TagConfig()
     tag_config.parse_config(sample_tag_config())
     TagConfigFile().save(tag_config.get_dict_format())