def _breadcrumb(self, title: str) -> Breadcrumb: breadcrumb = make_host_breadcrumb(self._request.host.name()) breadcrumb.append( BreadcrumbItem( title=title, url="javascript:document.location.reload(false)", )) return breadcrumb
def _show_file_breadcrumb(host_name: HostName, title: str) -> Breadcrumb: breadcrumb = make_host_breadcrumb(host_name) breadcrumb.append( BreadcrumbItem( title=_("Log files of host %s") % host_name, url=makeuri(request, [("file", "")]), )) breadcrumb.append(make_current_page_breadcrumb_item(title)) return breadcrumb
def _show_file_breadcrumb(host_name: HostName, title: str) -> Breadcrumb: breadcrumb = make_host_breadcrumb(host_name) breadcrumb.append( BreadcrumbItem( title=_("Log files of host %s") % host_name, url=html.makeuri([('file', '')]), )) breadcrumb.append(make_current_page_breadcrumb_item(title)) return breadcrumb
def show_host_log_list(site, host_name): title = _("Logfiles of host %s") % host_name html.header(title, make_host_breadcrumb(host_name)) html.begin_context_buttons() html.context_button(_("Services"), services_url(site, host_name), 'services') button_all_logfiles() html.context_button(_("Analyze host patterns"), analyse_url(site, host_name), 'analyze') ack_button(site, host_name) html.end_context_buttons() html.open_table(class_=["data"]) list_logs(site, host_name, logfiles_of_host(site, host_name)) html.close_table() html.footer()
def do_log_ack(site, host_name, file_name): logs_to_ack = [] if not host_name and not file_name: # all logs on all hosts for this_site, this_host, logs in all_logs(): for int_filename in logs: file_display = form_file_to_ext(int_filename) logs_to_ack.append( (this_site, this_host, int_filename, file_display)) ack_msg = _('all logfiles on all hosts') elif host_name and not file_name: # all logs on one host for int_filename in logfiles_of_host(site, host_name): file_display = form_file_to_ext(int_filename) logs_to_ack.append((site, host_name, int_filename, file_display)) ack_msg = _('all logfiles of host %s') % host_name elif host_name and file_name: # one log on one host int_filename = form_file_to_int(file_name) logs_to_ack = [(site, host_name, int_filename, form_file_to_ext(int_filename))] ack_msg = _('the log file %s on host %s') % (file_name, host_name) else: for this_site, this_host, logs in all_logs(): file_display = form_file_to_ext(file_name) if file_name in logs: logs_to_ack.append( (this_site, this_host, file_name, file_display)) ack_msg = _('log file %s on all hosts') % file_name title = _("Acknowledge %s") % html.render_text(ack_msg) if host_name: breadcrumb = make_host_breadcrumb(host_name) else: breadcrumb = make_simple_page_breadcrumb(MegaMenuMonitoring, title) html.header(title, breadcrumb) html.begin_context_buttons() button_all_logfiles() if host_name: html.context_button(_("All Logfiles of Host"), html.makeuri([('file', '')])) if host_name and file_name: html.context_button(_("Back to Logfile"), html.makeuri([])) html.end_context_buttons() ack = html.request.var('_ack') if not html.confirm( _("Do you really want to acknowledge %s by <b>deleting</b> all stored messages?" ) % ack_msg): html.footer() return if not config.user.may("general.act"): html.h1(_('Permission denied'), class_=["error"]) html.div(_('You are not allowed to acknowledge %s') % ack_msg, class_=["error"]) html.footer() return # filter invalid values if ack != '1': raise MKUserError('_ack', _('Invalid value for ack parameter.')) for this_site, this_host, int_filename, display_name in logs_to_ack: try: acknowledge_logfile(this_site, this_host, int_filename, display_name) except Exception as e: html.show_error( _('The log file <tt>%s</tt> of host <tt>%s</tt> could not be deleted: %s.' ) % (display_name, this_host, e)) html.footer() return html.show_message('<b>%s</b><p>%s</p>' % (_('Acknowledged %s') % ack_msg, _('Acknowledged all messages in %s.') % ack_msg)) html.footer()
def show_file(site, host_name, file_name): int_filename = form_file_to_int(file_name) title = _("Logfiles of Host %s: %s") % (host_name, file_name) html.header(title, make_host_breadcrumb(host_name)) html.begin_context_buttons() html.context_button(_("Services"), services_url(site, host_name), 'services') html.context_button(_("All Logfiles of Host"), html.makeuri([('file', '')])) button_all_logfiles() html.context_button(_("Analyze patterns"), analyse_url(site, host_name, file_name), 'analyze') if html.request.var('_hidecontext', 'no') == 'yes': hide_context_label = _('Show Context') hide_context_param = 'no' hide = True else: hide_context_label = _('Hide Context') hide_context_param = 'yes' hide = False try: log_chunks = parse_file(site, host_name, int_filename, hide) except Exception as e: if config.debug: raise html.end_context_buttons() html.show_error(_("Unable to show logfile: <b>%s</b>") % e) html.footer() return if log_chunks is None: html.end_context_buttons() html.show_error(_("The logfile does not exist.")) html.footer() return if log_chunks == []: html.end_context_buttons() html.show_message( _("This logfile contains no unacknowledged messages.")) html.footer() return ack_button(site, host_name, int_filename) html.context_button(hide_context_label, html.makeuri([('_hidecontext', hide_context_param)])) html.end_context_buttons() html.open_div(id_="logwatch") for log in log_chunks: html.open_div(class_=["chunk"]) html.open_table(class_=["section"]) html.open_tr() html.td(form_level(log['level']), class_=form_level(log['level'])) html.td(form_datetime(log['datetime']), class_="date") html.close_tr() html.close_table() for line in log['lines']: html.open_p(class_=line['class']) html.icon_button( analyse_url(site, host_name, file_name, line['line']), _("Analyze this line"), "analyze") html.write_text(line['line'].replace(" ", " ").replace( "\1", "<br>")) html.close_p() html.close_div() html.close_div() html.footer()
def _host_log_list_breadcrumb(host_name: HostName, title: str) -> Breadcrumb: breadcrumb = make_host_breadcrumb(host_name) breadcrumb.append(make_current_page_breadcrumb_item(title)) return breadcrumb