def render(self, row, cell): classes = ["perfometer"] if is_stale(row): classes.append("stale") try: title, h = Perfometer(row).render() if title is None and h is None: return "", "" except Exception as e: logger.exception("error rendering performeter") if config.debug: raise return " ".join(classes), _("Exception: %s") % e content = html.render_div(HTML(h), class_=["content"]) \ + html.render_div(title, class_=["title"]) \ + html.render_div("", class_=["glass"]) # pnpgraph_present: -1 means unknown (path not configured), 0: no, 1: yes if display_options.enabled(display_options.X) \ and row["service_pnpgraph_present"] != 0: url = cmk_graph_url(row, "service") disabled = False else: url = "javascript:void(0)" disabled = True return " ".join(classes), \ html.render_a(content=content, href=url, title=escaping.strip_tags(title), class_=["disabled" if disabled else None])
def render(self, what, row, tags, custom_vars): if is_stale(row): if what == "host": title = _("This host is stale") else: title = _("This service is stale") title += _(", no data has been received within the last %.1f check periods" ) % config.staleness_threshold return 'stale', title
def calculate_view_grouping_of_services(rows, row_group_cells): if not config.service_view_grouping: return {}, rows # First create dictionaries for each found group containing the # group spec and the row indizes of the grouped rows groups = {} current_group = None group_id = None last_row_group = None for index, (rid, row) in enumerate(rows[:]): group_spec = try_to_match_group(row) if not group_spec: current_group = None continue # New row groups need to separate the view groups. There is no folding allowed # between row groups (e.g. services of different hosts when the host is a group cell) if row_group_cells: this_row_group = group_value(row, row_group_cells) if this_row_group != last_row_group: group_id = rid last_row_group = this_row_group if current_group is None: group_id = rid elif current_group != group_spec: group_id = rid groups.setdefault(group_id, (group_spec, [])) # When the service is not OK and should not be grouped, move it's row # in front of the group. if row.get("service_state", -1) != 0 or is_stale(row): if current_group is None or current_group != group_spec: continue # skip grouping first row elif current_group == group_spec: row = rows.pop(index) rows.insert(index - len(groups[group_id][1]), row) continue current_group = group_spec groups[group_id][1].append(rid) # Now create the final structure as described above groupings = {} for group_id, (group_spec, row_indizes) in groups.items(): if len(row_indizes) >= group_spec.get("min_items", 2): groupings[row_indizes[0]] = group_spec, len(row_indizes) return groupings, rows
def _render_group(self, rows_with_ids, header, view, group_cells, cells, num_columns, show_checkboxes): repeat_heading_every = 20 # in case column_headers is "repeat" html.open_table(class_="groupheader", cellspacing=0, cellpadding=0, border=0) html.open_tr(class_="groupheader") painted = False for cell in group_cells: if painted: html.td(", ") painted = cell.paint(rows_with_ids[0][1]) html.close_tr() html.close_table() html.open_table(class_="data") odd = "odd" column_headers = view.get("column_headers") if column_headers != "off": self._show_header_line(cells, show_checkboxes) groups, rows_with_ids = calculate_view_grouping_of_services( rows_with_ids, row_group_cells=None) visible_row_number = 0 group_hidden, num_grouped_rows = None, 0 for index, row in rows_with_ids: if view.get("column_headers") == "repeat": if visible_row_number > 0 and visible_row_number % repeat_heading_every == 0: self._show_header_line(cells, show_checkboxes) visible_row_number += 1 odd = "even" if odd == "odd" else "odd" # state = row.get("service_state", row.get("aggr_state")) state = utils.saveint(row.get("service_state")) if state is None: state = utils.saveint(row.get("host_state", 0)) if state > 0: state += 1 # 1 is critical for hosts num_cells = len(cells) if index in groups: group_spec, num_grouped_rows = groups[index] group_hidden = grouped_row_title(index, group_spec, num_grouped_rows, odd, num_cells) odd = "even" if odd == "odd" else "odd" css_classes = [] if is_stale(row): css_classes.append("stale") hide = "" if num_grouped_rows > 0: num_grouped_rows -= 1 if group_hidden: hide = "display:none" if group_hidden is not None and num_grouped_rows == 0: # last row in group css_classes.append("group_end") group_hidden = None css_classes.append("%s%d" % (odd, state)) html.open_tr(class_=["data"] + css_classes, style=hide) if show_checkboxes: render_checkbox_td(view, row, num_cells) for cell in cells: cell.paint(row) html.close_tr() html.close_table() init_rowselect(view)
def _render_group(self, rows_with_ids, header, view, group_cells, cells, num_columns, show_checkboxes): repeat_heading_every = 20 # in case column_headers is "repeat" if group_cells: self._show_group_header_table(group_cells, rows_with_ids[0][1]) html.open_table(class_="data") odd = "odd" column_headers = view.get("column_headers") if column_headers != "off": self._show_header_line(cells, show_checkboxes) groups, rows_with_ids = calculate_view_grouping_of_services( rows_with_ids, row_group_cells=None) visible_row_number = 0 group_hidden, num_grouped_rows = None, 0 for index, row in rows_with_ids: if view.get("column_headers") == "repeat": if visible_row_number > 0 and visible_row_number % repeat_heading_every == 0: self._show_header_line(cells, show_checkboxes) visible_row_number += 1 odd = "even" if odd == "odd" else "odd" # state = row.get("service_state", row.get("aggr_state")) state = utils.saveint(row.get("service_state")) if state is None: state = utils.saveint(row.get("host_state", 0)) if state > 0: state += 1 # 1 is critical for hosts num_cells = len(cells) if index in groups: group_spec, num_grouped_rows = groups[index] group_hidden = grouped_row_title(index, group_spec, num_grouped_rows, odd, num_cells) odd = "even" if odd == "odd" else "odd" css_classes = [] if is_stale(row): css_classes.append("stale") hide = "" if num_grouped_rows > 0: num_grouped_rows -= 1 if group_hidden: hide = "display:none" if group_hidden is not None and num_grouped_rows == 0: # last row in group css_classes.append("group_end") group_hidden = None css_classes.append("%s%d" % (odd, state)) html.open_tr(class_=["data"] + css_classes, style=hide) if show_checkboxes: render_checkbox_td(view, row, num_cells) for cell in cells: cell.paint(row) html.close_tr() html.close_table() # Don't make rows selectable when no commands can be fired # Ignore "C" display option here. Otherwise the rows will not be selectable # after view reload. if not user.may("general.act"): return init_rowselect(_get_view_name(view))