def _create_status_box( self, site_ids: Collection[livestatus.SiteId], css_class: str, site_status: str, ): html.open_div(class_="spacertop") html.open_div(class_=css_class) message_template = ungettext("%d site is %s.", "%d sites are %s.", len(site_ids)) message = message_template % (len(site_ids), site_status) tooltip_template = ungettext( "Associated hosts, services and events are not included " "in the Tactical Overview. The %s site is %s.", "Associated hosts, services and events are not included " "in the Tactical Overview. The %s sites are %s.", len(site_ids), ) tooltip = tooltip_template % (site_status, ", ".join(site_ids)) if user.may("wato.sites"): url = makeuri_contextless(request, [("mode", "sites")], filename="wato.py") html.icon_button(url, tooltip, "sites", target="main") html.a(message, target="main", href=url) else: html.icon("sites", tooltip) html.write_text(message) html.close_div() html.close_div()
def _show_site_status(self): if not self.parameters().get("show_sites_not_connected"): return sites_not_connected = [ site_id for site_id, site_status in sites.states().items() if site_status["state"] != "online" ] if len(sites_not_connected) == 0: return html.open_div(class_="spacertop") html.open_div(class_="tacticalalert") message_template = ungettext("%d site is not connected", "%d sites are not connected", len(sites_not_connected)) tooltip_template = ungettext( "Associated hosts, services and events are not included " "in the Tactical Overview. The disconnected site is %s.", "Associated hosts, services and events are not included " "in the Tactical Overview. The disconnected sites are %s.", len(sites_not_connected)) message = message_template % len(sites_not_connected) tooltip = tooltip_template % ', '.join(sites_not_connected) if config.user.may("wato.sites"): url = html.makeuri_contextless([("mode", "sites")], filename="wato.py") html.icon_button(url, tooltip, "sites", target="main") html.a(message, target="main", href=url) else: html.icon(tooltip, "sites") html.write_text(message) html.close_div() html.close_div()
def action(self) -> ActionResult: renaming_config = self._vs_renaming_config().from_html_vars("") self._vs_renaming_config().validate_value(renaming_config, "") renamings = self._collect_host_renamings(renaming_config) if not renamings: flash(_("No matching host names")) return None warning = self._renaming_collision_error(renamings) if warning: flash(warning) return None message = HTMLWriter.render_b( _("Do you really want to rename to following hosts?" "This involves a restart of the monitoring core!")) rows = [] for _folder, host_name, target_name in renamings: rows.append( HTMLWriter.render_tr( HTMLWriter.render_td(host_name) + HTMLWriter.render_td(" → %s" % target_name))) message += HTMLWriter.render_table(HTML().join(rows)) nr_rename = len(renamings) c = _confirm( _("Confirm renaming of %d %s") % (nr_rename, ungettext("host", "hosts", nr_rename)), message, ) if c: title = _("Renaming of %s") % ", ".join("%s → %s" % x[1:] for x in renamings) host_renaming_job = RenameHostsBackgroundJob(title=title) host_renaming_job.set_function(rename_hosts_background_job, renamings) try: host_renaming_job.start() except background_job.BackgroundJobAlreadyRunning as e: raise MKGeneralException( _("Another host renaming job is already running: %s") % e) return redirect(host_renaming_job.detail_url()) if c is False: # not yet confirmed return FinalizeRequest(code=200) return None # browser reload
def page(self): if not may_acknowledge(): raise MKAuthException( _("You are not allowed to acknowlegde werks")) num_unacknowledged_werks = num_unacknowledged_incompatible_werks() tooltip_text = ungettext("%d unacknowledged incompatible werk", "%d unacknowledged incompatible werks", num_unacknowledged_werks) return { "count": num_unacknowledged_werks, "text": _("%d open incompatible werks") % num_unacknowledged_werks, "tooltip": tooltip_text, }
def page(self): popup_msg: List = [] hint_msg: int = 0 for msg in notify.get_gui_messages(): if 'gui_hint' in msg['methods']: hint_msg += 1 if 'gui_popup' in msg['methods']: popup_msg.append({"id": msg["id"], "text": msg['text']}) return { "popup_messages": popup_msg, "hint_messages": { "text": ungettext("message", "messages", hint_msg), "count": hint_msg, }, }
def page(self): popup_msg: List = [] hint_msg: int = 0 for msg in message.get_gui_messages(): if "gui_hint" in msg["methods"]: hint_msg += 1 if "gui_popup" in msg["methods"]: popup_msg.append({"id": msg["id"], "text": msg["text"]}) return { "popup_messages": popup_msg, "hint_messages": { "text": ungettext("message", "messages", hint_msg), "count": hint_msg, }, }
def _make_wato_page_state() -> PageState: changes_info = get_pending_changes_info() changelog_url = "wato.py?mode=changelog" span_id = "pending_changes" if changes_info: return PageState( text=html.render_span(changes_info, id_=span_id), icon_name="pending_changes", url=changelog_url, tooltip_text=ungettext(singular=_("Currently there is one change to activate"), plural=_("Currently there are %s to activate." % changes_info), n=int(re.findall(r"\d+", changes_info)[0])) + \ "\n" + _("Click here to go to pending changes."), ) return PageState( text=html.render_span(_("No pending changes"), id_=span_id), url=changelog_url, tooltip_text=_("Click here to see the activation status per site."))
def rename_hosts_background_job(renamings, job_interface=None): actions, auth_problems = rename_hosts( renamings, job_interface=job_interface) # Already activates the changes! confirm_all_local_changes( ) # All activated by the underlying rename automation action_txt = "".join(["<li>%s</li>" % a for a in actions]) message = _("Renamed %d %s at the following places:<br><ul>%s</ul>") % ( len(renamings), ungettext("host", "hosts", len(renamings)), action_txt, ) if auth_problems: message += _( "The following hosts could not be renamed because of missing permissions: %s" ) % ", ".join([ "%s (%s)" % (host_name, reason) for (host_name, reason) in auth_problems ]) job_interface.send_result_message(message)
def user_dialog_suffix(self, title: str, len_action_rows: int, cmdtag: str) -> str: return title + _(" the following %d crash %s") % ( len_action_rows, ungettext("report", "reports", len_action_rows), )