def page(self) -> None: with table_element(title=self._table_title(), searchable=False, sortable=False) as table: for key_id, key in sorted(self.key_store.load().items()): cert = crypto.load_certificate(crypto.FILETYPE_PEM, key.certificate.encode("ascii")) table.row() table.cell(_("Actions"), css=["buttons"]) if self._may_edit_config(): message = self._delete_confirm_msg() if key.owner != user.id: message += ( _("<br><b>Note</b>: this key has created by user <b>%s</b>") % key.owner ) delete_url = make_confirm_link( url=makeactionuri(request, transactions, [("_delete", key_id)]), message=message, ) html.icon_button(delete_url, _("Delete this key"), "delete") download_url = makeuri_contextless( request, [("mode", self.download_mode), ("key", key_id)], ) html.icon_button(download_url, _("Download this key"), "download") table.cell(_("Description"), key.alias) table.cell(_("Created"), cmk.utils.render.date(key.date)) table.cell(_("By"), key.owner) table.cell(_("Digest (MD5)"), cert.digest("md5").decode("ascii"))
def _show_credentials( cls, webauthn_credentials: dict[str, WebAuthnCredential]) -> None: with table_element(title=None, searchable=False, sortable=False) as table: for credential in webauthn_credentials.values(): table.row() table.cell(_("Actions"), css="buttons") delete_url = make_confirm_link( url=makeactionuri( request, transactions, [("_delete", credential["credential_id"])]), message=_("Do you really want to delete this credential"), ) html.icon_button(delete_url, _("Delete this credential"), "delete") html.icon_button( makeuri_contextless( request, [("_edit", credential["credential_id"])], filename="user_two_factor_edit_credential.py", ), _("Edit this credential"), "edit", ) table.cell(_("Alias"), credential["alias"]) table.cell( _("Registered at"), time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(credential["registered_at"])), )
def _page_menu_entry_acknowledge( site: Optional[SiteId] = None, host_name: Optional[HostName] = None, int_filename: Optional[str] = None, ) -> Iterator[PageMenuEntry]: if not user.may("general.act") or (host_name and not may_see(site, host_name)): return if int_filename: label = _("Clear log") else: label = _("Clear logs") urivars: HTTPVariables = [("_ack", "1")] if int_filename: urivars.append(("file", form_file_to_ext(int_filename))) ack_msg = _get_ack_msg( host_name, form_file_to_ext(int_filename) if int_filename else None) yield PageMenuEntry( title=label, icon_name="delete", item=make_simple_link( make_confirm_link( url=makeactionuri(request, transactions, urivars), message=_("Do you really want to acknowledge %s " "by <b>deleting</b> all stored messages?") % ack_msg, )), is_shortcut=True, is_suggested=True, )
def _show_host_actions(self, host): html.icon_button(host.edit_url(), _("Edit the properties of this host"), "edit") if config.user.may("wato.rulesets"): html.icon_button(host.params_url(), _("View the rule based parameters of this host"), "rulesets") if host.may('read'): if config.user.may("wato.services"): msg = _("Edit the services of this host, do a service discovery") else: msg = _("Display the services of this host") image = "services" if host.discovery_failed(): image = "inventory_failed" msg += ". " + _( "The service discovery of this host failed during a previous bulk service discovery." ) html.icon_button(host.services_url(), msg, image) if not host.locked(): if config.user.may("wato.edit_hosts") and config.user.may("wato.move_hosts"): self._show_move_to_folder_action(host) if config.user.may("wato.manage_hosts"): if config.user.may("wato.clone_hosts"): html.icon_button(host.clone_url(), _("Create a clone of this host"), "insert") delete_url = make_confirm_link( url=watolib.make_action_link([("mode", "folder"), ("_delete_host", host.name())]), message=_("Do you really want to delete the host <tt>%s</tt>?") % host.name(), ) html.icon_button(delete_url, _("Delete this host"), "delete")
def _show_subfolder_delete_button(self, subfolder): msg = _( "Do you really want to delete the folder %s?") % subfolder.title() if not config.wato_hide_filenames: msg += _(" Its directory is <tt>%s</tt>." ) % subfolder.filesystem_path() num_hosts = subfolder.num_hosts_recursively() if num_hosts: msg += _( " The folder contains <b>%d</b> hosts, which will also be deleted!" ) % num_hosts html.icon_button( make_confirm_link( url=watolib.make_action_link([("mode", "folder"), ("_delete_folder", subfolder.name())]), message=msg, ), _("Delete this folder"), "delete", id_='delete_' + subfolder.name(), cssclass='delete', style='display:none', )
def _show_action_cell(self, table, ident): table.cell(_("Actions"), css="buttons") edit_url = makeuri_contextless( request, [ ("mode", self._mode_type.edit_mode_name()), ("ident", ident), ], ) html.icon_button(edit_url, _("Edit this %s") % self._mode_type.name_singular(), "edit") clone_url = makeuri_contextless( request, [ ("mode", self._mode_type.edit_mode_name()), ("clone", ident), ], ) html.icon_button(clone_url, _("Clone this %s") % self._mode_type.name_singular(), "clone") delete_url = make_confirm_link( url=watolib.make_action_link([ ("mode", self._mode_type.list_mode_name()), ("_action", "delete"), ("_delete", ident), ]), message=self._delete_confirm_message(), ) html.icon_button(delete_url, _("Delete this %s") % self._mode_type.name_singular(), "delete")
def _page_menu_entries_ack_all_werks() -> Iterator[PageMenuEntry]: if not may_acknowledge(): return yield PageMenuEntry( title=_("Acknowledge all"), icon_name="werk_ack", is_shortcut=True, is_suggested=True, item=make_simple_link( make_confirm_link( url=makeactionuri(request, transactions, [("_ack_all", "1")]), message=_("Do you really want to acknowledge <b>all</b> incompatible werks?"), ) ), is_enabled=bool(unacknowledged_incompatible_werks()), )
def render_page_confirm(acktime, failed_notifications): title = _("Confirm failed notifications") breadcrumb = make_simple_page_breadcrumb( mega_menu_registry.menu_monitoring(), title) confirm_url = make_confirm_link( url=html.makeactionuri_contextless([ ("mode", "clear_failed_notifications"), ("acktime", str(acktime)), ("_confirm", "1"), ]), message= _("Do you really want to acknowledge all failed notifications up to %s?" ) % cmk.utils.render.date_and_time(acktime), ) page_menu = PageMenu( dropdowns=[ PageMenuDropdown( name="actions", title=_("Actions"), topics=[ PageMenuTopic( title=_("Actions"), entries=[ PageMenuEntry( title=_("Confirm"), icon_name="save", item=make_javascript_link(confirm_url), is_shortcut=True, is_suggested=True, is_enabled=failed_notifications, ), ], ), ], ), ], breadcrumb=breadcrumb, ) html.header(title, breadcrumb, page_menu) render_notification_table(failed_notifications) html.footer()
def _page_menu(self, acktime: float, failed_notifications: LivestatusResponse, breadcrumb: Breadcrumb) -> PageMenu: confirm_url = make_simple_link( make_confirm_link( url=makeactionuri(request, transactions, [("acktime", str(acktime)), ("_confirm", "1")]), message= _("Do you really want to acknowledge all failed notifications up to %s?" ) % cmk.utils.render.date_and_time(acktime), )) return PageMenu( dropdowns=[ PageMenuDropdown( name="actions", title=_("Actions"), topics=[ PageMenuTopic( title=_("Actions"), entries=[ PageMenuEntry( title=_("Confirm"), icon_name="save", item=confirm_url, is_shortcut=True, is_suggested=True, is_enabled=bool(failed_notifications), ), ], ), ], ), ], breadcrumb=breadcrumb, )
def show_job_details(cls, job_id, job_status): """Renders the complete job details in a single table with left headers""" html.open_table(class_=["data", "headerleft", "job_details"]) # Static info for left, right in [ (_("ID"), job_id), (_("Title"), job_status.get("title", "")), (_("Started"), cmk.utils.render.date_and_time(job_status["started"])), (_("Owner"), job_status.get("user", "")), ]: html.open_tr() html.th(left) html.td(right) html.close_tr() # Actions html.open_tr() html.th(_("Actions")) html.open_td() if job_status.get("may_stop"): html.icon_button( make_confirm_link( url=makeactionuri(request, transactions, [(ActionHandler.stop_job_var, job_id)]), message=_("Stop job %s%s?") % (job_id, cls._get_extra_info(job_status)), ), _("Stop this job"), "disable_test", ) if job_status.get("may_delete"): html.icon_button( make_confirm_link( url=makeactionuri( request, transactions, [(ActionHandler.delete_job_var, job_id)]), message=_("Delete job %s%s?") % (job_id, cls._get_extra_info(job_status)), ), _("Delete this job"), "delete", ) html.close_td() html.close_tr() # Job state html.open_tr() html.th(_("State")) html.td(job_status["state"], css=cls.get_css_for_jobstate(job_status["state"])) html.close_tr() if job_status["state"] == background_job.JobStatusStates.EXCEPTION: html.open_tr() html.th(_("Acknowledged by")) html.td(job_status.get("acknowledged_by", "")) html.close_tr() # Dynamic data loginfo = job_status.get("loginfo") runtime_info = cmk.utils.render.timespan(job_status.get("duration", 0)) if (job_status["state"] == background_job.JobStatusStates.RUNNING and job_status.get("estimated_duration") is not None): runtime_info += " (%s: %s)" % ( _("estimated duration"), cmk.utils.render.timespan(job_status["estimated_duration"]), ) for left, right in [ (_("Runtime"), runtime_info), (_("PID"), str(job_status["pid"]) or ""), (_("Result"), "<br>".join(loginfo["JobResult"])), ]: if right is None: continue html.open_tr() html.th(left) html.td(HTML(right)) html.close_tr() # Exceptions exceptions = loginfo["JobException"] if exceptions: html.open_tr() html.th(_("Exceptions")) html.open_td() if exceptions and "logfile_path" in job_status: exceptions.append( _("More information can be found in %s") % job_status["logfile_path"]) html.open_div(class_="log_output", id_="exception_log") html.pre("\n".join(exceptions)) html.close_div() html.close_td() html.close_tr() # Progress Update html.open_tr() html.th(_("Progress Info")) html.open_td() html.open_div(class_="log_output", style="height: 400px;", id_="progress_log") html.pre(HTML("\n").join(loginfo["JobProgressUpdate"])) html.close_div() html.close_td() html.close_tr() html.close_table()