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 _get_static_check_entries( config_cache: config.ConfigCache, host_config: config.HostConfig, ) -> Iterator[Service]: entries: List[Service] = [] for _checkgroup_name, check_plugin_name_str, item, params in host_config.static_checks: # TODO (mo): centralize maincheckify: CMK-4295 # in this case: move it to the transform of the static services rule. check_plugin_name = CheckPluginName(maincheckify(check_plugin_name_str)) descr = config.service_description(host_config.hostname, check_plugin_name, item) new_parameters = config.compute_check_parameters( config_cache.host_of_clustered_service(host_config.hostname, descr), check_plugin_name, item, {}, configured_parameters=TimespecificParameters((params,)), ) entries.append(Service(check_plugin_name, item, descr, new_parameters)) # Note: We need to reverse the order of the static_checks. This is # because users assume that earlier rules have precedence over later # ones. For static checks that is important if there are two rules for # a host with the same combination of check type and item. return reversed(entries)
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_static_check_entries( config_cache: config.ConfigCache, host_config: config.HostConfig, ) -> Iterator[ConfiguredService]: entries = [] for _checkgroup_name, check_plugin_name, item, params in host_config.static_checks: descr = config.service_description(host_config.hostname, check_plugin_name, item) entries.append( ConfiguredService( check_plugin_name=check_plugin_name, item=item, description=descr, parameters=config.compute_check_parameters( config_cache.host_of_clustered_service(host_config.hostname, descr), check_plugin_name, item, {}, configured_parameters=TimespecificParameters((params,)), ), discovered_parameters=None, service_labels={}, ) ) # Note: We need to reverse the order of the static_checks. This is # because users assume that earlier rules have precedence over later # ones. For static checks that is important if there are two rules for # a host with the same combination of check type and item. return reversed(entries)
def _keep_service( config_cache: config.ConfigCache, host_config: config.HostConfig, service: Service, filter_mode: Optional[Literal["only_clustered", "include_clustered"]], skip_ignored: bool, ) -> bool: hostname = host_config.hostname # drop unknown plugins: if agent_based_register.get_check_plugin(service.check_plugin_name) is None: return False if skip_ignored and config.service_ignored(hostname, service.check_plugin_name, service.description): return False if filter_mode == "include_clustered": return True if not host_config.part_of_clusters: return filter_mode != "only_clustered" host_of_service = config_cache.host_of_clustered_service( hostname, service.description, part_of_clusters=host_config.part_of_clusters, ) svc_is_mine = (hostname == host_of_service) if filter_mode is None: return svc_is_mine # filter_mode == "only_clustered" return not svc_is_mine
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)