def paint(self, value, hostname): value = convert_cgroups_from_tuple(value) texts: List[HTML] = [] self.load_data() if self._contactgroups is None: # conditional caused by horrible API raise Exception("invalid contact groups") items = self._contactgroups.items() for name, cgroup in sorted(items, key=lambda x: x[1]["alias"]): if name in value["groups"]: display_name = cgroup.get("alias", name) texts.append( html.render_a( display_name, href=makeuri_contextless( request, [("mode", "edit_contact_group"), ("edit", name)], filename="wato.py", ), )) result: HTML = HTML(", ").join(texts) if texts and value["use"]: result += html.render_span( html.render_b("*"), title= _("These contact groups are also used in the monitoring configuration." ), ) return "", result
def page_werk(): load_werks() werk_id = html.request.get_integer_input_mandatory("werk") if werk_id not in g_werks: raise MKUserError("werk", _("This werk does not exist.")) werk = g_werks[werk_id] html.header( ("%s %s - %s") % (_("Werk"), render_werk_id(werk, with_link=False), werk["title"])) html.begin_context_buttons() back_url = html.makeuri([], filename="version.py", delvars=["werk"]) # keeps filter settings html.context_button(_("Back"), back_url, "back") if werk["compatible"] == "incomp_unack" and may_acknowledge(): ack_url = html.makeactionuri([("_werk_ack", werk["id"])], filename="version.py") html.context_button(_("Acknowledge"), ack_url, "werk_ack") html.end_context_buttons() html.open_table(class_=["data", "headerleft", "werks"]) def werk_table_row(caption, content, css=None): html.open_tr() html.th(caption) html.open_td(class_=css) html.write(content) html.close_td() html.close_tr() translator = cmk.utils.werks.WerkTranslator() werk_table_row(_("ID"), render_werk_id(werk, with_link=False)) werk_table_row(_("Title"), html.render_b(render_werk_title(werk))) werk_table_row(_("Component"), translator.component_of(werk)) werk_table_row(_("Date"), render_werk_date(werk)) werk_table_row(_("Checkmk Version"), werk["version"]) werk_table_row(_("Level"), translator.level_of(werk), css="werklevel werklevel%d" % werk["level"]) werk_table_row(_("Class"), translator.class_of(werk), css="werkclass werkclass%s" % werk["class"]) werk_table_row(_("Compatibility"), translator.compatibility_of(werk), css="werkcomp werkcomp%s" % werk["compatible"]) werk_table_row(_("Description"), render_werk_description(werk), css="nowiki") html.close_table() html.footer()
def page_werk(): load_werks() werk_id = request.get_integer_input_mandatory("werk") if werk_id not in g_werks: raise MKUserError("werk", _("This werk does not exist.")) werk = g_werks[werk_id] title = ("%s %s - %s") % (_("Werk"), render_werk_id( werk, with_link=False), werk["title"]) breadcrumb = make_main_menu_breadcrumb(mega_menu_registry["help_links"]) breadcrumb.append( BreadcrumbItem( title=_("Change log (Werks)"), url="change_log.py", )) breadcrumb.append(make_current_page_breadcrumb_item(title)) html.header(title, breadcrumb, _page_menu_werk(breadcrumb, werk)) html.open_table(class_=["data", "headerleft", "werks"]) def werk_table_row(caption, content, css=None): html.open_tr() html.th(caption) html.td(content, class_=css) html.close_tr() translator = cmk.utils.werks.WerkTranslator() werk_table_row(_("ID"), render_werk_id(werk, with_link=False)) werk_table_row(_("Title"), html.render_b(render_werk_title(werk))) werk_table_row(_("Component"), translator.component_of(werk)) werk_table_row(_("Date"), render_werk_date(werk)) werk_table_row(_("Checkmk Version"), werk["version"]) werk_table_row(_("Level"), translator.level_of(werk), css="werklevel werklevel%d" % werk["level"]) werk_table_row(_("Class"), translator.class_of(werk), css="werkclass werkclass%s" % werk["class"]) werk_table_row( _("Compatibility"), translator.compatibility_of(werk), css="werkcomp werkcomp%s" % werk["compatible"], ) werk_table_row(_("Description"), render_werk_description(werk), css="nowiki") html.close_table() html.footer()
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 = html.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( html.render_tr( html.render_td(host_name) + html.render_td(" → %s" % target_name))) message += html.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 paint(self, value, hostname): value = convert_cgroups_from_tuple(value) texts = [] self.load_data() items = self._contactgroups.items() for name, cgroup in sorted(items, key=lambda x: x[1]['alias']): if name in value["groups"]: display_name = cgroup.get("alias", name) texts.append('<a href="wato.py?mode=edit_contact_group&edit=%s">%s</a>' % (name, display_name)) result = ", ".join(texts) if texts and value["use"]: result += html.render_span( html.render_b("*"), title=_("These contact groups are also used in the monitoring configuration.")) return "", result
def _show_node(self, tree, show_host, mousecode=None, img_class=None): # Check if we have an assumed state: comparing assumed state (tree[1]) with state (tree[0]) if tree[1] and tree[0] != tree[1]: addclass: Optional[str] = "assumed" effective_state = tree[1] else: addclass = None effective_state = tree[0] class_: List[Optional[str]] = [ "content", # "state", "state%d" % (effective_state["state"] if effective_state["state"] is not None else -1), addclass, ] html.open_span(class_=class_) html.write_text(self._render_bi_state(effective_state["state"])) html.close_span() if mousecode: if img_class: html.img( src=theme.url("images/tree_closed.svg"), class_=["treeangle", img_class], onclick=mousecode, ) html.open_span(class_=["content", "name"]) icon_name, icon_title = None, None if tree[0]["in_downtime"] == 2: icon_name = "downtime" icon_title = _("This element is currently in a scheduled downtime.") elif tree[0]["in_downtime"] == 1: # only display host downtime if the service has no own downtime icon_name = "derived_downtime" icon_title = _("One of the subelements is in a scheduled downtime.") if tree[0]["acknowledged"]: icon_name = "ack" icon_title = _("This problem has been acknowledged.") if not tree[0]["in_service_period"]: icon_name = "outof_serviceperiod" icon_title = _("This element is currently not in its service period.") if icon_name and icon_title: html.icon(icon_name, title=icon_title, class_=["icon", "bi"]) yield if mousecode: if str(effective_state["state"]) in tree[2].get("state_messages", {}): html.b(HTML("♦"), class_="bullet") html.write_text(tree[2]["state_messages"][str(effective_state["state"])]) html.close_span() output: HTML = cmk.gui.view_utils.format_plugin_output( effective_state["output"], shall_escape=config.escape_plugin_output ) if output: output = html.render_b(HTML("♦"), class_="bullet") + output else: output = HTML() html.span(output, class_=["content", "output"])