def _process_discovery_result_for_host(self, host, result: DiscoveryResult) -> str: if result.error_text == "": self._num_hosts_skipped += 1 return _("discovery skipped: host not monitored") if result.error_text is not None: self._num_hosts_failed += 1 if not host.locked(): host.set_discovery_failed() return _("discovery failed: %s") % result.error_text self._num_hosts_succeeded += 1 add_service_change( host, "bulk-discovery", _("Did service discovery on host %s: %d added, %d removed, %d kept, " "%d total services and %d host labels added, %d host labels total" ) % (host.name(), result.self_new, result.self_removed, result.self_kept, result.self_total, result.self_new_host_labels, result.self_total_host_labels), diff_text=result.diff_text) if not host.locked(): host.clear_discovery_failed() return _("discovery successful")
def get_check_table( discovery_request: StartDiscoveryRequest) -> DiscoveryResult: """Gathers the check table using a background job Cares about handling local / remote sites using an automation call. In both cases the ServiceDiscoveryBackgroundJob is executed to care about collecting the check table asynchronously. In case of a remote site the chain is: Starting from central site: _get_check_table() | v automation service-discovery-job-discover | v to remote site | v AutomationServiceDiscoveryJob().execute() | v _get_check_table() """ if discovery_request.options.action == DiscoveryAction.TABULA_RASA: _changes.add_service_change( "refresh-autochecks", _("Refreshed check configuration of host '%s'") % discovery_request.host.name(), discovery_request.host.object_ref(), discovery_request.host.site_id(), ) if site_is_local(discovery_request.host.site_id()): return execute_discovery_job(discovery_request) sync_changes_before_remote_automation(discovery_request.host.site_id()) return DiscoveryResult.deserialize( do_remote_automation( get_site_config(discovery_request.host.site_id()), "service-discovery-job", [ ("host_name", discovery_request.host.name()), ("options", json.dumps(discovery_request.options._asdict())), ], ))
def _process_discovery_result_for_host(self, host, failed_reason, host_counts): if failed_reason is None: self._num_hosts_skipped += 1 return _("discovery skipped: host not monitored") if failed_reason is not False: self._num_hosts_failed += 1 if not host.locked(): host.set_discovery_failed() return _("discovery failed: %s") % failed_reason self._num_hosts_succeeded += 1 add_service_change( host, "bulk-discovery", _("Did service discovery on host %s: %d added, %d removed, %d kept, " "%d total services") % tuple([host.name()] + host_counts)) if not host.locked(): host.clear_discovery_failed() return _("discovery successful")
def _save_services(self, old_autochecks: SetAutochecksTable, checks: SetAutochecksTable, need_sync: bool) -> None: message = _( "Saved check configuration of host '%s' with %d services") % ( self._host.name(), len(checks), ) _changes.add_service_change( action_name="set-autochecks", text=message, object_ref=self._host.object_ref(), site_id=self._host.site_id(), need_sync=need_sync, diff_text=make_diff_text( _make_host_audit_log_object(old_autochecks), _make_host_audit_log_object(checks)), ) set_autochecks( self._host.site_id(), self._host.name(), checks, )