示例#1
0
def test_get_sorted_check_table_no_cmc(monkeypatch, service_list):
    monkeypatch.setattr(config, "is_cmc", lambda: False)
    monkeypatch.setattr(check_table, "get_check_table",
                        lambda *a, **kw: {s.id(): s
                                          for s in service_list})
    monkeypatch.setattr(
        config, "service_depends_on", lambda _hn, descr: {
            "description A": ["description C"],
            "description B": ["description D"],
            "description D": ["description A", "description F"],
        }.get(descr, []))

    # all arguments are ignored in test
    sorted_service_list = check_table.get_sorted_service_list(
        "",
        filter_mode=None,
        skip_ignored=True,
    )
    assert [s.description for s in sorted_service_list] == [
        "description C",  #
        "description E",  # no deps, alphabetical order
        "description F",  #
        "description A",
        "description D",
        "description B",
    ]
示例#2
0
def test_get_sorted_check_table_cmc(monkeypatch, service_list):
    monkeypatch.setattr(config, "is_cmc", lambda: True)
    monkeypatch.setattr(check_table, "get_check_table",
                        lambda *a, **kw: {s.id(): s
                                          for s in service_list})

    # all arguments are ignored in test
    sorted_service_list = check_table.get_sorted_service_list(
        "", True, None, True)
    assert sorted_service_list == sorted(service_list,
                                         key=lambda s: s.description)
示例#3
0
def _get_services_to_fetch(
    host_name: HostName,
    belongs_to_cluster: bool,
    config_cache: config.ConfigCache,
) -> List[Service]:
    """Gather list of services to fetch the sections for

    Please note that explicitly includes the services that are assigned to cluster nodes.  In SNMP
    clusters the nodes have to fetch the information for the checking phase of the clustered
    services.
    """
    services = check_table.get_sorted_service_list(
        host_name, filter_mode=check_table.FilterMode.INCLUDE_CLUSTERED)

    return [
        service for service in services if not service_outside_check_period(
            config_cache, host_name, service.description)
    ]
示例#4
0
def _get_services_to_fetch(
    host_name: HostName,
    belongs_to_cluster: bool,
    config_cache: config.ConfigCache,
) -> List[Service]:
    """Gather list of services to fetch the sections for

    Please note that explicitly includes the services that are assigned to cluster nodes.  In SNMP
    clusters the nodes have to fetch the information for the checking phase of the clustered
    services.
    """
    services = check_table.get_sorted_service_list(host_name, filter_mode="include_clustered")

    # When check types are specified via command line, enforce them. Otherwise accept all check
    # plugin names.
    return [
        service for service in services
        if not service_outside_check_period(config_cache, host_name, service.description)
    ]
示例#5
0
def test_get_sorted_check_table_cyclic(monkeypatch, service_list):
    monkeypatch.setattr(config, "is_cmc", lambda: False)
    monkeypatch.setattr(check_table, "get_check_table",
                        lambda *a, **kw: {s.id(): s
                                          for s in service_list})
    monkeypatch.setattr(
        config, "service_depends_on", lambda _hn, descr: {
            "description A": ["description B"],
            "description B": ["description D"],
            "description D": ["description A"],
        }.get(descr, []))

    with pytest.raises(
            MKGeneralException,
            match=re.escape(
                "Cyclic service dependency of host MyHost. Problematic are:"
                " 'description A' (plugin_A / item), 'description B' (plugin_B / item),"
                " 'description D' (plugin_D / item)")):
        _ = check_table.get_sorted_service_list("MyHost", True, None, True)
示例#6
0
def _get_filtered_services(
    host_name: HostName,
    belongs_to_cluster: bool,
    config_cache: config.ConfigCache,
    only_check_plugins: Optional[Set[CheckPluginName]] = None,
) -> List[Service]:

    services = check_table.get_sorted_service_list(
        host_name,
        remove_duplicates=True,
        filter_mode="include_clustered" if belongs_to_cluster else None,
    )

    # When check types are specified via command line, enforce them. Otherwise use the
    # list of checks defined by the check table.
    if only_check_plugins is None:
        only_check_plugins = {
            service.check_plugin_name
            for service in services
        }

    def _is_not_of_host(service):
        return host_name != config_cache.host_of_clustered_service(
            host_name, service.description)

    # Filter out check types which are not used on the node
    if belongs_to_cluster:
        removed_plugins = {
            plugin
            for plugin in only_check_plugins if all(
                _is_not_of_host(service) for service in services
                if service.check_plugin_name == plugin)
        }
        only_check_plugins -= removed_plugins

    return [
        service for service in services
        if (service.check_plugin_name in only_check_plugins
            and not (belongs_to_cluster and _is_not_of_host(service))
            and not service_outside_check_period(config_cache, host_name,
                                                 service.description))
    ]