def _should_use_dns_cache(self) -> bool: site = self._host.effective_attribute("site") return watolib.sites.get_effective_global_setting( site, config.is_wato_slave_site(), "use_dns_cache", )
def userdb_sync_job_enabled() -> bool: cfg = user_sync_config() if cfg is None: return False # not enabled at all if cfg == "master" and config.is_wato_slave_site(): return False return True
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 config.is_wato_slave_site(): return True # Local site: Don't enable site specific locals when no remote sites configured if not config.has_wato_slave_sites(): return False return site["replication"] or config.site_is_local(site_id)
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 config.site_is_local(site_name) and not config.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 _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 config.is_wato_slave_site(): add_change("edit-users", "<br>".join(changes), add_user=False)
def default_site() -> Union[bool, None, SiteId]: if config.is_wato_slave_site(): return False return config.default_site()
def default_site(): if config.is_wato_slave_site(): return False return config.default_site()
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 config.is_wato_slave_site(): return # Don't execute this job on slaves. folder = _find_folder_to_scan() if not folder: return # Nothing to do. # We need to have the context of the user. The jobs are executed when # config.set_user_by_id() has not been executed yet. So there is no user context # available. Use the run_as attribute from the job config and revert # the previous state after completion. old_user = config.user.id 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())) config.set_user_by_id(folder.attribute("network_scan")["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 config.site_is_local(folder.site_id()): found = _do_network_scan(folder) else: found = do_remote_automation(config.site(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) if old_user: config.set_user_by_id(old_user)