Exemplo n.º 1
0
 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",
     )
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
    def _check_site(self, site_id):
        if _site_is_using_livestatus_proxy(site_id):
            yield ACResultOK(_("Site is using the Livestatus Proxy Daemon"))

        elif not is_wato_slave_site():
            yield ACResultWARN(
                _("The Livestatus Proxy is not only good for slave sites, "
                  "enable it for your master site"))

        else:
            yield ACResultWARN(
                _("Use the Livestatus Proxy Daemon for your site"))
Exemplo n.º 4
0
def user_sync_default_config(site_name: SiteId) -> UserSyncConfig:
    global_user_sync = _transform_userdb_automatic_sync(
        active_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
Exemplo n.º 5
0
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")
Exemplo n.º 6
0
    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 []
Exemplo n.º 7
0
 def available(self):
     # This filter is also available on slave sites with disabled WATO
     # To determine if this site is a slave we check the existance of the distributed_wato.mk
     # file and the absence of any site configuration
     return active_config.wato_enabled or site_config.is_wato_slave_site()
Exemplo n.º 8
0
def _handle_ldap_sync_finished(logger, profiles_to_synchronize, changes):
    _synchronize_profiles_to_sites(logger, profiles_to_synchronize)

    if changes and active_config.wato_enabled and not is_wato_slave_site():
        add_change("edit-users", "<br>".join(changes), add_user=False)
Exemplo n.º 9
0
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."""
    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)
Exemplo n.º 10
0
    def show(self):
        if not site_config.is_wato_slave_site():
            if not active_config.wato_enabled:
                html.write_text(_("Setup is disabled."))
                return False

        user_folders = compute_foldertree()

        #
        # Render link target selection
        #
        # Apply some view specific filters
        views_to_show: List[Tuple[str, ViewSpec]] = []
        dflt_target_name: str = "allhosts"
        dflt_topic_name: str = ""
        for name, view in views.get_permitted_views().items():
            if (not active_config.visible_views
                    or name in active_config.visible_views) and (
                        not active_config.hidden_views
                        or name not in active_config.hidden_views):
                views_to_show.append((name, view))
                if name == dflt_target_name:
                    dflt_topic_name = view["topic"]

        selected_topic_name: str
        selected_target_name: str
        selected_topic_name, selected_target_name = user.load_file(
            "foldertree", (dflt_topic_name, dflt_target_name))

        visuals_to_show = [("views", e) for e in views_to_show]
        visuals_to_show += [
            ("dashboards", e)
            for e in dashboard.get_permitted_dashboards().items()
        ]

        topics = make_topic_menu(visuals_to_show)
        topic_choices: Choices = [(topic.title, topic.title)
                                  for topic in topics]

        html.open_table()
        html.open_tr()
        html.open_td()
        html.dropdown(
            "topic",
            topic_choices,
            deflt=selected_topic_name,
            onchange="cmk.sidebar.wato_tree_topic_changed(this)",
        )
        html.close_td()
        html.close_tr()

        html.open_tr()
        html.open_td()

        for topic in topics:
            targets: Choices = []
            for item in topic.items:
                if item.url and item.url.startswith("dashboard.py"):
                    name = "dashboard|" + item.name
                else:
                    name = item.name
                targets.append((name, item.title))

            if topic.name != selected_topic_name:
                default = ""
                style: Optional[str] = "display:none"
            else:
                default = selected_target_name
                style = None
            html.dropdown(
                "target_%s" % topic.title,
                targets,
                deflt=default,
                onchange="cmk.sidebar.wato_tree_target_changed(this)",
                style=style,
            )

        html.close_td()
        html.close_tr()
        html.close_table()

        # Now render the whole tree
        if user_folders:
            render_tree_folder("wato-hosts",
                               list(user_folders.values())[0],
                               "cmk.sidebar.wato_tree_click")
Exemplo n.º 11
0
 def is_show_more(self) -> bool:
     return not (has_wato_slave_sites() or is_wato_slave_site())