예제 #1
0
    def page(self):
        if not self._job_snapshot.exists():
            # Skip if snapshot doesnt exists
            pass

        elif self._job_snapshot.is_active():
            # Still running
            html.message(
                HTML(_("User synchronization currently running: ")) + self._job_details_link())
            url = html.makeuri([])
            html.immediate_browser_redirect(2, url)

        elif self._job_snapshot.state() == gui_background_job.background_job.JobStatusStates.FINISHED \
             and not self._job_snapshot.acknowledged_by():
            # Just finished, auto-acknowledge
            userdb.UserSyncBackgroundJob().acknowledge(config.user.id)
            #html.message(_("User synchronization successful"))

        elif not self._job_snapshot.acknowledged_by() and self._job_snapshot.has_exception():
            # Finished, but not OK - show info message with links to details
            html.show_warning(
                HTML(_("Last user synchronization ran into an exception: ")) +
                self._job_details_link())

        self._show_user_list()
예제 #2
0
파일: users.py 프로젝트: majma24/checkmk
    def action(self):
        if html.request.var('_delete'):
            delid = html.request.get_unicode_input("_delete")
            c = wato_confirm(
                _("Confirm deletion of user %s") % delid,
                _("Do you really want to delete the user %s?") % delid)
            if c:
                delete_users([delid])
            elif c is False:
                return ""

        elif html.request.var('_sync') and html.check_transaction():
            try:

                job = userdb.UserSyncBackgroundJob()
                job.set_function(job.do_sync,
                                 add_to_changelog=True,
                                 enforce_sync=True,
                                 load_users_func=userdb.load_users,
                                 save_users_func=userdb.save_users)

                try:
                    job.start()
                except background_job.BackgroundJobAlreadyRunning as e:
                    raise MKUserError(
                        None,
                        _("Another synchronization job is already running: %s")
                        % e)

                self._job_snapshot = job.get_status_snapshot()
            except Exception:
                logger.exception("error syncing users")
                raise MKUserError(
                    None,
                    traceback.format_exc().replace('\n', '<br>\n'))

        elif html.request.var("_bulk_delete_users"):
            return self._bulk_delete_users_after_confirm()

        elif html.check_transaction():
            action_handler = gui_background_job.ActionHandler(
                self.breadcrumb())
            action_handler.handle_actions()
            if action_handler.did_acknowledge_job():
                self._job_snapshot = userdb.UserSyncBackgroundJob(
                ).get_status_snapshot()
                return None, _("Synchronization job acknowledged")
예제 #3
0
파일: users.py 프로젝트: arusa/checkmk
    def action(self) -> ActionResult:
        if not html.check_transaction():
            return redirect(self.mode_url())

        if html.request.var('_delete'):
            delete_users([html.request.get_unicode_input("_delete")])

        elif html.request.var('_sync'):
            try:

                job = userdb.UserSyncBackgroundJob()
                job.set_function(job.do_sync,
                                 add_to_changelog=True,
                                 enforce_sync=True,
                                 load_users_func=userdb.load_users,
                                 save_users_func=userdb.save_users)

                try:
                    job.start()
                except background_job.BackgroundJobAlreadyRunning as e:
                    raise MKUserError(None,
                                      _("Another synchronization job is already running: %s") % e)

                self._job_snapshot = job.get_status_snapshot()
            except Exception:
                logger.exception("error syncing users")
                raise MKUserError(None, traceback.format_exc().replace('\n', '<br>\n'))

        elif html.request.var("_bulk_delete_users"):
            self._bulk_delete_users_after_confirm()

        else:
            action_handler = gui_background_job.ActionHandler(self.breadcrumb())
            action_handler.handle_actions()
            if action_handler.did_acknowledge_job():
                self._job_snapshot = userdb.UserSyncBackgroundJob().get_status_snapshot()
                flash(_("Synchronization job acknowledged"))
        return redirect(self.mode_url())
예제 #4
0
 def __init__(self):
     super(ModeUsers, self).__init__()
     self._job = userdb.UserSyncBackgroundJob()
     self._job_snapshot = userdb.UserSyncBackgroundJob().get_status_snapshot()