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([("", _("All sites"))] + 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 action(self) -> ActionResult: try: transactions.check_transaction() user.save_file("parentscan", dict(self._settings._asdict())) self._job.set_function(self._job.do_execute, self._settings, self._get_tasks()) self._job.start() except Exception as e: if config.debug: raise logger.exception("Failed to start parent scan") raise MKUserError( None, _("Failed to start parent scan: %s") % ("%s" % e).replace("\n", "\n<br>") ) raise HTTPRedirect(self._job.detail_url())
def _save_user_settings(self): user.save_file("virtual_host_tree", { "tree": self._current_tree_id, "cwd": self._cwds })
def save_graph_pin() -> None: try: pin_timestamp = request.get_integer_input("pin") except ValueError: pin_timestamp = None user.save_file("graph_pin", None if pin_timestamp == -1 else pin_timestamp)
def save_user_graph_data_range(graph_data_range): user.save_file("graph_range", graph_data_range)
def render_ajax_graph(context): graph_data_range = context["data_range"] graph_render_options = context["render_options"] graph_recipe = context["definition"] start_time_var = request.var("start_time") end_time_var = request.var("end_time") step_var = request.var("step") if start_time_var is not None and end_time_var is not None and step_var is not None: start_time = float(start_time_var) end_time = float(end_time_var) step = float(step_var) else: start_time, end_time = graph_data_range["time_range"] step = graph_data_range["step"] size = graph_render_options["size"] resize_x_var = request.var("resize_x") resize_y_var = request.var("resize_y") if resize_x_var is not None and resize_y_var is not None: render_opt_x, render_opt_y = context["render_options"]["size"] size_x = max(min_resize_width, float(resize_x_var) / html_size_per_ex + render_opt_x) size_y = max(min_resize_height, float(resize_y_var) / html_size_per_ex + render_opt_y) user.save_file("graph_size", (size_x, size_y)) size = (size_x, size_y) range_from_var = request.var("range_from") range_to_var = request.var("range_to") if range_from_var is not None and range_to_var is not None: vertical_range: Optional[Tuple[float, float]] = (float(range_from_var), float(range_to_var)) else: vertical_range = None if request.has_var("pin"): artwork.save_graph_pin() if request.has_var("consolidation_function"): graph_recipe["consolidation_function"] = request.var( "consolidation_function") graph_render_options["size"] = size graph_data_range["time_range"] = (start_time, end_time) graph_data_range["vertical_range"] = vertical_range graph_data_range["step"] = step # Persist the current data range for the graph editor if graph_render_options["editing"]: save_user_graph_data_range(graph_data_range) graph_artwork = artwork.compute_graph_artwork(graph_recipe, graph_data_range, graph_render_options) with output_funnel.plugged(): _show_graph_html_content(graph_artwork, graph_data_range, graph_render_options) html_code = HTML(output_funnel.drain()) return { "html": html_code, "graph": graph_artwork, "context": { "graph_id": context["graph_id"], "definition": graph_recipe, "data_range": graph_data_range, "render_options": graph_render_options, }, }