示例#1
0
def translate_service_description(translation: TranslationOptions,
                                  service_description: ServiceName) -> ServiceName:
    if service_description.strip() in \
        ["Check_MK", "Check_MK Agent",
         "Check_MK Discovery", "Check_MK inventory",
         "Check_MK HW/SW Inventory"]:
        return service_description.strip()
    return _translate(translation, service_description)
示例#2
0
def test_ruleset_matcher_get_service_ruleset_values_labels(
    monkeypatch: MonkeyPatch,
    hostname: HostName,
    service_description: str,
    expected_result: Sequence[str],
) -> None:
    ts = Scenario()

    ts.add_host(HostName("host1"))
    ts.set_autochecks(
        HostName("host1"),
        [
            Service(
                CheckPluginName("cpu_load"),
                None,
                "CPU load",
                "{}",
                service_labels={
                    "os": ServiceLabel("os", "linux"),
                    "abc": ServiceLabel("abc", "xä"),
                    "hu": ServiceLabel("hu", "ha"),
                },
            )
        ],
    )

    ts.add_host(HostName("host2"))
    ts.set_autochecks(
        HostName("host2"),
        [
            Service(
                CheckPluginName("cpu_load"),
                None,
                "CPU load",
                "{}",
                service_labels={},
            ),
        ],
    )

    config_cache = ts.apply(monkeypatch)
    matcher = config_cache.ruleset_matcher

    assert (
        list(
            matcher.get_service_ruleset_values(
                config_cache.ruleset_match_object_of_service(
                    hostname, ServiceName(service_description)
                ),
                ruleset=service_label_ruleset,
                is_binary=False,
            )
        )
        == expected_result
    )