コード例 #1
0
    def get_parsed_section(
            self,
            host_name,  # type: HostName
            ip_address,  # type: Optional[HostAddress]
            section_name,  # type: PluginName
    ):
        # type: (...) -> Optional[ParsedSectionContent]
        cache_key = (host_name, ip_address, section_name)
        if cache_key in self._parsed_renamed_sections:
            return self._parsed_renamed_sections[cache_key]

        try:
            hosts_raw_sections = self._multi_host_sections[(
                host_name, ip_address)].sections
        except KeyError:
            return self._parsed_renamed_sections.setdefault(cache_key, None)

        available_raw_sections = [PluginName(n) for n in hosts_raw_sections]
        section_def = config.get_parsed_section_creator(
            section_name, available_raw_sections)
        if section_def is None:
            # no section creating the desired one was found, assume a 'default' section:
            raw_section_name = section_name
            parse_function = parse_string_table  # type: Union[SNMPParseFunction, AgentParseFunction]
        else:
            raw_section_name = section_def.name
            parse_function = section_def.parse_function

        try:
            string_table = hosts_raw_sections[str(raw_section_name)]
        except KeyError:
            return self._parsed_renamed_sections.setdefault(cache_key, None)

        try:
            parsed = parse_function(string_table)
        except Exception:
            if cmk.utils.debug.enabled():
                raise
            raise MKParseFunctionError(*sys.exc_info())

        return self._parsed_renamed_sections.setdefault(cache_key, parsed)
コード例 #2
0
    def _get_raw_section(self, host_key, section_name):
        # type: (HostKey, PluginName) -> Union[AgentSectionPlugin, SNMPSectionPlugin]
        """Get the raw sections name that will be parsed into the required section

        Raw sections may get renamed once they are parsed, if they declare it. This function
        deals with the task of determining which section we need to parse, in order to end
        up with the desired parsed section.
        This depends on the available raw sections, and thus on the host.
        """
        cache_key = host_key + (section_name,)
        if cache_key in self._parsed_to_raw_map:
            return self._parsed_to_raw_map[cache_key]

        try:
            hosts_raw_sections = self._multi_host_sections[host_key].sections
        except KeyError:
            return self._parsed_to_raw_map.setdefault(cache_key, None)

        available_raw_sections = [PluginName(n) for n in hosts_raw_sections]
        section_def = config.get_parsed_section_creator(section_name, available_raw_sections)
        return self._parsed_to_raw_map.setdefault(cache_key, section_def)