def _show_view_as_dashlet(self, view_spec: ViewSpec): html.add_body_css_class("view") html.open_div(id_="dashlet_content_wrapper") is_reload = html.request.has_var("_reload") view_display_options = "SIXLW" if not is_reload: view_display_options += "HR" html.request.set_var('display_options', view_display_options) html.request.set_var('_display_options', view_display_options) html.add_body_css_class('dashlet') # Need to be loaded before processing the painter_options below. # TODO: Make this dependency explicit display_options.load_from_html(html) painter_options = PainterOptions.get_instance() painter_options.load(self._dashlet_spec["name"]) view = views.View(self._dashlet_spec["name"], view_spec, self.context) view.row_limit = views.get_limit() view.only_sites = visuals.get_only_sites_from_context(self.context) view.user_sorters = views.get_user_sorters() views.process_view(views.GUIViewRenderer(view, show_buttons=False)) html.close_div()
def _show_view_as_dashlet(self, view_spec: ViewSpec): html.add_body_css_class("view") html.open_div(id_="dashlet_content_wrapper") is_reload = request.has_var("_reload") view_display_options = "SIXLW" if not is_reload: view_display_options += "HR" request.set_var("display_options", view_display_options) request.set_var("_display_options", view_display_options) html.add_body_css_class("dashlet") # Need to be loaded before processing the painter_options below. # TODO: Make this dependency explicit display_options.load_from_html(request, html) painter_options = PainterOptions.get_instance() painter_options.load(self._dashlet_spec["name"]) # Here the linked view default context has the highest priority # linkedview default>dashlet>url active filter, dashboard context = visuals.get_merged_context(self.context, view_spec["context"]) view = views.View(self._dashlet_spec["name"], view_spec, context) view.row_limit = views.get_limit() view.only_sites = visuals.get_only_sites_from_context(context) view.user_sorters = views.get_user_sorters() views.process_view(views.GUIViewRenderer(view, show_buttons=False)) html.close_div()
def paint_aggregated_tree_state(row, force_renderer_cls=None): if html.is_api_call(): return bi.render_tree_json(row) painter_options = PainterOptions.get_instance() treetype = painter_options.get("aggr_treetype") expansion_level = int(painter_options.get("aggr_expand")) only_problems = painter_options.get("aggr_onlyproblems") == "1" wrap_texts = painter_options.get("aggr_wrap") if force_renderer_cls: cls = force_renderer_cls elif treetype == "foldable": cls = bi.FoldableTreeRendererTree elif treetype in ["boxes", "boxes-omit-root"]: cls = bi.FoldableTreeRendererBoxes elif treetype == "bottom-up": cls = bi.FoldableTreeRendererBottomUp elif treetype == "top-down": cls = bi.FoldableTreeRendererTopDown else: raise NotImplementedError() renderer = cls( row, omit_root=(treetype == "boxes-omit-root"), expansion_level=expansion_level, only_problems=only_problems, lazy=True, wrap_texts=wrap_texts) return renderer.css_class(), renderer.render()
def render_mobile_dataset(rows, view, group_cells, cells, num_columns, show_checkboxes): if not html.mobile: html.show_error(_("This view can only be used in mobile mode.")) return painter_options = PainterOptions.get_instance() painter_options.set("ts_format", "both") for row in rows: html.open_table(class_="dataset") for cell in cells: _tdclass, content = cell.render(row) if not content: continue # Omit empty cells html.open_tr(class_="header") html.open_th() html.write(cell.title()) html.close_th() html.close_tr() html.open_tr(class_="data") cell.paint(row) html.close_tr() html.close_table() html.javascript( '$("table.dataset > tbody > tr.data > td").addClass("ui-shadow").not(".state").addClass("nonstatus");\n' '$("table.dataset > tbody > tr.data a").attr("data-ajax", "false");\n')
def _show_view_as_dashlet(self, view_spec): html.add_body_css_class("view") html.open_div(id_="dashlet_content_wrapper") is_reload = html.request.has_var("_reload") display_options = "SIXLW" if not is_reload: display_options += "HR" html.request.set_var('display_options', display_options) html.request.set_var('_display_options', display_options) html.add_body_css_class('dashlet') painter_options = PainterOptions.get_instance() painter_options.load(self._dashlet_spec["name"]) view = views.View(self._dashlet_spec["name"], view_spec, self.context) view.row_limit = views.get_limit() view.only_sites = visuals.get_only_sites_from_context(self.context) view.user_sorters = views.get_user_sorters() view_renderer = views.GUIViewRenderer(view, show_buttons=False) views.process_view(view, view_renderer) html.close_div()
def render_mobile_list(rows, view, group_cells, cells, num_columns, show_checkboxes): if not html.mobile: html.show_error(_("This view can only be used in mobile mode.")) return # Force relative timestamp always. This saves space. painter_options = PainterOptions.get_instance() painter_options.set("ts_format", "rel") html.open_ul(class_="mobilelist", **{"data-role": "listview"}) # Paint data rows for row in rows: html.open_li() rendered_cells = [cell.render(row) for cell in cells] if rendered_cells: # First cell (assumedly state) is left rendered_class, rendered_content = rendered_cells[0] html.open_p(class_=["ui-li-aside", "ui-li-desc", rendered_class]) html.write(rendered_content) html.close_p() if len(rendered_cells) > 1: content = HTML(" · ").join([ rendered_cell[1] for rendered_cell in rendered_cells[1:num_columns + 1] ]) html.h3(content) for rendered_cell, cell in zip( rendered_cells[num_columns + 1:], cells[num_columns + 1:]): rendered_class, rendered_content = rendered_cell html.open_p(class_="ui-li-desc") cell.paint_as_header() html.write_text(': ') html.open_span(class_=rendered_class) html.write(rendered_content) html.close_span() html.close_p() html.close_li() html.close_ul() html.javascript('$("ul.mobilelist a").attr("data-ajax", "false");')
def csv_export(self, rows, view, group_cells, cells): output_csv_headers(view) groups, unique_row_ids, matrix_cells = list( create_matrices(rows, group_cells, cells, num_columns=None))[0] value_counts, _row_majorities = self._matrix_find_majorities( rows, cells) painter_options = PainterOptions.get_instance() with table_element(output_format="csv") as table: for cell_nr, cell in enumerate(group_cells): table.row() table.cell("", cell.title(use_short=False)) for _group, group_row in groups: _tdclass, content = cell.render(group_row) table.cell("", content) for rid in unique_row_ids: # Omit rows where all cells have the same values if painter_options.get("matrix_omit_uniform"): at_least_one_different = False for counts in value_counts[rid].values(): if len(counts) > 1: at_least_one_different = True break if not at_least_one_different: continue table.row() _tdclass, content = cells[0].render( list(matrix_cells[rid].values())[0]) table.cell("", content) for group_id, group_row in groups: table.cell("") cell_row = matrix_cells[rid].get(group_id) if cell_row is not None: for cell_nr, cell in enumerate(cells[1:]): _tdclass, content = cell.render(cell_row) if cell_nr: html.write_text(",") html.write(content)
def update(self): is_reload = html.request.has_var("_reload") display_options = "SIXLW" if not is_reload: display_options += "HR" html.request.set_var('display_options', display_options) html.request.set_var('_display_options', display_options) html.add_body_css_class('dashlet') painter_options = PainterOptions.get_instance() painter_options.load(self._dashlet_spec["name"]) view = views.View(self._dashlet_spec["name"], self._dashlet_spec) view.row_limit = views.get_limit() view.only_sites = views.get_only_sites() view.user_sorters = views.get_user_sorters() view_renderer = views.GUIViewRenderer(view, show_buttons=False) views.show_view(view, view_renderer)
def render_mobile_table(rows, view, group_cells, cells, num_columns, show_checkboxes): if not is_mobile(request, response): html.show_error(_("This view can only be used in mobile mode.")) return # Force relative timestamp always. This saves space. painter_options = PainterOptions.get_instance() painter_options.set("ts_format", "rel") odd = "odd" html.open_table(class_="mobile data") # Paint header if view.get("column_headers") != "off": html.open_tr() n = 0 for cell in cells: cell.paint_as_header() html.close_tr() # Paint data rows for row in rows: odd = "even" if odd == "odd" else "odd" html.open_tr(class_="%s0" % odd) for n, cell in enumerate(cells): if n > 0 and n % num_columns == 0: html.close_tr() html.open_tr(class_="%s0" % odd) if n == len(cells) - 1 and n % num_columns != (num_columns - 1): colspan = num_columns - (n % num_columns) else: colspan = None cell.paint(row, colspan=colspan) html.close_row() html.close_table() html.javascript('$("table.mobile a").attr("data-ajax", "false");')
def paint_time_graph_cmk(row, cell, override_graph_render_options=None): graph_identification = ("template", { "site": row["site"], "host_name": row["host_name"], "service_description": row.get("service_description", "_HOST_"), }) # Load the graph render options from # a) the painter parameters configured in the view # b) the painter options set per user and view painter_params = cell.painter_parameters() painter_params = _transform_old_graph_render_options(painter_params) graph_render_options = painter_params["graph_render_options"] if override_graph_render_options is not None: graph_render_options.update(override_graph_render_options) painter_options = PainterOptions.get_instance() options = painter_options.get_without_default("graph_render_options") if options is not None: graph_render_options.update(options) graph_data_range = {} now = time.time() if "set_default_time_range" in painter_params: duration = painter_params["set_default_time_range"] graph_data_range["time_range"] = now - duration, now else: graph_data_range["time_range"] = now - 3600 * 4, now # Load timerange from painter option (overrides the defaults, if set by the user) painter_option_pnp_timerange = painter_options.get_without_default( "pnp_timerange") if painter_option_pnp_timerange is not None: graph_data_range[ "time_range"] = get_graph_timerange_from_painter_options() if is_mobile(request, response): graph_render_options.update({ "interaction": False, "show_controls": False, "show_pin": False, "show_graph_time": False, "show_time_range_previews": False, "show_legend": False, # Would be much better to autodetect the possible size (like on dashboard) "size": (27, 18), # ex }) if "host_metrics" in row: available_metrics = row["host_metrics"] perf_data = row["host_perf_data"] else: available_metrics = row["service_metrics"] perf_data = row["service_perf_data"] if not available_metrics and perf_data: return "", _( "No historic metrics recorded but performance data is available. " "Maybe performance data processing is disabled.") return "", html_render.render_graphs_from_specification_html( graph_identification, graph_data_range, graph_render_options)
def render(self, rows, view, group_cells, cells, num_columns, show_checkboxes): header_majorities = self._matrix_find_majorities_for_header( rows, group_cells) value_counts, row_majorities = self._matrix_find_majorities( rows, cells) painter_options = PainterOptions.get_instance() for groups, unique_row_ids, matrix_cells in \ create_matrices(rows, group_cells, cells, num_columns): # Paint the matrix. Begin with the group headers html.open_table(class_="data matrix") odd = "odd" for cell_nr, cell in enumerate(group_cells): odd = "even" if odd == "odd" else "odd" html.open_tr(class_="data %s0" % odd) html.open_td(class_="matrixhead") html.write(cell.title(use_short=False)) html.close_td() for _group, group_row in groups: tdclass, content = cell.render(group_row) if cell_nr > 0: gv = group_value(group_row, [cell]) majority_value = header_majorities.get( cell_nr - 1, None) if majority_value is not None and majority_value != gv: tdclass += " minority" html.open_td(class_=["left", tdclass]) html.write(content) html.close_td() html.close_tr() # Now for each unique service^H^H^H^H^H^H ID column paint one row for rid in unique_row_ids: # Omit rows where all cells have the same values if painter_options.get("matrix_omit_uniform"): at_least_one_different = False for counts in value_counts[rid].values(): if len(counts) > 1: at_least_one_different = True break if not at_least_one_different: continue odd = "even" if odd == "odd" else "odd" html.open_tr(class_="data %s0" % odd) tdclass, content = cells[0].render( list(matrix_cells[rid].values())[0]) html.open_td(class_=["left", tdclass]) html.write(content) html.close_td() # Now go through the groups and paint the rest of the # columns for group_id, group_row in groups: cell_row = matrix_cells[rid].get(group_id) if cell_row is None: html.td('') else: if len(cells) > 2: html.open_td(class_="cell") html.open_table() for cell_nr, cell in enumerate(cells[1:]): tdclass, content = cell.render(cell_row) gv = group_value(cell_row, [cell]) majority_value = row_majorities[rid].get( cell_nr, None) if majority_value is not None and majority_value != gv: tdclass += " minority" if len(cells) > 2: html.open_tr() html.open_td(class_=tdclass) html.write(content) html.close_td() if len(cells) > 2: html.close_tr() if len(cells) > 2: html.close_table() html.close_td() html.close_tr() html.close_table()