Beispiel #1
0
def _extract_snmp_sections():
    # type: () -> None
    for plugin_name, plugin_info in sorted(inv_info.items()):
        if 'snmp_info' not in plugin_info:
            continue
        section_name = section_name_of(plugin_name)
        if config.get_registered_section_plugin(PluginName(section_name)):
            continue

        fallback_files = (
            [_include_file_path(i) for i in plugin_info.get('includes', [])] +
            [_plugin_file_lookup[plugin_name]])

        try:
            snmp_section_plugin = create_snmp_section_plugin_from_legacy(
                section_name,
                {},
                plugin_info['snmp_scan_function'],
                plugin_info['snmp_info'],
                scan_function_fallback_files=fallback_files,
            )
        except (NotImplementedError, KeyError, AssertionError, ValueError):
            msg = config.AUTO_MIGRATION_ERR_MSG % ('section', plugin_name)
            if cmk.utils.debug.enabled():
                raise MKGeneralException(msg)
            # TODO (mo): bring this back:
            #console.warning(msg)
        else:
            config.registered_snmp_sections[
                snmp_section_plugin.name] = snmp_section_plugin
Beispiel #2
0
    def get_check_plugin_candidates(self):
        # type: () -> Set[PluginName]
        """Return names of check plugins that this multi_host_section may contain data for.

        Given this mutli_host_section, there is no point in trying to discover any check plugins
        not returned by this function.
        This does not address the question wether or not the returned check plugins will discover
        something.
        """
        raw_section_names = {
            PluginName(name)
            for node_data in self._multi_host_sections.values()
            for name in node_data.sections
        }

        raw_sections = [(name, config.get_registered_section_plugin(name))
                        for name in raw_section_names]

        parsed_section_names = {
            name if section is None else section.parsed_section_name
            for name, section in raw_sections
        }

        return {
            plugin.name
            for plugin in config.registered_check_plugins.values() if any(
                section in parsed_section_names for section in plugin.sections)
        }
Beispiel #3
0
    def _update_with_parse_function(
        section_content: AbstractSectionContent,
        section_name: SectionName,
    ) -> ParsedSectionContent:
        """Transform the section_content using the defined parse functions.

        Some checks define a parse function that is used to transform the section_content
        somehow. It is applied by this function.

        Please note that this is not a check/subcheck individual setting. This option is related
        to the agent section.

        All exceptions raised by the parse function will be catched and re-raised as
        MKParseFunctionError() exceptions."""
        section_plugin = config.get_registered_section_plugin(section_name)
        if section_plugin is None:
            # use legacy parse function for unmigrated sections
            parse_function = config.check_info.get(str(section_name),
                                                   {}).get("parse_function")
            if parse_function is None:
                return section_content
        else:
            # TODO (mo): deal with the parsed_section_name feature (CMK-4006)
            if str(section_plugin.name) != str(
                    section_plugin.parsed_section_name):
                raise NotImplementedError()
            parse_function = section_plugin.parse_function

        # TODO (mo): make this unnecessary
        parse_function = cast(
            Callable[[AbstractSectionContent], ParsedSectionContent],
            parse_function)

        # TODO: Item state needs to be handled in local objects instead of the
        # item_state._cached_item_states object
        # TODO (mo): ValueStores (formally Item state) need to be *only* available
        # from within the check function, nowhere else.
        orig_item_state_prefix = item_state.get_item_state_prefix()
        try:
            item_state.set_item_state_prefix(section_name, None)
            return parse_function(section_content)

        except item_state.MKCounterWrapped:
            raise

        except Exception:
            if cmk.utils.debug.enabled():
                raise
            raise MKParseFunctionError(*sys.exc_info())

        finally:
            item_state.set_item_state_prefix(*orig_item_state_prefix)
Beispiel #4
0
def _make_piggybacked_sections(host_config) -> SelectedRawSections:
    check_plugin_names = set(
        itertools.chain.from_iterable(
            check_table.get_needed_check_names(
                node_name,
                remove_duplicates=True,
                filter_mode="only_clustered",
            ) for node_name in host_config.nodes))
    selected_raw_sections = {}
    for name in config.get_relevant_raw_sections(check_plugin_names=check_plugin_names):
        section = config.get_registered_section_plugin(name)
        if section is not None:
            selected_raw_sections[name] = section
    return selected_raw_sections