Beispiel #1
0
    def _extract_persisted_sections(
            self, raw_data: SNMPRawData) -> SNMPPersistedSections:
        """Extract the sections to be persisted from the raw_data and return it

        Gather the check types to be persisted, extract the related data from
        the raw data, calculate the times and store the persisted info for
        later use.
        """
        persisted_sections: SNMPPersistedSections = {}

        for section_name, section_content in raw_data.items():
            fetch_interval = self._host_config.snmp_fetch_interval(
                section_name)
            if fetch_interval is None:
                continue

            cached_at = int(time.time())
            until = cached_at + (fetch_interval * 60)
            persisted_sections[section_name] = (cached_at, until,
                                                section_content)

        return persisted_sections
Beispiel #2
0
    def _extract_persisted_sections(
        raw_data: SNMPRawData,
        host_config: config.HostConfig,
    ) -> PersistedSections[SNMPSectionContent]:
        """Extract the sections to be persisted from the raw_data and return it

        Gather the check types to be persisted, extract the related data from
        the raw data, calculate the times and store the persisted info for
        later use.
        """
        persisted_sections = PersistedSections[SNMPSectionContent]({})

        for section_name, section_content in raw_data.items():
            fetch_interval = host_config.snmp_fetch_interval(section_name)
            if fetch_interval is None:
                continue

            cached_at = int(time.time())
            until = cached_at + (fetch_interval * 60)
            # pylint does not seem to understand `NewType`... leave the checking up to mypy.
            persisted_sections[section_name] = (  # false positive: pylint: disable=E1137
                (cached_at, until, section_content))

        return persisted_sections
Beispiel #3
0
 def _to_cache_file(self, raw_data: SNMPRawData) -> bytes:
     return (repr({str(k): v
                   for k, v in raw_data.items()}) + "\n").encode("utf-8")
Beispiel #4
0
 def _serialize(value: SNMPRawData) -> bytes:
     return json.dumps({str(k): v for k, v in value.items()}).encode("utf8")