def _show_sidebar(self) -> None: if not config.user.may("general.see_sidebar"): html.div("", id_="check_mk_navigation") return user_config = UserSidebarConfig(config.user, config.sidebar) html.open_div( id_="check_mk_navigation", class_="min" if config.user.get_attribute("nav_hide_icons_title") else None) self._show_sidebar_head() html.close_div() assert config.user.id is not None sidebar_position = cmk.gui.userdb.load_custom_attr( config.user.id, 'ui_sidebar_position', lambda x: None if x == "None" else "left") html.open_div(id_="check_mk_sidebar", class_=[sidebar_position]) self._show_shortcut_bar() self._show_snapin_bar(user_config) html.close_div() if user_config.folded: html.final_javascript("cmk.sidebar.fold_sidebar();")
def render_graph_container_html(graph_recipe, graph_data_range, graph_render_options): graph_render_options = artwork.add_default_render_options( graph_render_options) # Estimate size of graph. This will not be the exact size of the graph, because # this does calculate the size of the canvas area and does not take e.g. the legend # into account. We would need the graph_artwork to calculate that, but this is something # we don't have in this early stage. size = graph_render_options["size"] graph_width = size[0] * html_size_per_ex graph_height = size[1] * html_size_per_ex content = html.render_div("", class_="title") \ + html.render_div("", class_="content", style="width:%dpx;height:%dpx" % (graph_width, graph_height)) output = html.render_div(html.render_div(content, class_=["graph", "loading_graph"]), class_="graph_load_container") \ output += html.render_javascript( "cmk.graphs.load_graph_content(%s, %s, %s)" % ( json.dumps(graph_recipe), json.dumps(graph_data_range), json.dumps(graph_render_options), )) if "cmk.graphs.register_delayed_graph_listener" not in html.final_javascript_code: html.final_javascript("cmk.graphs.register_delayed_graph_listener()") return output
def _show_sidebar(self) -> None: if not config.user.may("general.see_sidebar"): html.div("", id_="check_mk_navigation") return user_config = UserSidebarConfig(config.user, config.sidebar) html.open_div(id_="check_mk_navigation") self._show_sidebar_head() html.close_div() html.open_div( id_="check_mk_sidebar", class_=[ "left" if config.user.get_attribute("ui_sidebar_position") else None ]) self._show_shortcut_bar() self._show_snapin_bar(user_config) html.close_div() if user_config.folded: html.final_javascript("cmk.sidebar.fold_sidebar();")
def show_topology_content(self, hostnames: List[HostName], mode: str, growth_auto_max_nodes: Optional[int] = None, max_nodes: int = 400, mesh_depth: int = 0) -> None: div_id = "node_visualization" html.div("", id=div_id) # Filters html.open_div(id="topology_filters") view, filters = self._get_topology_view_and_filters() html.request.set_var("topology_mesh_depth", str(mesh_depth)) html.request.set_var("topology_max_nodes", str(max_nodes)) cmk.gui.views.show_filter_form(view, filters) html.final_javascript("cmk.page_menu.open_popup('popup_filters');") html.close_div() html.javascript( "topology_instance = new cmk.node_visualization.TopologyVisualization(%s, %s);" % (json.dumps(div_id), json.dumps(mode))) if growth_auto_max_nodes: html.javascript("topology_instance.set_growth_auto_max_nodes(%d)" % growth_auto_max_nodes) html.javascript("topology_instance.set_max_nodes(%d)" % max_nodes) html.javascript("topology_instance.set_mesh_depth(%d)" % mesh_depth) html.javascript("topology_instance.set_theme(%s)" % json.dumps(html.get_theme())) overlay_config = self._get_overlay_config() if overlay_config: html.javascript("topology_instance.set_initial_overlays_config(%s)" % json.dumps(overlay_config)) html.javascript("topology_instance.show_topology(%s)" % json.dumps(hostnames))
def _show_popup(self, entry: PageMenuEntry) -> None: assert isinstance(entry.item, PageMenuPopup) if entry.name is None: raise ValueError("Missing \"name\" attribute on entry \"%s\"" % entry.title) classes = ["page_menu_popup"] + html.normalize_css_spec(entry.item.css_classes) if isinstance(entry.item, PageMenuSidePopup): classes.append("side_popup") popup_id = "popup_%s" % entry.name html.open_div(id_=popup_id, class_=classes) html.open_div(class_="head") html.h3(entry.title) html.a(html.render_icon("close"), class_="close_popup", href="javascript:void(0)", onclick="cmk.page_menu.close_popup(this)") html.close_div() if (isinstance(entry.item, PageMenuSidePopup) and entry.item.content and "side_popup_content" not in entry.item.content): raise RuntimeError( "Add a div container with the class \"side_popup_content\" to the popup content") html.open_div(class_="content") html.write(HTML(entry.item.content)) html.close_div() html.close_div() if isinstance(entry.item, PageMenuSidePopup): html.final_javascript("cmk.page_menu.side_popup_add_simplebar_scrollbar(%s);" % json.dumps(popup_id))
def page(self): html.open_div(class_="diag_host") html.open_table() html.open_tr() html.open_td() html.begin_form('diag_host', method="POST") html.prevent_password_auto_completion() forms.header(_('Host Properties')) forms.section(legend=False) # The diagnose page shows both snmp variants at the same time # We need to analyse the preconfigured community and set either the # snmp_community or the snmp_v3_credentials vs_dict = {} for key, value in self._host.attributes().items(): if key == "snmp_community" and isinstance(value, tuple): vs_dict["snmp_v3_credentials"] = value continue vs_dict[key] = value vs_host = self._vs_host() vs_host.render_input("vs_host", vs_dict) html.help(vs_host.help()) forms.end() html.open_div(style="margin-bottom:10px") html.close_div() forms.header(_('Options')) value = {} forms.section(legend=False) vs_rules = self._vs_rules() vs_rules.render_input("vs_rules", value) html.help(vs_rules.help()) forms.end() # When clicking "Save & Test" on the "Edit host" page, this will be set # to immediately execute the tests using the just saved settings if request.has_var("_start_on_load"): html.final_javascript( "cmk.page_menu.form_submit('diag_host', '_try');") html.hidden_fields() html.end_form() html.close_td() html.open_td(style="padding-left:10px;") self._show_diagnose_output()
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_tree_selection(self): html.begin_form("vtree") html.dropdown("vtree", self._tree_choices(), deflt="%s" % self._current_tree_id, onchange='virtual_host_tree_changed(this)', style="width:210px" if self._current_tree_path else None) # Give chance to change one level up, if we are in a subtree if self._current_tree_path: upurl = "javascript:virtual_host_tree_enter('%s')" % "|".join( self._current_tree_path[:-1]) html.icon_button(upurl, _("Go up one tree level"), "back") html.br() html.end_form() html.final_javascript(self._javascript())
def _sidebar_foot(self, user_config): html.open_div(id_="side_footer") if config.user.may("general.configure_sidebar"): html.icon_button("sidebar_add_snapin.py", _("Add snapin to the sidebar"), "sidebar_addsnapin", target="main") # editing the profile is not possible on remote sites which are sync targets # of a central WATO system if config.wato_enabled and \ (config.user.may("general.edit_profile") or config.user.may("general.change_password")): html.icon_button( "user_profile.py", _("Edit your personal settings, change your password"), "sidebar_settings", target="main") if config.user.may( "general.logout") and not config.auth_by_http_header: html.icon_button("logout.py", _("Log out"), "sidebar_logout", target="_top") html.icon_button("return void();", _("You have pending messages."), "sidebar_messages", onclick='cmk.sidebar.read_message()', id_='msg_button', style='display:none') html.open_div(style="display:none;", id_="messages") self.render_messages() html.close_div() html.open_div(class_=["copyright"]) html.write( HTML("© ") + html.render_a( "tribe29 GmbH", target="_blank", href="https://checkmk.com")) html.close_div() html.close_div() if user_config.folded: html.final_javascript("cmk.sidebar.fold_sidebar();")
def _show_popup(self, entry: PageMenuEntry) -> None: assert isinstance(entry.item, PageMenuPopup) if entry.name is None: raise ValueError('Missing "name" attribute on entry "%s"' % entry.title) classes: List[Optional[str]] = ["page_menu_popup"] classes += entry.item.css_classes if isinstance(entry.item, PageMenuSidePopup): classes.append("side_popup") popup_id = "popup_%s" % entry.name html.open_div(id_=popup_id, class_=classes) html.open_div(class_="head") html.h3(entry.title) html.a( html.render_icon("close"), class_="close_popup", href="javascript:void(0)", onclick="cmk.page_menu.close_popup(this)", ) html.close_div() if ( isinstance(entry.item, PageMenuSidePopup) and entry.item.content and "side_popup_content" not in entry.item.content ): raise RuntimeError( 'Add a div container with the class "side_popup_content" to the popup content' ) html.open_div(class_="content") html.write_html(entry.item.content) html.close_div() html.close_div() if isinstance(entry.item, PageMenuSidePopup): html.final_javascript( "cmk.page_menu.side_popup_add_simplebar_scrollbar(%s);" % json.dumps(popup_id) )