def _get_static_check_entries(self, host_config): # type: (config.HostConfig) -> Iterator[Service] entries = [] # type: List[Service] for _checkgroup_name, check_plugin_name, item, params in host_config.static_checks: if config.has_timespecific_params(params): timespec_params = [params] params = {} else: timespec_params = [] new_params = config.compute_check_parameters( host_config.hostname, check_plugin_name, item, params) if timespec_params: params = config.set_timespecific_param_list( timespec_params, new_params) else: params = new_params descr = config.service_description(host_config.hostname, check_plugin_name, item) entries.append(Service(check_plugin_name, item, descr, params)) # 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 _preview_params( host_name: HostName, service: Service, plugin: Optional[checking_classes.CheckPlugin], check_source: str, ) -> Optional[LegacyCheckParameters]: params: Optional[LegacyCheckParameters] = None if check_source not in ['legacy', 'active', 'custom']: if plugin is None: return params params = service.parameters if check_source != 'manual': params = config.compute_check_parameters( host_name, service.check_plugin_name, service.item, params, ) if check_source == "active": params = service.parameters if isinstance(params, config.TimespecificParamList): params = { "tp_computed_params": { "params": checking.time_resolved_check_parameters(params), "computed_at": time.time(), } } return params
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( 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_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 _get_static_check_entries(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 check_plugin_name = CheckPluginName(maincheckify(check_plugin_name_str)) if config.has_timespecific_params(params): timespec_params = [params] params = {} else: timespec_params = [] new_params = config.compute_check_parameters( host_config.hostname, check_plugin_name, item, params, for_static_checks=True, ) if timespec_params: params = config.set_timespecific_param_list(timespec_params, new_params) else: params = new_params descr = config.service_description(host_config.hostname, check_plugin_name, item) entries.append(Service(check_plugin_name, item, descr, params)) # 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, hostname: str, skip_autochecks: bool) -> CheckTable: check_table: CheckTable = {} for node in self._host_config.nodes or []: # TODO: Cleanup this to work exactly like the logic above (for a single host) node_config = self._config_cache.get_host_config(node) node_checks = list(self._get_static_check_entries(node_config)) if not skip_autochecks: node_checks += self._config_cache.get_autochecks_of(node) for service in node_checks: if self._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, ) cluster_service = Service( service.check_plugin_name, service.item, service.description, cluster_params, service.service_labels, ) check_table.update(self._handle_service(cluster_service)) return check_table
def _get_autochecks_of_uncached(self, hostname): # type: (HostName) -> List[Service] """Read automatically discovered checks of one host""" return [ Service( check_plugin_name=service.check_plugin_name, item=service.item, description=service.description, parameters=config.compute_check_parameters( hostname, service.check_plugin_name, service.item, service.parameters), service_labels=service.service_labels, ) for service in self._read_raw_autochecks(hostname) ]
def _preview_params( host_name: HostName, service: Service, plugin: Optional[checking_classes.CheckPlugin], check_source: _ServiceOrigin, ) -> Optional[LegacyCheckParameters]: if check_source in {"active", "manual", "custom"}: return service.parameters return config.compute_check_parameters( host_name, service.check_plugin_name, service.item, service.parameters, )
def _read_autochecks_of(self, hostname): # type: (str) -> List[Service] """Read automatically discovered checks of one host""" autochecks = [] for service in self._read_raw_autochecks_cached(hostname): autochecks.append( Service( check_plugin_name=service.check_plugin_name, item=service.item, description=service.description, parameters=config.compute_check_parameters( hostname, service.check_plugin_name, service.item, service.parameters), service_labels=service.service_labels, )) return autochecks