コード例 #1
0
    def _verify_slave_site_config(self, site_id):
        # type: (str) -> None
        if not site_id:
            raise MKGeneralException(_("Missing variable siteid"))

        our_id = config.omd_site()

        if not config.is_single_local_site():
            raise MKGeneralException(
                _("Configuration error. You treat us as "
                  "a <b>remote</b>, but we have an own distributed WATO configuration!"
                  ))

        if our_id is not None and our_id != site_id:
            raise MKGeneralException(
                _("Site ID mismatch. Our ID is '%s', but you are saying we are '%s'."
                  ) % (our_id, site_id))

        # Make sure there are no local changes we would lose!
        changes = ActivateChanges()
        changes.load()
        pending = list(reversed(changes.grouped_changes()))
        if pending:
            message = _(
                "There are %d pending changes that would get lost. The most recent are: "
            ) % len(pending)
            message += ", ".join(change["text"]
                                 for _change_id, change in pending[:10])

            raise MKGeneralException(message)
コード例 #2
0
ファイル: async_replication.py プロジェクト: m3rlinux/checkmk
def user_profile_async_replication_dialog(sites: Sequence[SiteId],
                                          back_url: str) -> None:
    html.p(
        _("In order to activate your changes available on all remote sites, your user profile needs "
          "to be replicated to the remote sites. This is done on this page now. Each site "
          "is being represented by a single image which is first shown gray and then fills "
          "to green during synchronisation."))

    html.h3(_("Replication States"))
    html.open_div(id_="profile_repl")
    num_replsites = 0
    for site_id in sites:
        site = active_config.sites[site_id]
        if "secret" not in site:
            status_txt = _("Not logged in.")
            start_sync = False
            icon = "repl_locked"
        else:
            status_txt = _("Waiting for replication to start")
            start_sync = True
            icon = "repl_pending"

        html.open_div(class_="site", id_="site-%s" % site_id)
        html.div("", title=status_txt, class_=["icon", "repl_status", icon])
        if start_sync:
            changes_manager = ActivateChanges()
            changes_manager.load()
            estimated_duration = changes_manager.get_activation_time(
                site_id, ACTIVATION_TIME_PROFILE_SYNC, 2.0)
            html.javascript("cmk.profile_replication.start(%s, %d, %s);" % (
                json.dumps(site_id),
                int(estimated_duration * 1000.0),
                json.dumps(_("Replication in progress")),
            ))
            num_replsites += 1
        else:
            _add_profile_replication_change(site_id, status_txt)
        html.span(site.get("alias", site_id))

        html.close_div()

    html.javascript("cmk.profile_replication.prepare(%d, %s);\n" %
                    (num_replsites, json.dumps(back_url)))

    html.close_div()
コード例 #3
0
ファイル: async_replication.py プロジェクト: m3rlinux/checkmk
    def _synchronize_profile(self, site_id: SiteId, site: SiteConfiguration,
                             user_id: UserId) -> Union[bool, str]:
        users = userdb.load_users(lock=False)
        if user_id not in users:
            raise MKUserError(None, _("The requested user does not exist"))

        start = time.time()
        result = push_user_profiles_to_site_transitional_wrapper(
            site, {user_id: users[user_id]})

        duration = time.time() - start
        ActivateChanges().update_activation_time(site_id,
                                                 ACTIVATION_TIME_PROFILE_SYNC,
                                                 duration)
        return result