def test_availability_percentage_only_option(monkeypatch, what, group_title, availability_table, avoptions, result): monkeypatch.setattr("cmk.gui.availability.get_object_cells", lambda what, av, lab: 0) assert layout_availability_table(what, group_title, availability_table, avoptions) == result
def _output_availability_csv(what, av_data, avoptions): # type: (AVObjectType, AVData, AVOptions) -> None def cells_from_row(table, group_titles, group_cells, object_titles, cell_titles, row_object, row_cells): # type: (Table, List[Text], List[Text], List[Text], List[Text], AVObjectCells, AVRowCells) -> None for column_title, group_title in zip(group_titles, group_cells): table.cell(column_title, group_title) for title, (name, _url) in zip(object_titles, row_object): table.cell(title, name) for (title, _help), (text, _css) in zip(cell_titles, row_cells): table.cell(title, text) _av_output_set_content_disposition("Checkmk-Availability") availability_tables = availability.compute_availability_groups( what, av_data, avoptions) with table_element("av_items", output_format="csv") as table: for group_title, availability_table in availability_tables: av_table = availability.layout_availability_table( what, group_title, availability_table, avoptions) pad = 0 if group_title: group_titles, group_cells = [_("Group")], [group_title] else: group_titles, group_cells = [], [] for row in av_table["rows"]: table.row() cells_from_row( table, group_titles, group_cells, av_table["object_titles"], av_table["cell_titles"], row["object"], row["cells"], ) # presumably all rows have the same width pad = len(row["object"]) - 1 table.row() if "summary" in av_table: row_object = [(_("Summary"), "")] # type: AVObjectCells row_object += [(u"", "")] * pad cells_from_row( table, group_titles, group_cells, av_table["object_titles"], av_table["cell_titles"], row_object, av_table["summary"], )
def render_availability_table(group_title, availability_table, what, avoptions): av_table = availability.layout_availability_table(what, group_title, availability_table, avoptions) # TODO: If summary line is activated, then sorting should now move that line to the # top. It should also stay at the bottom. This would require an extension to the # table.py module. with table_element("av_items", av_table["title"], css="availability", searchable=False, limit=None, omit_headers="omit_headers" in avoptions["labelling"]) as table: show_urls, show_timeline = False, False for row in av_table["rows"]: table.row() # Column with icons timeline_url = None if row["urls"]: show_urls = True table.cell("", css="buttons") for image, tooltip, url in row["urls"]: html.icon_button(url, tooltip, image) if image == "timeline": timeline_url = url # Column with host/service or aggregate name for title, (name, url) in zip(av_table["object_titles"], row["object"]): table.cell(title, html.render_a(name, url)) if "timeline" in row: show_timeline = True table.cell(_("Timeline"), css="timeline") html.open_a(href=timeline_url) render_timeline_bar(row["timeline"], "inline") html.close_a() # Columns with the actual availability data for (title, help_txt), (text, css) in zip(av_table["cell_titles"], row["cells"]): table.cell(title, text, css=css, help_txt=help_txt) if "summary" in av_table: table.row(css="summary", fixed=True) if show_urls: table.cell("", "") # Empty cell in URLs column table.cell("", _("Summary"), css="heading") for _x in xrange(1, len(av_table["object_titles"])): table.cell("", "") # empty cells, of more object titles than one if show_timeline: table.cell("", "") for (title, help_txt), (text, css) in zip(av_table["cell_titles"], av_table["summary"]): table.cell(title, text, css="heading " + css, help_txt=help_txt)