def add_default_render_options(graph_render_options, render_unthemed=False): options = get_default_graph_render_options() options.update(graph_render_options) options.setdefault("size", user.load_file("graph_size", (70, 16))) # Users can't modify graph colors. Only defaults are allowed theme_colors = _graph_colors(theme.get() if not render_unthemed else "pdf") options.update(theme_colors) return options
def ajax_set_snapin_site(): response.set_content_type("application/json") ident = request.var("ident") if ident not in snapin_registry: raise MKUserError(None, _("Invalid ident")) site = request.var("site") site_choices = dict([(SiteId(""), _("All sites"))] + user_sites.get_configured_site_choices()) if site not in site_choices: raise MKUserError(None, _("Invalid site")) snapin_sites = user.load_file("sidebar_sites", {}, lock=True) snapin_sites[ident] = site user.save_file("sidebar_sites", snapin_sites)
def _load_user_settings(self): tree_conf = user.load_file("virtual_host_tree", {"tree": 0, "cwd": {}}) if isinstance(tree_conf, int): tree_conf = { "tree": tree_conf, "cwd": {} } # convert from old style tree_id = tree_conf["tree"] # Fallback to first defined tree in case the user selected does not exist anymore if tree_id not in self._trees and self._trees: tree_id = self._tree_choices()[0][0] self._cwds = tree_conf["cwd"] self._current_tree_id = tree_id self._current_tree_path = self._cwds.get(self._current_tree_id, [])
def snapin_site_choice( ident: str, choices: List[Tuple[SiteId, str]]) -> Optional[List[SiteId]]: sites = user.load_file("sidebar_sites", {}) available_site_choices = filter_available_site_choices(choices) site = sites.get(ident, "") if site == "": only_sites = None else: only_sites = [site] if len(available_site_choices) <= 1: return None dropdown_choices: Choices = [ ("", _("All sites")), ] dropdown_choices += available_site_choices onchange = "cmk.sidebar.set_snapin_site(event, %s, this)" % json.dumps( ident) html.dropdown("site", dropdown_choices, deflt=site, onchange=onchange) return only_sites
def _show_start_form(self): html.begin_form("parentscan", method="POST") html.hidden_fields() # Mode of action html.open_p() if not self._complete_folder: num_selected = len(get_hosts_from_checkboxes()) html.write_text(_("You have selected <b>%d</b> hosts for parent scan. ") % num_selected) html.p( _( "The parent scan will try to detect the last gateway " "on layer 3 (IP) before a host. This will be done by " "calling <tt>traceroute</tt>. If a gateway is found by " "that way and its IP address belongs to one of your " "monitored hosts, that host will be used as the hosts " "parent. If no such host exists, an artifical ping-only " "gateway host will be created if you have not disabled " "this feature." ) ) forms.header(_("Settings for Parent Scan")) self._settings = ParentScanSettings( **user.load_file( "parentscan", { "where": "subfolder", "alias": _("Created by parent scan"), "recurse": True, "select": "noexplicit", "timeout": 8, "probes": 2, "ping_probes": 5, "max_ttl": 10, "force_explicit": False, }, ) ) # Selection forms.section(_("Selection")) if self._complete_folder: html.checkbox("recurse", self._settings.recurse, label=_("Include all subfolders")) html.br() html.radiobutton( "select", "noexplicit", self._settings.select == "noexplicit", _("Skip hosts with explicit parent definitions (even if empty)") + "<br>", ) html.radiobutton( "select", "no", self._settings.select == "no", _("Skip hosts hosts with non-empty parents (also if inherited)") + "<br>", ) html.radiobutton( "select", "ignore", self._settings.select == "ignore", _("Scan all hosts") + "<br>" ) # Performance forms.section(_("Performance")) html.open_table() html.open_tr() html.open_td() html.write_text(_("Timeout for responses") + ":") html.close_td() html.open_td() html.text_input("timeout", str(self._settings.timeout), size=2, cssclass="number") html.write_text(_("sec")) html.close_td() html.close_tr() html.open_tr() html.open_td() html.write_text(_("Number of probes per hop") + ":") html.close_td() html.open_td() html.text_input("probes", str(self._settings.probes), size=2, cssclass="number") html.close_td() html.close_tr() html.open_tr() html.open_td() html.write_text(_("Maximum distance (TTL) to gateway") + ":") html.close_td() html.open_td() html.text_input("max_ttl", str(self._settings.max_ttl), size=2, cssclass="number") html.close_td() html.close_tr() html.open_tr() html.open_td() html.write_text(_("Number of PING probes") + ":") html.help( _( "After a gateway has been found, Check_MK checks if it is reachable " "via PING. If not, it is skipped and the next gateway nearer to the " "monitoring core is being tried. You can disable this check by setting " "the number of PING probes to 0." ) ) html.close_td() html.open_td() html.text_input("ping_probes", str(self._settings.ping_probes), size=2, cssclass="number") html.close_td() html.close_tr() html.close_table() # Configuring parent forms.section(_("Configuration")) html.checkbox( "force_explicit", deflt=self._settings.force_explicit, label=_( "Force explicit setting for parents even if setting matches that of the folder" ), ) # Gateway creation forms.section(_("Creation of gateway hosts")) html.write_text(_("Create gateway hosts in")) html.open_ul() html.radiobutton( "where", "subfolder", self._settings.where == "subfolder", _("in the subfolder <b>%s/Parents</b>") % Folder.current_disk_folder().title(), ) html.br() html.radiobutton( "where", "here", self._settings.where == "here", _("directly in the folder <b>%s</b>") % Folder.current_disk_folder().title(), ) html.br() html.radiobutton( "where", "there", self._settings.where == "there", _("in the same folder as the host") ) html.br() html.radiobutton( "where", "nowhere", self._settings.where == "nowhere", _("do not create gateway hosts") ) html.close_ul() html.write_text(_("Alias for created gateway hosts") + ": ") html.text_input("alias", default_value=self._settings.alias) forms.end() # Start button html.button("_start", _("Start")) html.hidden_fields() html.end_form()
def load_graph_pin() -> Optional[int]: return user.load_file("graph_pin", None)
def show(self): if not site_config.is_wato_slave_site(): if not active_config.wato_enabled: html.write_text(_("Setup is disabled.")) return False user_folders = compute_foldertree() # # Render link target selection # # Apply some view specific filters views_to_show: List[Tuple[str, ViewSpec]] = [] dflt_target_name: str = "allhosts" dflt_topic_name: str = "" for name, view in views.get_permitted_views().items(): if (not active_config.visible_views or name in active_config.visible_views) and ( not active_config.hidden_views or name not in active_config.hidden_views): views_to_show.append((name, view)) if name == dflt_target_name: dflt_topic_name = view["topic"] selected_topic_name: str selected_target_name: str selected_topic_name, selected_target_name = user.load_file( "foldertree", (dflt_topic_name, dflt_target_name)) visuals_to_show = [("views", e) for e in views_to_show] visuals_to_show += [ ("dashboards", e) for e in dashboard.get_permitted_dashboards().items() ] topics = make_topic_menu(visuals_to_show) topic_choices: Choices = [(topic.title, topic.title) for topic in topics] html.open_table() html.open_tr() html.open_td() html.dropdown( "topic", topic_choices, deflt=selected_topic_name, onchange="cmk.sidebar.wato_tree_topic_changed(this)", ) html.close_td() html.close_tr() html.open_tr() html.open_td() for topic in topics: targets: Choices = [] for item in topic.items: if item.url and item.url.startswith("dashboard.py"): name = "dashboard|" + item.name else: name = item.name targets.append((name, item.title)) if topic.name != selected_topic_name: default = "" style: Optional[str] = "display:none" else: default = selected_target_name style = None html.dropdown( "target_%s" % topic.title, targets, deflt=default, onchange="cmk.sidebar.wato_tree_target_changed(this)", style=style, ) html.close_td() html.close_tr() html.close_table() # Now render the whole tree if user_folders: render_tree_folder("wato-hosts", list(user_folders.values())[0], "cmk.sidebar.wato_tree_click")
def load_graph_pin(): return user.load_file("graph_pin", None)