def get_cluster_attributes(config_cache: config.ConfigCache, host_config: config.HostConfig, nodes: List[str]) -> Dict: sorted_nodes = sorted(nodes) attrs = { "_NODENAMES": " ".join(sorted_nodes), } node_ips_4 = [] if host_config.is_ipv4_host: family = socket.AF_INET for h in sorted_nodes: node_config = config_cache.get_host_config(h) addr = ip_address_of(node_config, family) if addr is not None: node_ips_4.append(addr) else: node_ips_4.append(ip_lookup.fallback_ip_for(family)) node_ips_6 = [] if host_config.is_ipv6_host: family = socket.AF_INET6 for h in sorted_nodes: node_config = config_cache.get_host_config(h) addr = ip_address_of(node_config, family) if addr is not None: node_ips_6.append(addr) else: node_ips_6.append(ip_lookup.fallback_ip_for(family)) node_ips = node_ips_6 if host_config.is_ipv6_primary else node_ips_4 for suffix, val in [("", node_ips), ("_4", node_ips_4), ("_6", node_ips_6)]: attrs["_NODEIPS%s" % suffix] = " ".join(val) return attrs
def _ip_address_for_dump_host( host_config: config.HostConfig, *, family: socket.AddressFamily, ) -> Optional[str]: try: return config.lookup_ip_address(host_config, family=family) except Exception: return "" if host_config.is_cluster else ip_lookup.fallback_ip_for(family)
def ip_address_of(host_config: config.HostConfig, family: socket.AddressFamily) -> Optional[str]: try: return config.lookup_ip_address(host_config, family=family) except Exception as e: if host_config.is_cluster: return "" _failed_ip_lookups.append(host_config.hostname) if not _ignore_ip_lookup_failures: warning("Cannot lookup IP address of '%s' (%s). " "The host will not be monitored correctly." % (host_config.hostname, e)) return ip_lookup.fallback_ip_for(family)
def __init__( self, host_config: HostConfig, ipaddress: Optional[HostAddress], *, selected_sections: SectionNameCollection, on_scan_error: OnError, force_snmp_cache_refresh: bool, ) -> None: super().__init__() self.host_config: Final = host_config self.ipaddress: Final = ipaddress self.selected_sections: Final = selected_sections self.on_scan_error: Final = on_scan_error self.force_snmp_cache_refresh: Final = force_snmp_cache_refresh self._fallback_ip: Final = ip_lookup.fallback_ip_for( self.host_config.default_address_family) self._elems: Dict[str, Source] = {} self._initialize()
def __init__( self, host_config: HostConfig, ipaddress: Optional[HostAddress], *, mode: Mode, selected_sections: SectionNameCollection, on_scan_error: str, ) -> None: super().__init__() self._host_config = host_config self._hostname = host_config.hostname self._ipaddress = ipaddress self._fallback_ip = ip_lookup.fallback_ip_for(self._host_config.default_address_family) self._mode = mode self._selected_sections = selected_sections self._on_scan_error = on_scan_error self._elems: Dict[str, Source] = {} self._initialize()