def _get_clustered_services( config_cache: config.ConfigCache, host_config: config.HostConfig, skip_autochecks: bool, ) -> Iterable[Service]: for node in host_config.nodes or []: # TODO: Cleanup this to work exactly like the logic above (for a single host) # (mo): in particular: this means that autochecks will win over static checks. # for a single host the static ones win. node_config = config_cache.get_host_config(node) node_checks = list(_get_static_check_entries(node_config)) if not (skip_autochecks or host_config.is_ping_host): node_checks += config_cache.get_autochecks_of(node) for service in node_checks: services_host = config_cache.host_of_clustered_service( node, service.description) if services_host != host_config.hostname: continue cluster_params = config.compute_check_parameters( host_config.hostname, service.check_plugin_name, service.item, service.parameters, ) yield Service( service.check_plugin_name, service.item, service.description, cluster_params, service.service_labels, )
def _aggregate_check_table_services( *, config_cache: config.ConfigCache, host_config: config.HostConfig, skip_autochecks: bool, skip_ignored: bool, filter_mode: FilterMode, ) -> Iterable[Service]: sfilter = _ServiceFilter( config_cache=config_cache, host_config=host_config, mode=filter_mode, skip_ignored=skip_ignored, ) # process all entries that are specific to the host # in search (single host) or that might match the host. if not (skip_autochecks or host_config.is_ping_host): yield from ( s for s in config_cache.get_autochecks_of(host_config.hostname) if sfilter.keep(s)) yield from (s for s in _get_static_check_entries(host_config) if sfilter.keep(s)) # Now add checks a cluster might receive from its nodes if host_config.is_cluster: yield from (s for s in _get_clustered_services( config_cache, host_config, skip_autochecks) if sfilter.keep(s))
def _get_clustered_services( self, config_cache: config.ConfigCache, host_config: config.HostConfig, hostname: str, skip_autochecks: bool, ) -> Iterable[Service]: for node in host_config.nodes or []: # TODO: Cleanup this to work exactly like the logic above (for a single host) node_config = config_cache.get_host_config(node) node_checks = list(self._get_static_check_entries(node_config)) if not skip_autochecks: node_checks += config_cache.get_autochecks_of(node) for service in node_checks: if config_cache.host_of_clustered_service( node, service.description) != hostname: continue cluster_params = config.compute_check_parameters( hostname, service.check_plugin_name, service.item, service.parameters, ) yield Service( service.check_plugin_name, service.item, service.description, cluster_params, service.service_labels, )
def _get_clustered_services( config_cache: config.ConfigCache, host_config: config.HostConfig, skip_autochecks: bool, ) -> Iterable[Service]: for node in host_config.nodes or []: # TODO: Cleanup this to work exactly like the logic above (for a single host) # (mo): in particular: this means that autochecks will win over static checks. # for a single host the static ones win. node_config = config_cache.get_host_config(node) node_checks = list(_get_static_check_entries(config_cache, node_config)) if not (skip_autochecks or host_config.is_ping_host): node_checks += config_cache.get_autochecks_of(node) yield from (service for service in node_checks if config_cache.host_of_clustered_service( node, service.description) == host_config.hostname)
def __init__( self, config_cache: config.ConfigCache, host_config: config.HostConfig, skip_autochecks: bool, filter_mode: Optional[Literal["only_clustered", "include_clustered"]], skip_ignored: bool, ) -> None: """Returns check table for a specific host Format of check table is: {(checkname, item): (params, description)} filter_mode: None -> default, returns only checks for this host filter_mode: "only_clustered" -> returns only checks belonging to clusters filter_mode: "include_clustered" -> returns checks of own host, including clustered checks """ hostname = host_config.hostname # Now process all entries that are specific to the host # in search (single host) or that might match the host. if not skip_autochecks: self.update({ service.id(): service for service in config_cache.get_autochecks_of(hostname) if self._keep_service(config_cache, host_config, service, filter_mode, skip_ignored) }) self.update({ service.id(): service for service in self._get_static_check_entries(host_config) if self._keep_service(config_cache, host_config, service, filter_mode, skip_ignored) }) # Now add checks a cluster might receive from its nodes if host_config.is_cluster: self.update({ service.id(): service for service in self._get_clustered_services( config_cache, host_config, hostname, skip_autochecks) if self._keep_service(config_cache, host_config, service, filter_mode, skip_ignored) })
def test_manager_get_autochecks_of( test_config: config.ConfigCache, autochecks_content: str, expected_result: Sequence[discovery.Service], ) -> None: autochecks_file = Path(cmk.utils.paths.autochecks_dir, "host.mk") with autochecks_file.open("w", encoding="utf-8") as f: f.write(autochecks_content) manager = test_config._autochecks_manager result = manager.get_autochecks_of( HostName("host"), config.compute_check_parameters, config.service_description, lambda hostname, _desc: hostname, ) assert result == expected_result # Check that the ConfigCache method also returns the correct data assert test_config.get_autochecks_of(HostName("host")) == result
def test_manager_get_autochecks_of( test_config: config.ConfigCache, autochecks_content: str, expected_result: Sequence[ConfiguredService], ) -> None: autochecks_file = Path(cmk.utils.paths.autochecks_dir, "host.mk") with autochecks_file.open("w", encoding="utf-8") as f: f.write(autochecks_content) manager = test_config._autochecks_manager result = manager.get_autochecks_of( HostName("host"), lambda *a: _COMPUTED_PARAMETERS_SENTINEL, lambda _host, check, item: f"{check}-{item}", lambda hostname, _desc: hostname, ) assert result == expected_result # see that compute_check_parameters has been called: assert result[0].parameters is _COMPUTED_PARAMETERS_SENTINEL # Check that the ConfigCache method also returns the correct data assert test_config.get_autochecks_of(HostName("host")) == result