def _should_use_dns_cache(self) -> bool: site = self._host.effective_attribute("site") return watolib.sites.get_effective_global_setting( site, is_wato_slave_site(), "use_dns_cache", )
def site_globals_editable(site_id, site) -> bool: # Site is a remote site of another site. Allow to edit probably pushed site # specific globals when remote WATO is enabled if is_wato_slave_site(): return True # Local site: Don't enable site specific locals when no remote sites configured if not has_wato_slave_sites(): return False return site["replication"] or site_is_local(site_id)
def _update_site_specific_global_settings(self): """Update the sitespecific.mk of the local site (which is a remote site)""" if not is_wato_slave_site(): return global_config = cmk.gui.watolib.global_settings.load_site_global_settings( ) self._update_global_config(global_config) cmk.gui.watolib.global_settings.save_site_global_settings( global_config)
def user_sync_default_config(site_name: SiteId) -> UserSyncConfig: global_user_sync = _transform_userdb_automatic_sync(config.userdb_automatic_sync) if global_user_sync == "master": if site_is_local(site_name) and not is_wato_slave_site(): user_sync_default: UserSyncConfig = "all" else: user_sync_default = None else: user_sync_default = global_user_sync return user_sync_default
def warn_about_renamed_remote_site(old_site_id: SiteId, new_site_id: SiteId) -> None: """Warn user about central site that needs to be updated manually Detect whether or not this is a remote site and issue a warning to let the user known""" if not is_wato_slave_site(): return logger.info("") warning( "You renamed a distributed remote site.\n\nTo make your distributed " "setup work again, you will have to update the \"Distributed Monitoring\" " "configuration in your central site.\n")
def activate(self, settings: Optional[SerializedSettings] = None) -> ConfigurationWarnings: current_settings = self._load_site_config() settings = {} settings.update(self._to_omd_config(self.load())) settings.update(self._to_omd_config(self.load_site_globals())) config_change_commands: List[str] = [] self._logger.debug("Set omd config: %r" % settings) for key, val in settings.items(): if key not in current_settings: continue # Skip settings unknown to current OMD if current_settings[key] == val: continue # Skip unchanged settings config_change_commands.append("%s=%s" % (key, val)) if not config_change_commands: self._logger.debug("Got no config change commands...") return [] self._logger.debug('Executing "omd config change"') self._logger.debug(" Commands: %r" % config_change_commands) # We need a background job on remote sites to wait for the restart, so # that the central site can gather the result of the activation. # On a central site, the waiting for the end of the restart is already # taken into account by the activate changes background job within # async_progress.js. Just execute the omd config change command if is_wato_slave_site(): job = OMDConfigChangeBackgroundJob() if job.is_active(): raise MKUserError(None, _("Another omd config change job is already running.")) job.set_function(job.do_execute, config_change_commands) job.start() else: _do_config_change(config_change_commands, self._logger) return []
def execute_network_scan_job() -> None: """Executed by the multisite cron job once a minute. Is only executed in the central site. Finds the next folder to scan and starts it via WATO automation. The result is written to the folder in the master site.""" init_wato_datastructures(with_wato_lock=True) if is_wato_slave_site(): return # Don't execute this job on slaves. folder = _find_folder_to_scan() if not folder: return # Nothing to do. run_as = folder.attribute("network_scan")["run_as"] if not userdb.user_exists(run_as): raise MKGeneralException( _("The user %s used by the network " "scan of the folder %s does not exist.") % (run_as, folder.title())) with UserContext(run_as): result: NetworkScanResult = { "start": time.time(), "end": True, # means currently running "state": None, "output": "The scan is currently running.", } # Mark the scan in progress: Is important in case the request takes longer than # the interval of the cron job (1 minute). Otherwise the scan might be started # a second time before the first one finished. _save_network_scan_result(folder, result) try: if site_is_local(folder.site_id()): found = _do_network_scan(folder) else: found = do_remote_automation(get_site_config(folder.site_id()), "network-scan", [("folder", folder.path())]) if not isinstance(found, list): raise MKGeneralException( _("Received an invalid network scan result: %r") % found) _add_scanned_hosts_to_folder(folder, found) result.update({ "state": True, "output": _("The network scan found %d new hosts.") % len(found), }) except Exception as e: result.update({ "state": False, "output": _("An exception occured: %s") % e, }) logger.error("Exception in network scan:\n%s", traceback.format_exc()) result["end"] = time.time() _save_network_scan_result(folder, result)
def _get_effective_global_setting(self, varname: str) -> Any: return get_effective_global_setting( omd_site(), is_wato_slave_site(), varname, )
def is_show_more(self) -> bool: return not (has_wato_slave_sites() or is_wato_slave_site())
def _handle_ldap_sync_finished(logger, profiles_to_synchronize, changes): _synchronize_profiles_to_sites(logger, profiles_to_synchronize) if changes and config.wato_enabled and not is_wato_slave_site(): add_change("edit-users", "<br>".join(changes), add_user=False)