Exemple #1
0
    def _execute(
        self,
        *,
        selected_raw_sections: Optional[SelectedRawSections],
    ) -> RawAgentData:
        if self._use_only_cache:
            raise MKAgentError("Got no data: No usable cache file present at %s" %
                               self._cache_file_path())

        ip_lookup.verify_ipaddress(self.ipaddress)
        assert self.ipaddress

        with TCPDataFetcher(
                socket.AF_INET6 if self._host_config.is_ipv6_primary else socket.AF_INET,
            (self.ipaddress, self.port),
                self.timeout,
                self._host_config.agent_encryption,
        ) as fetcher:
            output = fetcher.data()
            if not output:  # may be caused by xinetd not allowing our address
                raise MKEmptyAgentData("Empty output from agent at %s:%d" %
                                       (self.ipaddress, self.port))
            if len(output) < 16:
                raise MKAgentError("Too short output from agent: %r" % output)
            return output
        raise MKAgentError("Failed to read data")
Exemple #2
0
 def _execute(self) -> SNMPRawData:
     ip_lookup.verify_ipaddress(self.ipaddress)
     with SNMPDataFetcher(
             self._make_oid_infos(),
             self._use_snmpwalk_cache,
             self._snmp_config,
     ) as fetcher:
         return fetcher.data()
     raise MKAgentError("Failed to read data")
Exemple #3
0
 def __init__(
     self,
     hostname: HostName,
     ipaddress: HostAddress,
     *,
     mode: Mode,
     source_type: SourceType,
     id_: str,
     cpu_tracking_id: str,
     cache_dir: Optional[Path] = None,
     persisted_section_dir: Optional[Path] = None,
     title: str,
     on_error: str = "raise",
     do_snmp_scan: bool = False,
 ):
     super().__init__(
         hostname,
         ipaddress,
         mode=mode,
         source_type=source_type,
         fetcher_type=FetcherType.SNMP,
         description=SNMPConfigurator._make_description(hostname,
                                                        ipaddress,
                                                        title=title),
         id_=id_,
         cpu_tracking_id=cpu_tracking_id,
         cache_dir=cache_dir,
         persisted_section_dir=persisted_section_dir,
     )
     if self.ipaddress is None:
         # snmp_config.ipaddress is not Optional.
         #
         # At least classic SNMP enforces that there is an address set,
         # Inline-SNMP has some lookup logic for some reason. We need
         # to find out whether or not we can really have None here.
         # Looks like it could be the case for cluster hosts which
         # don't have an IP address set.
         raise TypeError(self.ipaddress)
     ip_lookup.verify_ipaddress(self.ipaddress)
     self.snmp_config = (
         # Because of crap inheritance.
         self.host_config.snmp_config(self.ipaddress)
         if self.source_type is SourceType.HOST else
         self.host_config.management_snmp_config)
     self.on_snmp_scan_error = on_error
     self.do_snmp_scan = do_snmp_scan
     self.detector: Final = CachedSNMPDetector()
     # Attributes below are wrong
     self.use_snmpwalk_cache = True
     self.ignore_check_interval = False
     self.selected_raw_sections: Optional[SelectedRawSections] = None
     self.prefetched_sections: Sequence[SectionName] = ()
     self.section_store: SectionStore[SNMPPersistedSections] = SectionStore(
         self.persisted_sections_file_path,
         self._logger,
     )
Exemple #4
0
    def configure_fetcher(self):
        ip_lookup.verify_ipaddress(self.ipaddress)
        assert self.ipaddress

        return {
            "file_cache": self.file_cache.configure(),
            "family": socket.AF_INET6 if self.host_config.is_ipv6_primary else socket.AF_INET,
            "address": (self.ipaddress, self.port or self.host_config.agent_port),
            "timeout": self.timeout or self.host_config.tcp_connect_timeout,
            "encryption_settings": self.host_config.agent_encryption,
        }
Exemple #5
0
 def _execute(
     self,
     *,
     selected_raw_sections: Optional[SelectedRawSections],
 ) -> SNMPRawData:
     ip_lookup.verify_ipaddress(self.ipaddress)
     with SNMPDataFetcher(
             self._make_oid_infos(
                 selected_raw_sections=selected_raw_sections),
             self._use_snmpwalk_cache,
             self._snmp_config,
     ) as fetcher:
         return fetcher.data()
     raise MKAgentError("Failed to read data")