def _perform_automatic_refresh(self, api_request): # TODO: In distributed sites this must not add a change on the remote site. We need to build # the way back to the central site and show the information there. discovery( api_request.host.site_id(), "refresh", ["@scan"], api_request.host.name(), non_blocking_http=True, )
def _execute_discovery(self, task, mode, do_scan, error_handling) -> AutomationDiscoveryResult: flags: MutableSequence[str] = [] if not error_handling: flags.append("@raiseerrors") if do_scan: flags.append("@scan") return discovery( task.site_id, mode, flags, task.host_names, timeout=request.request_timeout - 2, non_blocking_http=True, )
def _execute_discovery( self, task: DiscoveryTask, mode: DiscoveryMode, do_scan: DoFullScan, ignore_errors: IgnoreErrors, ) -> AutomationDiscoveryResult: flags: MutableSequence[str] = [] if not ignore_errors: flags.append("@raiseerrors") if do_scan: flags.append("@scan") return discovery( task.site_id, mode, flags, task.host_names, timeout=request.request_timeout - 2, non_blocking_http=True, )
def _discover_services(self, request): mode = request.get("mode", "new") hostname = request.get("hostname") check_hostname(hostname, should_exist=True) host = watolib.Host.load_host(hostname) host_attributes = host.effective_attributes() if host.is_cluster(): # This is currently the only way to get some actual discovery statitics. # Start a dry-run -> Get statistics # Do an actual discovery on the nodes -> data is written try_result = try_discovery( host_attributes.get("site"), ["@scan"], hostname, ) new = 0 old = 0 for entry in try_result.check_table: if entry[0] == "new": new += 1 elif entry[0] == "old": old += 1 result = DiscoveryResult(self_new=new, self_kept=old, self_total=new + old) discovery( host_attributes.get("site"), mode, ["@scan"], host.cluster_nodes(), ) else: result = discovery( host_attributes.get("site"), mode, ["@scan"], [hostname], non_blocking_http=True, ).hosts[hostname] if result.error_text: if not host.discovery_failed(): host.set_discovery_failed() raise MKUserError(None, _("Failed to discover %s: %s") % (hostname, result.error_text)) if host.discovery_failed(): host.clear_discovery_failed() if mode == "refresh": message = _("Refreshed check configuration of host [%s] with %d services") % ( hostname, result.self_total, ) watolib.add_service_change(host, "refresh-autochecks", message) else: message = _("Saved check configuration of host [%s] with %d services") % ( hostname, result.self_total, ) watolib.add_service_change(host, "set-autochecks", message) msg = _( "Service discovery successful. Added %d, removed %d, kept %d, total %d services " "and %d new, %d total host labels" ) % ( result.self_new, result.self_removed, result.self_kept, result.self_total, result.self_new_host_labels, result.self_total_host_labels, ) return msg