Esempio n. 1
0
def render_bi_availability(title, aggr_rows):
    av_mode = html.var("av_mode", "availability")

    avoptions = get_availability_options_from_url("bi")
    time_range, range_title = avoptions["range"]

    if av_mode == "timeline":
        title = _("Timeline of ") + title
    else:
        title = _("Availability of ") + title

    if html.output_format != "csv_export":
        html.body_start(title,
                        stylesheets=["pages", "views", "status", "bi"],
                        javascripts=['bi'])
        html.top_heading(title)
        html.begin_context_buttons()
        togglebutton("avoptions", False, "painteroptions",
                     _("Configure details of the report"))
        html.context_button(_("Status View"),
                            html.makeuri([("mode", "status")]), "status")
        if config.reporting_available() and config.user.may(
                "general.reporting"):
            html.context_button(_("Export as PDF"),
                                html.makeuri([], filename="report_instant.py"),
                                "report")
        if av_mode == "availability":
            html.context_button(
                _("Export as CSV"),
                html.makeuri([("output_format", "csv_export")]),
                "download_csv")

        if av_mode == "timeline":
            html.context_button(_("Availability"),
                                html.makeuri([("av_mode", "availability")]),
                                "availability")

        elif len(aggr_rows) == 1:
            aggr_name = aggr_rows[0]["aggr_name"]
            aggr_group = aggr_rows[0]["aggr_group"]
            timeline_url = html.makeuri([("av_mode", "timeline"),
                                         ("av_aggr_name", aggr_name),
                                         ("av_aggr_group", aggr_group)])
            html.context_button(_("Timeline"), timeline_url, "timeline")
        html.end_context_buttons()

        avoptions = render_availability_options("bi")

    timewarpcode = ""
    if not html.has_user_errors():
        countdown_logrow_limit = avoptions["logrow_limit"]
        has_reached_logrow_limit = False
        spans = []
        for aggr_row in aggr_rows:
            tree = aggr_row["aggr_tree"]
            reqhosts = tree["reqhosts"]
            try:
                timewarp = int(html.var("timewarp"))
            except:
                timewarp = None

            (these_spans, timewarp_tree_state), countdown_logrow_limit = \
                availability.get_bi_spans(tree, aggr_row["aggr_group"], avoptions, countdown_logrow_limit, timewarp)

            # We take only complete aggregations i.d. if we have
            # undershot the log row limit then we ignore the rest
            if avoptions["logrow_limit"] and countdown_logrow_limit < 0:
                has_reached_logrow_limit = True
                break

            spans += these_spans
            if timewarp and timewarp_tree_state:
                state, assumed_state, node, subtrees = timewarp_tree_state
                eff_state = state
                if assumed_state != None:
                    eff_state = assumed_state
                row = {
                    "aggr_tree": tree,
                    "aggr_treestate": timewarp_tree_state,
                    "aggr_state": state,  # state disregarding assumptions
                    "aggr_assumed_state":
                    assumed_state,  # is None, if there are no assumptions
                    "aggr_effective_state":
                    eff_state,  # is assumed_state, if there are assumptions, else real state
                    "aggr_name": node["title"],
                    "aggr_output": eff_state["output"],
                    "aggr_hosts": node["reqhosts"],
                    "aggr_function": node["func"],
                    "aggr_group": html.var("aggr_group"),
                }
                tdclass, htmlcode = bi.render_tree_foldable(
                    row,
                    boxes=False,
                    omit_root=False,
                    expansion_level=bi.load_ex_level(),
                    only_problems=False,
                    lazy=False)
                html.plug()
                # TODO: SOMETHING IS WRONG IN HERE (used to be the same situation in original code!)
                html.open_h3()

                # render icons for back and forth
                if int(these_spans[0]["from"]) == timewarp:
                    html.disabled_icon_button("back_off")
                have_forth = False
                previous_span = None
                for span in these_spans:
                    if int(span["from"]) == timewarp and previous_span != None:
                        html.icon_button(
                            html.makeuri([("timewarp",
                                           str(int(previous_span["from"])))]),
                            _("Jump one phase back"), "back")
                    elif previous_span and int(
                            previous_span["from"]
                    ) == timewarp and span != these_spans[-1]:
                        html.icon_button(
                            html.makeuri([("timewarp",
                                           str(int(span["from"])))]),
                            _("Jump one phase forth"), "forth")
                        have_forth = True
                    previous_span = span
                if not have_forth:
                    html.disabled_icon_button("forth_off")

                html.write(" &nbsp; ")
                html.icon_button(html.makeuri([("timewarp", "")]),
                                 _("Close Timewarp"), "closetimewarp")
                timewarpcode = html.drain()
                html.unplug()
                timewarpcode += '%s %s</h3>' % (_("Timewarp to "), time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timewarp))) + \
                               '<table class="data table timewarp"><tr class="data odd0"><td class="%s">' % tdclass + \
                               htmlcode + \
                               '</td></tr></table>'

        # Note: 'spans_by_object' returns two arguments which are used by
        # all availability views but not by BI. There we have to take
        # only complete aggregations
        av_rawdata = availability.spans_by_object(spans, None)[0]
        av_data = availability.compute_availability("bi", av_rawdata,
                                                    avoptions)

        # If we abolish the limit we have to fetch the data again
        # with changed logrow_limit = 0, which means no limit
        if has_reached_logrow_limit:
            text = _(
                "Your query matched more than %d log entries. "
                "<b>Note:</b> The number of shown rows does not necessarily reflect the "
                "matched entries and the result might be incomplete. "
            ) % avoptions["logrow_limit"]
            text += '<a href="%s">%s</a>' % \
                    (html.makeuri([("_unset_logrow_limit", "1")]), _('Repeat query without limit.'))
            html.show_warning(text)

        if html.output_format == "csv_export":
            output_availability_csv("bi", av_data, avoptions)
            return

        html.write(timewarpcode)
        do_render_availability("bi", av_rawdata, av_data, av_mode, None,
                               avoptions)  # ,  timewarpcode)

    html.bottom_footer()
    html.body_end()
Esempio n. 2
0
def render_bi_availability(title, aggr_rows):
    av_mode = html.var("av_mode", "availability")

    avoptions = get_availability_options_from_url("bi")
    time_range, range_title = avoptions["range"]

    if av_mode == "timeline":
        title = _("Timeline of ") + title
    else:
        title = _("Availability of ") + title

    if html.output_format != "csv_export":
        html.body_start(title, stylesheets=["pages","views","status", "bi"], javascripts=['bi'])
        html.top_heading(title)
        html.begin_context_buttons()
        togglebutton("avoptions", False, "painteroptions", _("Configure details of the report"))
        html.context_button(_("Status View"), html.makeuri([("mode", "status")]), "status")
        if config.reporting_available():
            html.context_button(_("Export as PDF"), html.makeuri([], filename="report_instant.py"), "report")
        if av_mode == "availability":
            html.context_button(_("Export as CSV"), html.makeuri([("output_format", "csv_export")]), "download_csv")

        if av_mode == "timeline":
            html.context_button(_("Availability"), html.makeuri([("av_mode", "availability")]), "availability")

        elif len(aggr_rows) == 1:
            aggr_name = aggr_rows[0]["aggr_name"]
            aggr_group = aggr_rows[0]["aggr_group"]
            timeline_url = html.makeuri([("av_mode", "timeline"), ("av_aggr_name", aggr_name), ("av_aggr_group", aggr_group)])
            html.context_button(_("Timeline"), timeline_url, "timeline")
        html.end_context_buttons()

        avoptions = render_availability_options("bi")

    timewarpcode = ""
    if not html.has_user_errors():
        spans = []
        for aggr_row in aggr_rows:
            tree = aggr_row["aggr_tree"]
            reqhosts = tree["reqhosts"]
            try:
                timewarp = int(html.var("timewarp"))
            except:
                timewarp = None
            these_spans, timewarp_tree_state = availability.get_bi_spans(tree, aggr_row["aggr_group"], avoptions, timewarp)
            spans += these_spans
            if timewarp and timewarp_tree_state:
                state, assumed_state, node, subtrees = timewarp_tree_state
                eff_state = state
                if assumed_state != None:
                    eff_state = assumed_state
                row = {
                        "aggr_tree"            : tree,
                        "aggr_treestate"       : timewarp_tree_state,
                        "aggr_state"           : state,          # state disregarding assumptions
                        "aggr_assumed_state"   : assumed_state,  # is None, if there are no assumptions
                        "aggr_effective_state" : eff_state,      # is assumed_state, if there are assumptions, else real state
                        "aggr_name"            : node["title"],
                        "aggr_output"          : eff_state["output"],
                        "aggr_hosts"           : node["reqhosts"],
                        "aggr_function"        : node["func"],
                        "aggr_group"           : html.var("aggr_group"),
                }
                tdclass, htmlcode = bi.render_tree_foldable(row, boxes=False, omit_root=False,
                                         expansion_level=bi.load_ex_level(), only_problems=False, lazy=False)
                html.plug()
                html.write('<h3>')

                # render icons for back and forth
                if int(these_spans[0]["from"]) == timewarp:
                    html.disabled_icon_button("back_off")
                have_forth = False
                previous_span = None
                for span in these_spans:
                    if int(span["from"]) == timewarp and previous_span != None:
                        html.icon_button(html.makeuri([("timewarp", str(int(previous_span["from"])))]), _("Jump one phase back"), "back")
                    elif previous_span and int(previous_span["from"]) == timewarp and span != these_spans[-1]:
                        html.icon_button(html.makeuri([("timewarp", str(int(span["from"])))]), _("Jump one phase forth"), "forth")
                        have_forth = True
                    previous_span = span
                if not have_forth:
                    html.disabled_icon_button("forth_off")

                html.write(" &nbsp; ")
                html.icon_button(html.makeuri([("timewarp", "")]), _("Close Timewarp"), "closetimewarp")
                timewarpcode = html.drain()
                html.unplug()
                timewarpcode += '%s %s</h3>' % (_("Timewarp to "), time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timewarp))) + \
                               '<table class="data table timewarp"><tr class="data odd0"><td class="%s">' % tdclass + \
                               htmlcode + \
                               '</td></tr></table>'

        av_rawdata = availability.spans_by_object(spans)
        av_data = availability.compute_availability("bi", av_rawdata, avoptions)

        if html.output_format == "csv_export":
            output_availability_csv("bi", av_data, avoptions)
            return

        html.write(timewarpcode)
        do_render_availability("bi", av_rawdata, av_data, av_mode, None, avoptions)# ,  timewarpcode)

    html.bottom_footer()
    html.body_end()
Esempio n. 3
0
def render_bi_availability(title, aggr_rows):
    av_mode = html.var("av_mode", "availability")

    avoptions = get_availability_options_from_url("bi")
    time_range, range_title = avoptions["range"]

    if av_mode == "timeline":
        title = _("Timeline of ") + title
    else:
        title = _("Availability of ") + title

    if html.output_format != "csv_export":
        html.body_start(title,
                        stylesheets=["pages", "views", "status", "bi"],
                        javascripts=['bi'])
        html.top_heading(title)
        html.begin_context_buttons()
        togglebutton("avoptions", False, "painteroptions",
                     _("Configure details of the report"))
        html.context_button(_("Status View"),
                            html.makeuri([("mode", "status")]), "status")
        if config.reporting_available() and config.may("general.reporting"):
            html.context_button(_("Export as PDF"),
                                html.makeuri([], filename="report_instant.py"),
                                "report")
        if av_mode == "availability":
            html.context_button(
                _("Export as CSV"),
                html.makeuri([("output_format", "csv_export")]),
                "download_csv")

        if av_mode == "timeline":
            html.context_button(_("Availability"),
                                html.makeuri([("av_mode", "availability")]),
                                "availability")

        elif len(aggr_rows) == 1:
            aggr_name = aggr_rows[0]["aggr_name"]
            aggr_group = aggr_rows[0]["aggr_group"]
            timeline_url = html.makeuri([("av_mode", "timeline"),
                                         ("av_aggr_name", aggr_name),
                                         ("av_aggr_group", aggr_group)])
            html.context_button(_("Timeline"), timeline_url, "timeline")
        html.end_context_buttons()

        avoptions = render_availability_options("bi")

    timewarpcode = ""
    if not html.has_user_errors():
        spans = []
        for aggr_row in aggr_rows:
            tree = aggr_row["aggr_tree"]
            reqhosts = tree["reqhosts"]
            try:
                timewarp = int(html.var("timewarp"))
            except:
                timewarp = None
            these_spans, timewarp_tree_state = availability.get_bi_spans(
                tree, aggr_row["aggr_group"], avoptions, timewarp)
            spans += these_spans
            if timewarp and timewarp_tree_state:
                state, assumed_state, node, subtrees = timewarp_tree_state
                eff_state = state
                if assumed_state != None:
                    eff_state = assumed_state
                row = {
                    "aggr_tree": tree,
                    "aggr_treestate": timewarp_tree_state,
                    "aggr_state": state,  # state disregarding assumptions
                    "aggr_assumed_state":
                    assumed_state,  # is None, if there are no assumptions
                    "aggr_effective_state":
                    eff_state,  # is assumed_state, if there are assumptions, else real state
                    "aggr_name": node["title"],
                    "aggr_output": eff_state["output"],
                    "aggr_hosts": node["reqhosts"],
                    "aggr_function": node["func"],
                    "aggr_group": html.var("aggr_group"),
                }
                tdclass, htmlcode = bi.render_tree_foldable(
                    row,
                    boxes=False,
                    omit_root=False,
                    expansion_level=bi.load_ex_level(),
                    only_problems=False,
                    lazy=False)
                html.plug()
                html.write('<h3>')

                # render icons for back and forth
                if int(these_spans[0]["from"]) == timewarp:
                    html.disabled_icon_button("back_off")
                have_forth = False
                previous_span = None
                for span in these_spans:
                    if int(span["from"]) == timewarp and previous_span != None:
                        html.icon_button(
                            html.makeuri([("timewarp",
                                           str(int(previous_span["from"])))]),
                            _("Jump one phase back"), "back")
                    elif previous_span and int(
                            previous_span["from"]
                    ) == timewarp and span != these_spans[-1]:
                        html.icon_button(
                            html.makeuri([("timewarp",
                                           str(int(span["from"])))]),
                            _("Jump one phase forth"), "forth")
                        have_forth = True
                    previous_span = span
                if not have_forth:
                    html.disabled_icon_button("forth_off")

                html.write(" &nbsp; ")
                html.icon_button(html.makeuri([("timewarp", "")]),
                                 _("Close Timewarp"), "closetimewarp")
                timewarpcode = html.drain()
                html.unplug()
                timewarpcode += '%s %s</h3>' % (_("Timewarp to "), time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timewarp))) + \
                               '<table class="data table timewarp"><tr class="data odd0"><td class="%s">' % tdclass + \
                               htmlcode + \
                               '</td></tr></table>'

        av_rawdata = availability.spans_by_object(spans)
        av_data = availability.compute_availability("bi", av_rawdata,
                                                    avoptions)

        if html.output_format == "csv_export":
            output_availability_csv("bi", av_data, avoptions)
            return

        html.write(timewarpcode)
        do_render_availability("bi", av_rawdata, av_data, av_mode, None,
                               avoptions)  # ,  timewarpcode)

    html.bottom_footer()
    html.body_end()
Esempio n. 4
0
def render_bi_availability(title, aggr_rows):
    av_mode = html.var("av_mode", "availability")

    avoptions = get_availability_options_from_url("bi")
    time_range, range_title = avoptions["range"]

    if av_mode == "timeline":
        title = _("Timeline of ") + title
    else:
        title = _("Availability of ") + title

    if html.output_format != "csv_export":
        html.body_start(title, stylesheets=["pages", "views", "status", "bi"], javascripts=["bi"])
        html.top_heading(title)
        html.begin_context_buttons()
        togglebutton("avoptions", False, "painteroptions", _("Configure details of the report"))
        html.context_button(_("Status View"), html.makeuri([("mode", "status")]), "status")
        if config.reporting_available():
            html.context_button(_("Export as PDF"), html.makeuri([], filename="report_instant.py"), "report")
        if av_mode == "availability":
            html.context_button(_("Export as CSV"), html.makeuri([("output_format", "csv_export")]), "download_csv")

        if av_mode == "timeline":
            html.context_button(_("Availability"), html.makeuri([("av_mode", "availability")]), "availability")

        elif len(aggr_rows) == 1:
            aggr_name = aggr_rows[0]["aggr_name"]
            aggr_group = aggr_rows[0]["aggr_group"]
            timeline_url = html.makeuri(
                [("av_mode", "timeline"), ("av_aggr_name", aggr_name), ("av_aggr_group", aggr_group)]
            )
            html.context_button(_("Timeline"), timeline_url, "timeline")
        html.end_context_buttons()

        avoptions = render_availability_options("bi")

    timewarpcode = ""
    if not html.has_user_errors():
        countdown_logrow_limit = avoptions["logrow_limit"]
        has_reached_logrow_limit = False
        spans = []
        for aggr_row in aggr_rows:
            tree = aggr_row["aggr_tree"]
            reqhosts = tree["reqhosts"]
            try:
                timewarp = int(html.var("timewarp"))
            except:
                timewarp = None

            (these_spans, timewarp_tree_state), countdown_logrow_limit = availability.get_bi_spans(
                tree, aggr_row["aggr_group"], avoptions, countdown_logrow_limit, timewarp
            )

            # We take only complete aggregations i.d. if we have
            # undershot the log row limit then we ignore the rest
            if avoptions["logrow_limit"] and countdown_logrow_limit < 0:
                has_reached_logrow_limit = True
                break

            spans += these_spans
            if timewarp and timewarp_tree_state:
                state, assumed_state, node, subtrees = timewarp_tree_state
                eff_state = state
                if assumed_state != None:
                    eff_state = assumed_state
                row = {
                    "aggr_tree": tree,
                    "aggr_treestate": timewarp_tree_state,
                    "aggr_state": state,  # state disregarding assumptions
                    "aggr_assumed_state": assumed_state,  # is None, if there are no assumptions
                    "aggr_effective_state": eff_state,  # is assumed_state, if there are assumptions, else real state
                    "aggr_name": node["title"],
                    "aggr_output": eff_state["output"],
                    "aggr_hosts": node["reqhosts"],
                    "aggr_function": node["func"],
                    "aggr_group": html.var("aggr_group"),
                }
                tdclass, htmlcode = bi.render_tree_foldable(
                    row,
                    boxes=False,
                    omit_root=False,
                    expansion_level=bi.load_ex_level(),
                    only_problems=False,
                    lazy=False,
                )
                html.plug()
                html.write("<h3>")

                # render icons for back and forth
                if int(these_spans[0]["from"]) == timewarp:
                    html.disabled_icon_button("back_off")
                have_forth = False
                previous_span = None
                for span in these_spans:
                    if int(span["from"]) == timewarp and previous_span != None:
                        html.icon_button(
                            html.makeuri([("timewarp", str(int(previous_span["from"])))]),
                            _("Jump one phase back"),
                            "back",
                        )
                    elif previous_span and int(previous_span["from"]) == timewarp and span != these_spans[-1]:
                        html.icon_button(
                            html.makeuri([("timewarp", str(int(span["from"])))]), _("Jump one phase forth"), "forth"
                        )
                        have_forth = True
                    previous_span = span
                if not have_forth:
                    html.disabled_icon_button("forth_off")

                html.write(" &nbsp; ")
                html.icon_button(html.makeuri([("timewarp", "")]), _("Close Timewarp"), "closetimewarp")
                timewarpcode = html.drain()
                html.unplug()
                timewarpcode += (
                    "%s %s</h3>" % (_("Timewarp to "), time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timewarp)))
                    + '<table class="data table timewarp"><tr class="data odd0"><td class="%s">' % tdclass
                    + htmlcode
                    + "</td></tr></table>"
                )

        # Note: 'spans_by_object' returns two arguments which are used by
        # all availability views but not by BI. There we have to take
        # only complete aggregations
        av_rawdata = availability.spans_by_object(spans, None)[0]
        av_data = availability.compute_availability("bi", av_rawdata, avoptions)

        # If we abolish the limit we have to fetch the data again
        # with changed logrow_limit = 0, which means no limit
        if has_reached_logrow_limit:
            text = (
                _(
                    "Your query matched more than %d log entries. "
                    "<b>Note:</b> The number of shown rows does not necessarily reflect the "
                    "matched entries and the result might be incomplete. "
                )
                % avoptions["logrow_limit"]
            )
            text += '<a href="%s">%s</a>' % (
                html.makeuri([("_unset_logrow_limit", "1")]),
                _("Repeat query without limit."),
            )
            html.show_warning(text)

        if html.output_format == "csv_export":
            output_availability_csv("bi", av_data, avoptions)
            return

        html.write(timewarpcode)
        do_render_availability("bi", av_rawdata, av_data, av_mode, None, avoptions)  # ,  timewarpcode)

    html.bottom_footer()
    html.body_end()