def page(self) -> None: acktime = request.get_float_input_mandatory('acktime', time.time()) if request.var('_confirm'): _acknowledge_failed_notifications(acktime, time.time()) if user.authorized_login_sites(): watolib.init_wato_datastructures(with_wato_lock=True) title = _('Replicate user profile') breadcrumb = make_simple_page_breadcrumb( mega_menu_registry.menu_monitoring(), title) html.header(title, breadcrumb) for message in get_flashed_messages(): html.show_message(message) # This local import is needed for the moment import cmk.gui.wato.user_profile # pylint: disable=redefined-outer-name cmk.gui.wato.user_profile.user_profile_async_replication_page( back_url="clear_failed_notifications.py") return failed_notifications = load_failed_notifications( before=acktime, after=acknowledged_time()) self._show_page(acktime, failed_notifications) if request.var('_confirm'): html.reload_whole_page()
def ajax_snapin(): """Renders and returns the contents of the requested sidebar snapin(s) in JSON format""" response.set_content_type("application/json") user_config = UserSidebarConfig(user, config.sidebar) snapin_id = request.var("name") snapin_ids = ([snapin_id] if snapin_id else request.get_str_input_mandatory("names", "").split(",")) snapin_code: List[str] = [] for snapin_id in snapin_ids: try: snapin_instance = user_config.get_snapin(snapin_id).snapin_type() except KeyError: continue # Skip not existing snapins if not snapin_instance.may_see(): continue # When restart snapins are about to be refreshed, only render # them, when the core has been restarted after their initial # rendering if not snapin_instance.refresh_regularly( ) and snapin_instance.refresh_on_restart(): since = request.get_float_input_mandatory("since", 0) newest = since for site in sites.states().values(): prog_start = site.get("program_start", 0) if prog_start > newest: newest = prog_start if newest <= since: # no restart snapin_code.append("") continue with output_funnel.plugged(): try: snapin_instance.show() except Exception as e: write_snapin_exception(e) e_message = ( _("Exception during element refresh (element '%s')") % snapin_instance.type_name()) logger.error("%s %s: %s", request.requested_url, e_message, traceback.format_exc()) finally: snapin_code.append(output_funnel.drain()) response.set_data(json.dumps(snapin_code))
def page(self) -> None: acktime = request.get_float_input_mandatory("acktime", time.time()) if request.var("_confirm"): _acknowledge_failed_notifications(acktime, time.time()) if user.authorized_login_sites(): title = _("Replicate user profile") breadcrumb = make_simple_page_breadcrumb( mega_menu_registry.menu_monitoring(), title ) html.header(title, breadcrumb) for message in get_flashed_messages(): html.show_message(message) user_profile_async_replication_page(back_url="clear_failed_notifications.py") return failed_notifications = load_failed_notifications(before=acktime, after=acknowledged_time()) self._show_page(acktime, failed_notifications) if request.var("_confirm"): html.reload_whole_page()
def host_service_graph_dashlet_cmk( graph_identification: GraphIdentifier, custom_graph_render_options, ): graph_render_options = {**default_dashlet_graph_render_options} graph_render_options = artwork.add_default_render_options( graph_render_options) graph_render_options.update(custom_graph_render_options) width_var = request.get_float_input_mandatory("width", 0.0) width = int((width_var / html_size_per_ex)) height_var = request.get_float_input_mandatory("height", 0.0) height = int((height_var / html_size_per_ex)) bounds = _graph_margin_ex(graph_render_options) height -= _graph_title_height_ex(graph_render_options) height -= bounds.top + bounds.bottom width -= bounds.left + bounds.right graph_render_options["size"] = (width, height) # The timerange is specified in PNP like manner. range_secs = { "0": 4 * 3600, "1": 25 * 3600, "2": 7 * 86400, "3": 31 * 86400, "4": 366 * 86400, } secs_var = request.var("timerange") if secs_var not in range_secs: secs = 4 * 3600 else: secs = range_secs[secs_var] end_time = time.time() start_time = end_time - secs graph_data_range = { "time_range": (start_time, end_time), } graph_data_range["step"] = estimate_graph_step_for_html( graph_data_range["time_range"], graph_render_options) graph_recipes = resolve_graph_recipe_with_error_handling( graph_identification, destination=GraphDestinations.dashlet, ) if not isinstance(graph_recipes, list): return graph_recipes # This is to html.write the exception if graph_recipes: graph_recipe = graph_recipes[0] else: raise MKGeneralException(_("Failed to calculate a graph recipe.")) # When the legend is enabled, we need to reduce the height by the height of the legend to # make the graph fit into the dashlet area. if graph_render_options["show_legend"]: # TODO FIXME: This graph artwork is calulated twice. Once here and once in render_graphs_from_specification_html() graph_artwork = artwork.compute_graph_artwork(graph_recipe, graph_data_range, graph_render_options) if graph_artwork["curves"]: legend_height = graph_legend_height_ex(graph_render_options, graph_artwork) graph_render_options["size"] = (width, height - legend_height) html_code = render_graphs_from_definitions([graph_recipe], graph_data_range, graph_render_options, render_async=False) html.write_html(html_code)
def _scaled_bound(value): try: return request.get_float_input_mandatory(value) * self._scale except MKUserError: return None