def page(self): filter_names = json.loads(html.request.var("aggregations", "[]")) forced_layout_id = html.request.var("layout_id") if forced_layout_id not in BILayoutManagement.get_all_bi_template_layouts( ): forced_layout_id = None state_data = bi.api_get_aggregation_state(filter_names=filter_names) aggregation_info = {"aggregations": {}} aggregation_layouts = BILayoutManagement.get_all_bi_aggregation_layouts( ) for row in state_data["rows"]: aggr_name = row["tree"]["aggr_name"] if filter_names and aggr_name not in filter_names: continue visual_mapper = NodeVisualizationBIDataMapper() aggr_treestate = row["tree"]["aggr_treestate"] hierarchy = visual_mapper.consume(aggr_treestate) data = {} data["hierarchy"] = hierarchy data["groups"] = row["groups"] data["data_timestamp"] = int(time.time()) aggr_settings = row["tree"]["aggr_tree"]["node_visualization"] layout = {"config": {}} if forced_layout_id: layout["enforced_id"] = aggr_name layout["origin_type"] = "globally_enforced" layout["origin_info"] = _("Globally enforced") layout[ "use_layout"] = BILayoutManagement.load_bi_template_layout( forced_layout_id) else: if aggr_name in aggregation_layouts: layout["origin_type"] = "explicit" layout["origin_info"] = _("Explicit set") layout["explicit_id"] = aggr_name layout["config"] = aggregation_layouts[aggr_name] layout["config"]["ignore_rule_styles"] = True else: layout.update( self._get_template_based_layout_settings( aggr_settings)) if "ignore_rule_styles" not in layout["config"]: layout["config"]["ignore_rule_styles"] = aggr_settings.get( "ignore_rule_styles", False) if "line_config" not in layout["config"]: layout["config"]["line_config"] = self._get_line_style_config( aggr_settings) data["layout"] = layout aggregation_info["aggregations"][row["tree"]["aggr_name"]] = data html.set_output_format("json") return aggregation_info
def get_bi_aggregation_state(params): """Get the state of BI aggregations""" user.need_permission("wato.bi_rules") filter_config = params.get("body", {}) filter_names = filter_config.get("filter_names") filter_groups = filter_config.get("filter_groups") return constructors.serve_json( api_get_aggregation_state(filter_names=filter_names, filter_groups=filter_groups) )
def page(self): filter_names = json.loads(html.request.var("aggregations", "[]")) forced_layout_id = html.request.var("layout_id") if forced_layout_id not in BILayoutManagement.get_all_bi_template_layouts( ): forced_layout_id = None state_data = bi.api_get_aggregation_state(filter_names=filter_names) aggregation_info = {"aggregations": {}} aggregation_layouts = BILayoutManagement.get_all_bi_aggregation_layouts( ) for row in state_data["rows"]: aggr_name = row["tree"]["aggr_name"] if filter_names and aggr_name not in filter_names: continue visual_mapper = NodeVisualizationBIDataMapper() aggr_treestate = row["tree"]["aggr_treestate"] hierarchy = visual_mapper.consume(aggr_treestate) data = {} data["hierarchy"] = hierarchy data["groups"] = row["groups"] data["data_timestamp"] = int(time.time()) if not forced_layout_id: if aggr_name in aggregation_layouts: data["use_layout_id"] = aggr_name data["use_layout"] = aggregation_layouts[aggr_name] data["layout_origin"] = _("Explicit set") else: template_layout_id = row["tree"]["aggr_tree"][ "use_layout_id"] if template_layout_id and template_layout_id in BILayoutManagement.get_all_bi_template_layouts( ): data["template_layout_id"] = template_layout_id data[ "use_layout"] = BILayoutManagement.load_bi_template_layout( template_layout_id) data["layout_origin"] = _("Template: %s" % template_layout_id) else: data["use_default_layout"] = config.default_bi_layout data["layout_origin"] = _( "Default layout: %s" % config.default_bi_layout.title()) aggregation_info["aggregations"][row["tree"]["aggr_name"]] = data if forced_layout_id: aggregation_info[ "use_layout"] = BILayoutManagement.load_bi_template_layout( forced_layout_id) html.set_output_format("json") return aggregation_info
def _get(self, request): return bi.api_get_aggregation_state(filter_names=request.get("filter", {}).get("names"), filter_groups=request.get("filter", {}).get("groups"))