def _forge_tooltip_and_url(self, time_frame, properties, context): mode_properties = properties["render_mode"][1] time_range = self._int_time_range_from_rangespec( mode_properties["time_range"]) ending_timestamp = min(time_frame["ending_timestamp"], time_range[1]) from_time_str = date_and_time(time_frame["timestamp"]) to_time_str = date_and_time(ending_timestamp) # TODO: Can this be simplified by passing a list as argument to html.render_table()? tooltip = html.render_table( html.render_tr( html.render_td(_("From:")) + html.render_td(from_time_str)) + html.render_tr( html.render_td(_("To:")) + html.render_td(to_time_str)) + html.render_tr( html.render_td("%ss:" % properties["log_target"].capitalize()) + html.render_td(time_frame["value"]))) args: HTTPVariables = [] # Generic filters args.append(("filled_in", "filter")) args.append(("_show_filter_form", "0")) args.append(("view_name", "events")) args.append(("logtime_from", str(time_frame["timestamp"]))) args.append(("logtime_from_range", "unix")) args.append(("logtime_until", str(ending_timestamp))) args.append(("logtime_until_range", "unix")) args.append(("logclass%d" % self.log_class, "on")) # Only include "end user notitification entries. Exclude entries related to the internal # raw notification events. args.append(("is_log_notification_phase", "0")) if properties["log_target"] in ("host", "both"): #args.append(("logst_h0", "on")) args.append(("logst_h1", "on")) args.append(("logst_h2", "on")) if properties["log_target"] in ("service", "both"): #args.append(("logst_s0", "on")) args.append(("logst_s1", "on")) args.append(("logst_s2", "on")) args.append(("logst_s3", "on")) # Exclude e.g. "SERVICE NOTIFICATION RESULT" type args.append( ("log_type", self._get_log_type_expr(properties["log_target"]))) # Context for fil in context.values(): for k, f in fil.items(): args.append((k, f)) return tooltip, makeuri_contextless(request, args, filename="view.py")
def _display_log(self, log): with table_element(css="data wato auditlog audit", limit=None, sortable=False, searchable=False) as table: for entry in log: table.row() table.cell(_("Time"), html.render_nobr( render.date_and_time(float(entry.time))), css="narrow") user = ( '<i>%s</i>' % _('internal')) if entry.user_id == '-' else entry.user_id table.cell(_("User"), html.render_text(user), css="nobreak narrow") table.cell(_("Object type"), entry.object_ref.object_type.name if entry.object_ref else "", css="narrow") table.cell(_("Object"), render_object_ref(entry.object_ref) or "", css="narrow") text = escaping.escape_text(entry.text).replace("\n", "<br>\n") table.cell(_("Summary"), text) if self._show_details: diff_text = entry.diff_text.replace( "\n", "<br>\n") if entry.diff_text else "" table.cell(_("Details"), diff_text)
def _create_scatter_elements(cls, properties, context): columns, data_rows = cls._get_data(properties, context) # type: ignore[call-arg] elements = [] metric_name = get_metric_info(properties["metric"], 0)[0]["title"] for row in data_rows: d_row = dict(zip(columns, row)) series = merge_multicol(d_row, columns, properties) site, host = row[:2] for ts, elem in series.time_data_pairs(): if elem: elements.append({ "timestamp": ts, "value": round(elem, 3), "tag": "scatter", "label": host, "url": cls._create_url_to_service_view( site, host, metric_name), "tooltip": "%s on %s: %.2f" % (host, date_and_time(ts), elem), }) return elements
def _change_table(self): with table_element("changes", sortable=False, searchable=False, css="changes", limit=None, empty_text=_("Currently there are no changes to activate.")) as table: for _change_id, change in reversed(self._changes): css = [] if self._is_foreign(change): css.append("foreign") if not config.user.may("wato.activateforeign"): css.append("not_permitted") table.row(css=" ".join(css)) table.cell(_("Object"), css="narrow nobr") rendered = render_object_ref(change["object"]) if rendered: html.write(rendered) table.cell(_("Time"), render.date_and_time(change["time"]), css="narrow nobr") table.cell(_("User"), css="narrow nobr") html.write_text(change["user_id"] if change["user_id"] else "") if self._is_foreign(change): html.icon("foreign_changes", _("This change has been made by another user")) table.cell(_("Change"), change["text"]) table.cell(_("Affected sites"), css="affected_sites") if self._affects_all_sites(change): html.write_text("<i>%s</i>" % _("All sites")) else: html.write_text(", ".join(sorted(change["affected_sites"])))
def _expire_logfiles(settings: Settings, config: Config, logger: Logger, lock_history: threading.Lock, flush: bool) -> None: with lock_history: try: days = config["history_lifetime"] min_mtime = time.time() - days * 86400 logger.log(VERBOSE, "Expiring logfiles (Horizon: %d days -> %s)", days, date_and_time(min_mtime)) for path in settings.paths.history_dir.value.glob('*.log'): if flush or path.stat().st_mtime < min_mtime: logger.info("Deleting log file %s (age %s)" % (path, date_and_time(path.stat().st_mtime))) path.unlink() except Exception as e: if settings.options.debug: raise logger.exception("Error expiring log files: %s" % e)
def _forge_tooltip_and_url(self, time_frame, properties, context): mode_properties = properties["render_mode"][1] time_range = self._int_time_range_from_rangespec( mode_properties["time_range"]) ending_timestamp = min(time_frame["ending_timestamp"], time_range[1]) from_time_str = date_and_time(time_frame["timestamp"]) to_time_str = date_and_time(ending_timestamp) # TODO: Can this be simplified by passing a list as argument to html.render_table()? tooltip = html.render_table( html.render_tr( html.render_td(_("From:")) + html.render_td(from_time_str)) + html.render_tr( html.render_td(_("To:")) + html.render_td(to_time_str)) + html.render_tr( html.render_td("%ss:" % properties["log_target"].capitalize()) + html.render_td(time_frame["value"]))) args: HTTPVariables = [] # Generic filters args.append(("filled_in", "filter")) args.append(("view_name", "events")) args.append(("logtime_from", str(time_frame["timestamp"]))) args.append(("logtime_from_range", "unix")) args.append(("logtime_until", str(ending_timestamp))) args.append(("logtime_until_range", "unix")) args.append(("logclass%d" % self.log_class, "on")) # Target filters if properties["log_target"] == "host": args.append(("logst_h0", "on")) args.append(("logst_h1", "on")) args.append(("logst_h2", "on")) elif properties["log_target"] == "service": args.append(("logst_s0", "on")) args.append(("logst_s1", "on")) args.append(("logst_s2", "on")) args.append(("logst_s3", "on")) # Context for fil in context.values(): for k, f in fil.items(): args.append((k, f)) return tooltip, makeuri_contextless(request, args, filename="view.py")
def _create_tooltip(cls, timestamp, host_to_value_dict, additional_rows=None): table_rows = sorted(host_to_value_dict.items(), key=lambda item: item[1]) + additional_rows table_html = "" # TODO: cleanup str casting for a, b in table_rows: table_html += str(html.render_tr(html.render_td(a) + html.render_td(b))) table_html = str(html.render_table(table_html)) tooltip = html.render_div(date_and_time(timestamp)) + table_html return tooltip
def _display_log(self, log): with table_element(css="data wato auditlog audit", limit=None, sortable=False, searchable=False) as table: for t, linkinfo, user, _action, text in log: table.row() table.cell(_("Object"), self._render_logfile_linkinfo(linkinfo)) table.cell(_("Time"), html.render_nobr(render.date_and_time(float(t)))) user = ('<i>%s</i>' % _('internal')) if user == '-' else user table.cell(_("User"), html.render_text(user), css="nobreak") # This must not be attrencoded: The entries are encoded when writing to the log. table.cell(_("Change"), text.replace("\\n", "<br>\n"), css="fill")
def _change_table(self): with table_element( "changes", title=_("Pending changes (%s)") % self._get_amount_changes(), sortable=False, searchable=False, css="changes", limit=None, empty_text=_("Currently there are no changes to activate."), foldable=Foldable.FOLDABLE_STATELESS, ) as table: for _change_id, change in reversed(self._changes): css = [] if self._is_foreign(change): css.append("foreign") if not user.may("wato.activateforeign"): css.append("not_permitted") table.row(css=" ".join(css)) table.cell("", css="buttons") rendered = render_object_ref_as_icon(change["object"]) if rendered: html.write_html(rendered) table.cell(_("Time"), render.date_and_time(change["time"]), css="narrow nobr") table.cell(_("User"), css="narrow nobr") html.write_text(change["user_id"] if change["user_id"] else "") if self._is_foreign(change): html.icon("foreign_changes", _("This change has been made by another user")) # Text is already escaped (see ActivateChangesWriter._add_change_to_site). We have # to handle this in a special way because of the SiteChanges file format. Would be # cleaner to transport the text type (like AuditLogStore is doing it). table.cell(_("Change"), HTML(change["text"])) table.cell(_("Affected sites"), css="affected_sites") if self._affects_all_sites(change): html.write_text("<i>%s</i>" % _("All sites")) else: html.write_text(", ".join(sorted( change["affected_sites"])))
def message(): text = _("The configuration is currently in read only mode. ") if config.wato_read_only["enabled"] is True: text += _( "The read only mode is enabled until it is turned of manually. ") elif isinstance(config.wato_read_only['enabled'], tuple): end_time = config.wato_read_only['enabled'][1] text += _("The read only mode is enabled until %s. " ) % render.date_and_time(end_time) if may_override(): text += _("But you are allowed to make changes anyway. ") text += "<br><br>" + _("Reason: %s") % config.wato_read_only["message"] return text
def _create_scatter_elements(cls, data_rows, properties): elements = [] for row in data_rows: start, _end, step = row[-1][:3] site, host = row[:2] service = properties["service"] for i, elem in enumerate(row[-1][3:]): if elem: if elem > 20: continue ts = start + i * step elements.append({ "timestamp": ts, "value": round(elem, 3), "tag": "scatter", "label": row[1], "url": cls._create_url_to_service_view(site, host, service), "tooltip": "%s on %s: %.2f" % (row[1], date_and_time(ts), elem), }) return elements