def get_check_preview( *, host_name: HostName, max_cachefile_age: int, use_cached_snmp_data: bool, on_error: OnError, ) -> Tuple[CheckPreviewTable, QualifiedDiscovery[HostLabel]]: """Get the list of service of a host or cluster and guess the current state of all services if possible""" config_cache = config.get_config_cache() host_config = config_cache.get_host_config(host_name) ip_address = None if host_config.is_cluster else config.lookup_ip_address(host_config) _set_cache_opts_of_checkers(use_cached_snmp_data=use_cached_snmp_data) parsed_sections_broker, _source_results = make_broker( config_cache=config_cache, host_config=host_config, ip_address=ip_address, mode=Mode.DISCOVERY, file_cache_max_age=max_cachefile_age, selected_sections=NO_SELECTION, fetcher_messages=(), force_snmp_cache_refresh=not use_cached_snmp_data, on_scan_error=on_error, ) host_labels = analyse_host_labels( host_config=host_config, ipaddress=ip_address, parsed_sections_broker=parsed_sections_broker, load_labels=True, save_labels=False, on_error=on_error, ) grouped_services = _get_host_services( host_config, ip_address, parsed_sections_broker, on_error, ) with load_host_value_store(host_name, store_changes=False) as value_store_manager: table = [ _check_preview_table_row( host_config=host_config, ip_address=ip_address, service=service, check_source=check_source, parsed_sections_broker=parsed_sections_broker, found_on_nodes=found_on_nodes, value_store_manager=value_store_manager, ) for check_source, services_with_nodes in grouped_services.items() for service, found_on_nodes in services_with_nodes ] return table, host_labels
def _consume_checkresult( self, node: str, result_generator: CheckResult, ) -> Sequence[Union[Result, Metric, IgnoreResults]]: with load_host_value_store( node, store_changes=self._persist_value_store_changes, ) as value_store_manager: with value_store_manager.namespace(self._service_id): try: return list(result_generator) except IgnoreResultsError as exc: return [IgnoreResults(str(exc))]
def check_host_services( *, config_cache: config.ConfigCache, host_config: config.HostConfig, ipaddress: Optional[HostAddress], parsed_sections_broker: ParsedSectionsBroker, services: Sequence[Service], run_plugin_names: Container[CheckPluginName], dry_run: bool, show_perfdata: bool, ) -> Tuple[int, List[CheckPluginName]]: """Compute service state results for all given services on node or cluster * Loops over all services, * calls the check * examines the result and sends it to the core (unless `dry_run` is True). """ num_success = 0 plugins_missing_data: Set[CheckPluginName] = set() with plugin_contexts.current_host(host_config.hostname): with value_store.load_host_value_store( host_config.hostname, store_changes=not dry_run) as value_store_manager: for service in _filter_services_to_check( services=services, run_plugin_names=run_plugin_names, config_cache=config_cache, host_name=host_config.hostname, ): success = _execute_check( parsed_sections_broker, host_config, ipaddress, service, dry_run=dry_run, show_perfdata=show_perfdata, value_store_manager=value_store_manager, ) if success: num_success += 1 else: plugins_missing_data.add(service.check_plugin_name) return num_success, sorted(plugins_missing_data)
def do_all_checks_on_host( *, config_cache: config.ConfigCache, host_config: config.HostConfig, ipaddress: Optional[HostAddress], parsed_sections_broker: ParsedSectionsBroker, services: Sequence[Service], run_plugin_names: Container[CheckPluginName], dry_run: bool, show_perfdata: bool, ) -> Tuple[int, List[CheckPluginName]]: num_success = 0 plugins_missing_data: Set[CheckPluginName] = set() with plugin_contexts.current_host(host_config.hostname): with value_store.load_host_value_store( host_config.hostname, store_changes=not dry_run) as value_store_manager: for service in _filter_services_to_check( services=services, run_plugin_names=run_plugin_names, config_cache=config_cache, host_name=host_config.hostname, ): success = _execute_check( parsed_sections_broker, host_config, ipaddress, service, dry_run=dry_run, show_perfdata=show_perfdata, value_store_manager=value_store_manager, ) if success: num_success += 1 else: plugins_missing_data.add(service.check_plugin_name) return num_success, sorted(plugins_missing_data)