def show_crash_report(info): html.h2(_("Crash Report")) html.open_table(class_="data") _crash_row(_("Crash Type"), info["crash_type"], odd=False, legend=True) _crash_row( _("Time"), time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(info["time"])), odd=True) _crash_row(_("Operating System"), info["os"], False) if info["crash_type"] == "cma": version_title = _("CMA Version") else: version_title = _("Check_MK Version") _crash_row(version_title, info["version"], True) _crash_row(_("Edition"), info.get("edition", ""), False) _crash_row(_("Core"), info.get("core", ""), True) _crash_row(_("Python Version"), info.get("python_version", _("Unknown")), False) _crash_row( _("Exception"), "%s (%s)" % (info["exc_type"], info["exc_value"]), odd=True, pre=True) _crash_row(_("Traceback"), format_traceback(info["exc_traceback"]), odd=False, pre=True) _crash_row( _("Local Variables"), format_local_vars(info["local_vars"]) if "local_vars" in info else "", odd=True, pre=True) joined_paths = "<br>".join( [html.attrencode(p) for p in info.get("python_paths", [_("Unknown")])]) _crash_row(_("Python Module Paths"), joined_paths, odd=False) html.close_table()
def page(self): html.open_div(id_="ldap") html.open_table() html.open_tr() html.open_td() html.begin_form("connection", method="POST") html.prevent_password_auto_completion() vs = self._valuespec() vs.render_input("connection", self._connection_cfg) vs.set_focus("connection") html.hidden_fields() html.end_form() html.close_td() html.open_td(style="padding-left:10px;vertical-align:top") html.h2(_('Diagnostics')) if not html.request.var('_test') or not self._connection_id: html.show_message( HTML( '<p>%s</p><p>%s</p>' % (_('You can verify the single parts of your ldap configuration using this ' 'dialog. Simply make your configuration in the form on the left side and ' 'hit the "Save & Test" button to execute the tests. After ' 'the page reload, you should see the results of the test here.'), _('If you need help during configuration or experience problems, please refer ' 'to the <a target="_blank" ' 'href="https://checkmk.com/checkmk_multisite_ldap_integration.html">' 'LDAP Documentation</a>.')))) else: connection = userdb.get_connection(self._connection_id) assert isinstance(connection, LDAPUserConnector) for address in connection.servers(): html.h3("%s: %s" % (_('Server'), address)) with table_element('test', searchable=False) as table: for title, test_func in self._tests(): table.row() try: state, msg = test_func(connection, address) except Exception as e: state = False msg = _('Exception: %s') % html.render_text("%s" % e) logger.exception("error testing LDAP %s for %s", title, address) if state: img = html.render_icon("success", _('Success')) else: img = html.render_icon("failed", _("Failed")) table.cell(_("Test"), title) table.cell(_("State"), img) table.cell(_("Details"), msg) connection.disconnect() html.close_td() html.close_tr() html.close_table() html.close_div()
def _show_crashed_check_details(self, info): def format_bool(val): return { True: _("Yes"), False: _("No"), None: _("Unknown"), }[val] details = info["details"] html.h2(_("Details")) html.open_table(class_="data") _crash_row(_("Host"), details["host"], odd=False, legend=True) _crash_row(_("Is Cluster Host"), format_bool(details.get("is_cluster")), odd=True) _crash_row(_("Check Type"), details["check_type"], odd=False) _crash_row(_("Manual Check"), format_bool(details.get("manual_check")), odd=True, pre=True) _crash_row(_("Inline-SNMP"), format_bool(details.get("inline_snmp")), odd=True, pre=True) _crash_row(_("Check Item"), details.get("item", "This check has no item."), odd=False) _crash_row(_("Description"), details["description"], odd=True) if "params" in details: _crash_row(_("Parameters"), format_params(details["params"]), odd=False, pre=True) else: _crash_row(_("Parameters"), "This Check has no parameters", odd=False) html.close_table()
def show_log_list(): title = _("All problematic logfiles") html.header(title, make_simple_page_breadcrumb(MegaMenuMonitoring, title)) html.begin_context_buttons() html.context_button( _("Analyze Patterns"), "%swato.py?mode=pattern_editor" % html.request.var('master_url', ''), 'analyze') ack_button() html.end_context_buttons() for site, host_name, logs in all_logs(): if not logs: continue all_logs_empty = not any( [parse_file(site, host_name, file_name) for file_name in logs]) if all_logs_empty: continue # Logfile vanished html.h2( html.render_a(host_name, href=html.makeuri([('site', site), ('host', host_name)]))) list_logs(site, host_name, logs) html.footer()
def write_snapin_exception(e): html.open_div(class_=["snapinexception"]) html.h2(_('Error')) html.p(e) html.div(traceback.format_exc().replace('\n', '<br>'), style="display:none;") html.close_div()
def _render_manpage_list(titles, manpage_list, path_comp, heading): def translate(t): return titles.get(t, t) html.h2(heading) with table_element(searchable=False, sortable=False, css="check_catalog") as table: for entry in sorted(manpage_list, key=lambda x: x["title"]): if not isinstance(entry, dict): continue table.row() url = makeuri( request, [ ("mode", "check_manpage"), ("check_type", entry["name"]), ("back", makeuri(request, [])), ], ) table.cell(_("Type of Check"), "<a href='%s'>%s</a>" % (url, entry["title"]), css="title") table.cell(_("Plugin Name"), "<tt>%s</tt>" % entry["name"], css="name") table.cell(_("Agents"), ", ".join(map(translate, sorted(entry["agents"]))), css="agents")
def write_snapin_exception(e: Exception) -> None: html.open_div(class_=["snapinexception"]) html.h2(_("Error")) html.p(str(e)) html.div(traceback.format_exc().replace("\n", "<br>"), style="display:none;") html.close_div()
def show_log_list(): title = _("All problematic logfiles") breadcrumb = make_simple_page_breadcrumb( mega_menu_registry.menu_monitoring(), title) html.header(title, breadcrumb, _log_list_page_menu(breadcrumb)) if html.request.has_var( '_ack') and not html.request.var("_do_actions") == _("No"): do_log_ack(site=None, host_name=None, file_name=None) return for site, host_name, logs in all_logs(): if not logs: continue all_logs_empty = not any( [parse_file(site, host_name, file_name) for file_name in logs]) if all_logs_empty: continue # Logfile vanished html.h2( html.render_a(host_name, href=makeuri( request, [('site', site), ('host', host_name)], ))) list_logs(site, host_name, logs) html.footer()
def _show_graph_html_content(graph_artwork, graph_data_range, graph_render_options) -> None: """Render the HTML code of a graph without its container That is a canvas object for drawing the actual graph and also legend, buttons, resize handle, etc. """ graph_render_options = artwork.add_default_render_options( graph_render_options) html.open_div( class_=[ "graph", "preview" if graph_render_options["preview"] else None ], style="font-size: %.1fpt;%s" % (graph_render_options["font_size"], _graph_padding_styles(graph_render_options)), ) if graph_render_options["show_controls"]: _show_graph_add_to_icon_for_popup(graph_artwork, graph_data_range, graph_render_options) v_axis_label = graph_artwork["vertical_axis"]["axis_label"] if v_axis_label: html.div(v_axis_label, class_="v_axis_label") # Add the floating elements if graph_render_options[ "show_graph_time"] and not graph_render_options["preview"]: html.div( graph_artwork["time_axis"]["title"] or "", css=[ "time", "inline" if graph_render_options["show_title"] == "inline" else None ], ) if graph_render_options["show_controls"] and graph_render_options[ "resizable"]: html.img(src=theme.url("images/resize_graph.png"), class_="resize") _show_html_graph_title(graph_artwork, graph_render_options) _show_graph_canvas(graph_render_options) # Note: due to "omit_zero_metrics" the graph might not have any curves if _graph_legend_enabled(graph_render_options, graph_artwork): _show_graph_legend(graph_artwork, graph_render_options) model_params_repr = graph_artwork["definition"].get("model_params_repr") model_params_display = (graph_artwork["definition"].get( "model_params", {}).get("display_model_parametrization")) if model_params_repr and model_params_display: html.open_div(align="center") html.h2(_("Forecast Parametrization")) html.write_html(model_params_repr) html.close_div() html.close_div()
def page(self): self._activation_msg() self._activation_form() html.h2(_("Activation status")) self._activation_status() html.h2(_("Pending changes")) self._change_table()
def show_details(self, crash_info, row): if not crash_info["details"]: return html.h2(_("Details")) html.p( _("No detail renderer for crash of type '%s' available. Details structure is:" ) % crash_info["crash_type"]) html.pre(pprint.pformat(crash_info["details"]))
def _show_filter_bar(self, filter_bar: PageMenuEntry) -> None: html.open_td(class_="filter_bar") html.open_a(href="javascript:void(0)", onclick="cmk.page_menu.toggle_popup(%s)" % json.dumps("popup_%s" % filter_bar.name), id_=("menu_suggestion_%s" % filter_bar.name if filter_bar.name else None)) html.h2(filter_bar.title) html.icon(filter_bar.icon_name) html.close_a() html.close_td()
def page(self): self._activation_msg() self._activation_form() html.h2(_("Activation status")) self._activation_status() if self.has_changes(): html.open_h2(class_="pending_changes_header") html.write_text(_("Pending changes")) html.div("", id_="row_info") html.close_h2() html.final_javascript("cmk.utils.display_header_info();") self._change_table()
def show(self): html.open_table(class_="dashlet_overview") html.open_tr() html.open_td(valign="top") html.open_a(href="https://checkmk.com/") html.img(html.theme_url("images/check_mk.trans.120.png"), style="margin-right: 30px;") html.close_a() html.close_td() html.open_td() html.h2("CheckMK") html.write_text( _('Welcome to Checkmk. If you want to learn more about Checkmk, please visit ' 'our <a href="https://checkmk.com/" target="_blank">user manual</a>.')) html.close_td() html.close_tr() html.close_table()
def show(self): html.open_table(class_="dashlet_overview") html.open_tr() html.open_td(valign="top") html.open_a(href="https://mathias-kettner.com/check_mk.html") html.img(html.theme_url("images/check_mk.trans.120.png"), style="margin-right: 30px;") html.close_a() html.close_td() html.open_td() html.h2("Check_MK Multisite") html.write_html( 'Welcome to Check_MK Multisite. If you want to learn more about Multisite, please visit ' 'our <a href="https://mathias-kettner.com/checkmk_multisite.html">online documentation</a>. ' 'Multisite is part of <a href="https://mathias-kettner.com/check_mk.html">Check_MK</a> - an Open Source ' 'project by <a href="https://mathias-kettner.com">Mathias Kettner</a>.' ) html.close_td() html.close_tr() html.close_table()
def show_gui_crash_details(info): details = info["details"] html.h2(_("Details")) html.open_table(class_="data") _crash_row(_("Page"), details["page"], odd=False, legend=True) _crash_row(_("Request Method"), details.get("request_method", _("Unknown"))) html.open_tr(class_="data even0") html.td(_("HTTP Parameters"), class_="left") html.open_td() html.debug_vars(vars_=details["vars"], hide_with_mouse=False) html.close_td() html.close_tr() _crash_row(_("Referer"), details.get("referer", _("Unknown"))) _crash_row(_("Username"), details["username"], odd=False) _crash_row(_("User Agent"), details["user_agent"]) _crash_row(_("Mobile GUI"), details["is_mobile"], odd=False) _crash_row(_("SSL"), details["is_ssl_request"]) _crash_row(_("Language"), details["language"], odd=False) html.close_table()
def page(self): search = get_search_expression() html.begin_form("role", method="POST") # ID forms.header(_("Basic properties"), css="wide") forms.section(_("Internal ID"), simple="builtin" in self._role, is_required=True) if self._role.get("builtin"): html.write_text("%s (%s)" % (self._role_id, _("builtin role"))) html.hidden_field("id", self._role_id) else: html.text_input("id", self._role_id) html.set_focus("id") # Alias forms.section(_("Alias")) html.help(_("An alias or description of the role")) html.text_input("alias", self._role.get("alias", ""), size=50) # Based on if not self._role.get("builtin"): forms.section(_("Based on role")) html.help( _("Each user defined role is based on one of the builtin roles. " "When created it will start with all permissions of that role. When due to a software " "update or installation of an addons new permissions appear, the user role will get or " "not get those new permissions based on the default settings of the builtin role it's " "based on.")) role_choices: Choices = [(i, r["alias"]) for i, r in self._roles.items() if r.get("builtin")] html.dropdown("basedon", role_choices, deflt=self._role.get("basedon", "user"), ordered=True) forms.end() html.h2(_("Permissions")) # Permissions base_role_id = self._role.get("basedon", self._role_id) html.help( _("When you leave the permissions at "default" then they get their " "settings from the factory defaults (for builtin roles) or from the " "factory default of their base role (for user define roles). Factory defaults " "may change due to software updates. When choosing another base role, all " "permissions that are on default will reflect the new base role." )) for section in permission_section_registry.get_sorted_sections(): # Now filter by the optional search term filtered_perms = [] for perm in permission_registry.get_sorted_permissions(section): if search and (search not in perm.title.lower() and search not in perm.name.lower()): continue filtered_perms.append(perm) if not filtered_perms: continue forms.header(section.title, isopen=search is not None, css="wide") for perm in filtered_perms: forms.section(perm.title) pvalue = self._role["permissions"].get(perm.name) def_value = base_role_id in perm.defaults choices: Choices = [ ("yes", _("yes")), ("no", _("no")), ("default", _("default (%s)") % (def_value and _("yes") or _("no"))), ] deflt = {True: "yes", False: "no"}.get(pvalue, "default") html.dropdown("perm_" + perm.name, choices, deflt=deflt, style="width: 130px;") html.help(perm.description) forms.end() html.hidden_fields() html.end_form()
def _preview(self): # type: () -> None html.begin_form("preview", method="POST") self._preview_form() attributes = self._attribute_choices() # first line could be missing in situation of import error csv_reader = self._open_csv_file() if not csv_reader: return # don't try to show preview when CSV could not be read html.h2(_("Preview")) attribute_list = "<ul>%s</ul>" % "".join( ["<li>%s (%s)</li>" % a for a in attributes if a[0] is not None]) html.help( _("This list shows you the first 10 rows from your CSV file in the way the import is " "currently parsing it. If the lines are not splitted correctly or the title line is " "not shown as title of the table, you may change the import settings above and try " "again.") + "<br><br>" + _("The first row below the titles contains fields to specify which column of the " "CSV file should be imported to which attribute of the created hosts. The import " "progress is trying to match the columns to attributes automatically by using the " "titles found in the title row (if you have some). " "If you use the correct titles, the attributes can be mapped automatically. The " "currently available attributes are:") + attribute_list + _("You can change these assignments according to your needs and then start the " "import by clicking on the <i>Import</i> button above.")) # Wenn bei einem Host ein Fehler passiert, dann wird die Fehlermeldung zu dem Host angezeigt, so dass man sehen kann, was man anpassen muss. # Die problematischen Zeilen sollen angezeigt werden, so dass man diese als Block in ein neues CSV-File eintragen kann und dann diese Datei # erneut importieren kann. if self._has_title_line: try: headers = list(next(csv_reader)) except StopIteration: headers = [] # nope, there is no header else: headers = [] rows = list(csv_reader) # Determine how many columns should be rendered by using the longest column num_columns = max([len(r) for r in [headers] + rows]) with table_element(sortable=False, searchable=False, omit_headers=not self._has_title_line) as table: # Render attribute selection fields table.row() for col_num in range(num_columns): header = headers[col_num] if len(headers) > col_num else None table.cell(html.render_text(header)) attribute_varname = "attribute_%d" % col_num if html.request.var(attribute_varname): attribute_method = html.request.get_ascii_input_mandatory( "attribute_varname") else: attribute_method = self._try_detect_default_attribute( attributes, header) html.request.del_var(attribute_varname) html.dropdown("attribute_%d" % col_num, attributes, deflt=attribute_method, autocomplete="off") # Render sample rows for row in rows: table.row() for cell in row: table.cell(None, html.render_text(cell)) html.end_form()