Esempio n. 1
0
def _check_host_labels(
    host_labels: QualifiedDiscovery[HostLabel],
    params: config.DiscoveryCheckParameters,
) -> _DiscoverySubresult:
    return (
        int(params.get("severity_new_host_label", 1)),
        [f"{len(host_labels.new)} new host labels"],
        [],
        [],
        _get_rediscovery_mode(params) in ("new", "fixall", "refresh"),
    ) if host_labels.new else (
        0,
        ["no new host labels"],
        [],
        [],
        False,
    )
Esempio n. 2
0
def _check_service_lists(
    *,
    host_name: HostName,
    services_by_transition: ServicesByTransition,
    params: config.DiscoveryCheckParameters,
    service_filters: _ServiceFilters,
    discovery_mode: DiscoveryMode,
) -> Tuple[ActiveCheckResult, bool]:

    status = 0
    infotexts = []
    long_infotexts = []
    need_rediscovery = False

    for transition, title, params_key, default_state, service_filter in [
        ("new", "unmonitored", "severity_unmonitored",
         config.inventory_check_severity, service_filters.new),
        ("vanished", "vanished", "severity_vanished", 0,
         service_filters.vanished),
    ]:

        affected_check_plugin_names: Counter[CheckPluginName] = Counter()
        unfiltered = False

        for (discovered_service,
             _found_on_nodes) in services_by_transition.get(transition, []):
            affected_check_plugin_names[
                discovered_service.check_plugin_name] += 1

            if not unfiltered and service_filter(host_name,
                                                 discovered_service):
                unfiltered = True

            #TODO In service_filter:we use config.service_description(...)
            # in order to finalize service_description (translation, etc.).
            # Why do we use discovered_service.description here?
            long_infotexts.append(u"%s: %s: %s" %
                                  (title, discovered_service.check_plugin_name,
                                   discovered_service.description))

        if affected_check_plugin_names:
            info = ", ".join(
                ["%s:%d" % e for e in affected_check_plugin_names.items()])
            st = params.get(params_key, default_state)
            status = worst_service_state(status, st, default=0)
            infotexts.append(u"%d %s services (%s)%s" % (
                sum(affected_check_plugin_names.values()),
                title,
                info,
                state_markers[st],
            ))

            if (unfiltered and ((transition == "new" and discovery_mode in
                                 (DiscoveryMode.NEW, DiscoveryMode.FIXALL,
                                  DiscoveryMode.REFRESH)) or
                                (transition == "vanished" and discovery_mode in
                                 (DiscoveryMode.REMOVE, DiscoveryMode.FIXALL,
                                  DiscoveryMode.REFRESH)))):
                need_rediscovery = True
        else:
            infotexts.append(u"no %s services found" % title)

    for (discovered_service,
         _found_on_nodes) in services_by_transition.get("ignored", []):
        long_infotexts.append(u"ignored: %s: %s" %
                              (discovered_service.check_plugin_name,
                               discovered_service.description))

    return ActiveCheckResult(status, infotexts, long_infotexts,
                             []), need_rediscovery
Esempio n. 3
0
def _check_service_lists(
    host_name: HostName,
    services_by_transition: ServicesByTransition,
    params: config.DiscoveryCheckParameters,
) -> _DiscoverySubresult:

    status = 0
    infotexts = []
    long_infotexts = []
    perfdata: List[Tuple] = []
    need_rediscovery = False

    service_filters = _ServiceFilters.from_settings(
        _get_rediscovery_parameters(params))
    rediscovery_mode = _get_rediscovery_mode(params)

    for transition, title, params_key, default_state, service_filter in [
        ("new", "unmonitored", "severity_unmonitored",
         config.inventory_check_severity, service_filters.new),
        ("vanished", "vanished", "severity_vanished", 0,
         service_filters.vanished),
    ]:

        affected_check_plugin_names: Counter[CheckPluginName] = Counter()
        unfiltered = False

        for (discovered_service,
             _found_on_nodes) in services_by_transition.get(transition, []):
            affected_check_plugin_names[
                discovered_service.check_plugin_name] += 1

            if not unfiltered and service_filter(host_name,
                                                 discovered_service):
                unfiltered = True

            #TODO In service_filter:we use config.service_description(...)
            # in order to finalize service_description (translation, etc.).
            # Why do we use discovered_service.description here?
            long_infotexts.append(u"%s: %s: %s" %
                                  (title, discovered_service.check_plugin_name,
                                   discovered_service.description))

        if affected_check_plugin_names:
            info = ", ".join(
                ["%s:%d" % e for e in affected_check_plugin_names.items()])
            st = params.get(params_key, default_state)
            status = cmk.base.utils.worst_service_state(status, st)
            infotexts.append(u"%d %s services (%s)%s" % (
                sum(affected_check_plugin_names.values()),
                title,
                info,
                state_markers[st],
            ))

            if (unfiltered and
                ((transition == "new"
                  and rediscovery_mode in ("new", "fixall", "refresh")) or
                 (transition == "vanished"
                  and rediscovery_mode in ("remove", "fixall", "refresh")))):
                need_rediscovery = True
        else:
            infotexts.append(u"no %s services found" % title)

    for (discovered_service,
         _found_on_nodes) in services_by_transition.get("ignored", []):
        long_infotexts.append(u"ignored: %s: %s" %
                              (discovered_service.check_plugin_name,
                               discovered_service.description))

    return status, infotexts, long_infotexts, perfdata, need_rediscovery