Ejemplo n.º 1
0
    def _show_tree(self):
        td_style = None if self._wrap_texts == "wrap" else "white-space: nowrap;"

        tree = self._get_tree()
        depth = status_tree_depth(tree)
        leaves = self._gen_table(tree, depth, len(self._row["aggr_hosts"]) > 1)

        html.open_table(class_=["aggrtree", "ltr"])
        odd = "odd"
        for code, colspan, parents in leaves:
            html.open_tr()

            leaf_td = HTMLWriter.render_td(code,
                                           class_=["leaf", odd],
                                           style=td_style,
                                           colspan=colspan)
            odd = "even" if odd == "odd" else "odd"

            tds = [leaf_td]
            for rowspan, c in parents:
                tds.append(
                    HTMLWriter.render_td(c,
                                         class_=["node"],
                                         style=td_style,
                                         rowspan=rowspan))

            if self._mirror:
                tds.reverse()

            html.write_html(HTML("").join(tds))
            html.close_tr()

        html.close_table()
Ejemplo n.º 2
0
    def show(self) -> None:
        only_sites = snapin_site_choice("mkeventd_performance", get_event_console_site_choices())

        try:
            entries = self._mkeventd_performance_entries(only_sites)
        except Exception as e:
            html.show_error("%s" % e)
            return

        html.open_table(class_=["mkeventd_performance"])
        for _index, left, right in entries:
            html.tr(HTMLWriter.render_td("%s:" % left) + HTMLWriter.render_td(right))
        html.close_table()
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
def end() -> None:
    global g_header_open
    g_header_open = False
    section_close()
    html.tr(HTMLWriter.render_td("", colspan=2), class_=["bottom"])
    html.close_tbody()
    html.close_table()
Ejemplo n.º 5
0
def render_perfometer_td(perc: float, color: str) -> HTML:
    # the hex color can have additional information about opacity
    # internet explorer has problems with the format of rgba, e.g.: #aaaaaa4d
    # the solution is to set the background-color value to rgb ('#aaaaaa')
    # and use the css opacity for the opacity hex value in float '4d' -> 0.3
    opacity = None
    if len(color) == 9:
        opacity = int(color[7:], 16) / 255.0
        color = color[:7]

    style = ["width: %d%%;" % int(float(perc)), "background-color: %s" % color]
    if opacity is not None:
        style += ["opacity: %s" % opacity]
    return HTMLWriter.render_td("", class_="inner", style=style)
Ejemplo n.º 6
0
def header(
    title: str,
    isopen: bool = True,
    table_id: str = "",
    narrow: bool = False,
    css: Optional[str] = None,
    show_table_head: bool = True,
    show_more_toggle: bool = False,
    show_more_mode: bool = False,
    help_text: Union[str, HTML, None] = None,
) -> None:
    global g_header_open, g_section_open
    if g_header_open:
        end()

    id_ = base64.b64encode(title.encode()).decode()
    treename = html.form_name or "nform"
    isopen = user.get_tree_state(treename, id_, isopen)
    container_id = foldable_container_id(treename, id_)

    class_ = ["nform"]
    if narrow:
        class_.append("narrow")
    if css:
        class_.append(css)
    class_.append("open" if isopen else "closed")
    if user.get_show_more_setting("foldable_%s" % id_) or show_more_mode:
        class_.append("more")

    html.open_table(
        id_=table_id if table_id else None,
        class_=class_,
    )

    if show_table_head:
        _table_head(
            treename=treename,
            id_=id_,
            isopen=isopen,
            title=title,
            show_more_toggle=show_more_toggle,
            help_text=help_text,
        )

    html.open_tbody(id_=container_id, class_=["open" if isopen else "closed"])
    html.tr(HTMLWriter.render_td("", colspan=2))
    g_header_open = True
    g_section_open = False
Ejemplo n.º 7
0
def space() -> None:
    html.tr(HTMLWriter.render_td("", colspan=2, style="height:15px;"))