Ejemplo n.º 1
0
    def _get_raw_section_names_to_process(self):
        # type: () -> Set[CheckPluginName]
        """Return a set of raw section names that shall be processed"""
        # TODO (mo): Make this (and the called) function(s) return the sections directly!
        if self._selected_raw_section_names is not None:
            return {str(n) for n in self._selected_raw_section_names}

        # TODO (mo): At the moment, we must also consider the legacy version:
        if self._enforced_check_plugin_names is not None:
            # TODO (mo): centralize maincheckify: CMK-4295
            return {maincheckify(n) for n in self._enforced_check_plugin_names}

        return self._detector(
            self._snmp_config,
            on_error=self._on_error,
            do_snmp_scan=self._do_snmp_scan,
            for_mgmt_board=self.source_type is SourceType.MANAGEMENT,
        )
Ejemplo n.º 2
0
def execute_check(multi_host_sections, host_config, ipaddress, service):
    # type: (data_sources.MultiHostSections, config.HostConfig, Optional[HostAddress], Service) -> bool
    # TODO (mo): centralize maincheckify: CMK-4295
    plugin_name = PluginName(maincheckify(service.check_plugin_name))
    plugin = config.registered_check_plugins.get(plugin_name)
    # check if we must use legacy mode. remove this block entirely one day
    if (plugin is not None and host_config.is_cluster
            and plugin.cluster_check_function.__name__
            == CLUSTER_LEGACY_MODE_FROM_HELL):
        return _execute_check_legacy_mode(
            multi_host_sections,
            host_config.hostname,
            ipaddress,
            service,
        )

    submit, data_received, result = _get_aggregated_result(
        multi_host_sections,
        host_config,
        ipaddress,
        service,
    )

    if submit:
        _submit_check_result(
            host_config.hostname,
            service.description,
            result,
            multi_host_sections.get_cache_info(plugin.sections)
            if plugin else None,
        )
    elif data_received:
        console.verbose("%-20s PEND - %s\n", ensure_str(service.description),
                        result[1])

    return data_received
Ejemplo n.º 3
0
def _get_aggregated_result(
    multi_host_sections: data_sources.MultiHostSections,
    host_config: config.HostConfig,
    ipaddress: Optional[HostAddress],
    service: Service,
) -> Tuple[bool, bool, ServiceCheckResult]:
    # TODO (mo): centralize maincheckify: CMK-4295
    plugin_name = PluginName(maincheckify(service.check_plugin_name))
    plugin = config.registered_check_plugins.get(plugin_name)
    if plugin is None:
        return False, True, CHECK_NOT_IMPLEMENTED

    check_function = (plugin.cluster_check_function
                      if host_config.is_cluster else plugin.check_function)

    source_type = (SourceType.MANAGEMENT
                   if service.check_plugin_name.startswith('mgmt_') else
                   SourceType.HOST)
    kwargs = None
    try:
        kwargs = multi_host_sections.get_section_cluster_kwargs(
            host_config.hostname,
            source_type,
            plugin.sections,
            service.description,
        ) if host_config.is_cluster else multi_host_sections.get_section_kwargs(
            (host_config.hostname, ipaddress, source_type),
            plugin.sections,
        )

        if not kwargs:
            return False, False, RECEIVED_NO_DATA

        if service.item is not None:
            kwargs["item"] = service.item
        if plugin.check_ruleset_name:
            kwargs["params"] = determine_check_params(service.parameters)

        with value_store.context(plugin.name, service.item):
            result = _aggregate_results(check_function(**kwargs))

    except (item_state.MKCounterWrapped,
            checking_types.IgnoreResultsError) as e:
        msg = str(e) or "No service summary available"
        return False, True, (0, msg, [])

    except MKTimeout:
        raise

    except Exception:
        if cmk.utils.debug.enabled():
            raise
        return True, True, (
            3,
            cmk.base.crash_reporting.create_check_crash_dump(
                host_config.hostname, service.check_plugin_name, service.item,
                is_manual_check(host_config.hostname,
                                service.check_plugin_name, service.item),
                service.parameters, service.description, kwargs),
            [],
        )

    return True, True, result
Ejemplo n.º 4
0
def execute_check(multi_host_sections, host_config, ipaddress, service):
    # type: (data_sources.MultiHostSections, config.HostConfig, Optional[HostAddress], Service) -> bool
    # TODO (mo): centralize maincheckify: CMK-4295
    plugin_name = PluginName(maincheckify(service.check_plugin_name))
    plugin = config.registered_check_plugins.get(plugin_name)
    if plugin is None:
        _submit_check_result(host_config.hostname, service.description, CHECK_NOT_IMPLEMENTED, None)
        return True

    check_function = (plugin.cluster_check_function
                      if host_config.is_cluster else plugin.check_function)

    if check_function.__name__ == CLUSTER_LEGACY_MODE_FROM_HELL:
        return _execute_check_legacy_mode(multi_host_sections, host_config.hostname, ipaddress,
                                          service)

    kwargs = None
    try:
        kwargs = multi_host_sections.get_section_cluster_kwargs(
            host_config.hostname,
            plugin.sections,
            service.description,
        ) if host_config.is_cluster else multi_host_sections.get_section_kwargs(
            host_config.hostname,
            ipaddress,
            plugin.sections,
        )

        if not kwargs:
            return False

        if service.item is not None:
            kwargs["item"] = service.item
        if plugin.check_ruleset_name:
            kwargs["params"] = determine_check_params(service.parameters)

        with value_store.context(plugin.name, service.item):
            result = _aggregate_results(check_function(**kwargs))

    except (item_state.MKCounterWrapped, checking_types.IgnoreResultsError) as e:
        msg = str(e) or "No service summary available"
        # Do not submit any check result in this case.
        console.verbose("%-20s PEND - %s\n", six.ensure_str(service.description), msg)
        return True

    except MKTimeout:
        raise

    except Exception:
        if cmk.utils.debug.enabled():
            raise
        result = 3, cmk.base.crash_reporting.create_check_crash_dump(
            host_config.hostname, service.check_plugin_name, service.item,
            is_manual_check(host_config.hostname, service.check_plugin_name, service.item),
            service.parameters, service.description, kwargs), []

    _submit_check_result(
        host_config.hostname,
        service.description,
        result,
        multi_host_sections.get_cache_info(plugin.sections),
    )
    return True