def _transform_dashlets_mut(dashlet_spec: DashletConfig) -> DashletConfig: # abusing pass by reference to mutate dashlet if dashlet_spec['type'] == 'view': transform_painter_spec(dashlet_spec) # ->2014-10 if dashlet_spec['type'] == 'pnpgraph': if 'service' not in dashlet_spec['single_infos']: dashlet_spec['single_infos'].append('service') if 'host' not in dashlet_spec['single_infos']: dashlet_spec['single_infos'].append('host') # The service context has to be set, otherwise the pnpgraph dashlet would # complain about missing context information when displaying host graphs. dashlet_spec["context"].setdefault("service", "_HOST_") if dashlet_spec['type'] in ['pnpgraph', 'custom_graph']: # -> 1.5.0i2 if "graph_render_options" not in dashlet_spec: dashlet_spec["graph_render_options"] = { "show_legend": dashlet_spec.pop("show_legend", False), "show_service": dashlet_spec.pop("show_service", True), } # -> 2.0.0b6 transform_graph_render_options(dashlet_spec["graph_render_options"]) dashlet_spec["graph_render_options"].pop("show_title", None) # title_format is not used in Dashlets (Custom tiltle instead, field 'title') dashlet_spec["graph_render_options"].pop("title_format", None) if dashlet_spec["type"] == "network_topology": # -> 2.0.0i Removed network topology dashlet type transform_topology_dashlet(dashlet_spec) return dashlet_spec
def _transform_dashlets_mut(dashlet_spec): # abusing pass by reference to mutate dashlet if dashlet_spec['type'] == 'view': transform_painter_spec(dashlet_spec) # ->2014-10 if dashlet_spec['type'] == 'pnpgraph': if 'service' not in dashlet_spec['single_infos']: dashlet_spec['single_infos'].append('service') if 'host' not in dashlet_spec['single_infos']: dashlet_spec['single_infos'].append('host') if dashlet_spec['type'] in ['pnpgraph', 'custom_graph']: # -> 1.5.0i2 if "graph_render_options" not in dashlet_spec: dashlet_spec["graph_render_options"] = { "show_legend": dashlet_spec.pop("show_legend", False), "show_service": dashlet_spec.pop("show_service", True), } # -> 2.0.0i1 dashlet_spec["graph_render_options"].setdefault( "title_format", default_dashlet_graph_render_options["title_format"]) transform_graph_render_options(dashlet_spec["graph_render_options"]) title_format = dashlet_spec["graph_render_options"].pop("title_format") dashlet_spec.setdefault( "title_format", title_format or dashlet_spec["graph_render_options"]["title_format"]) dashlet_spec["graph_render_options"].pop("show_title", None) # -> 2.0.0i1 All dashlets have new mandatory title_format dashlet_spec.setdefault("title_format", ['plain']) return dashlet_spec
def __init__(self, dashboard_name: DashboardName, dashboard: DashboardConfig, dashlet_id: DashletId, dashlet: DashletConfig) -> None: super().__init__(dashboard_name=dashboard_name, dashboard=dashboard, dashlet_id=dashlet_id, dashlet=dashlet) # Be compatible to pre 1.5.0i2 format if "graph_render_options" not in self._dashlet_spec: self._dashlet_spec["graph_render_options"] = transform_graph_render_options({ "show_legend": self._dashlet_spec.pop("show_legend", False), "show_service": self._dashlet_spec.pop("show_service", True), }) title_format = self._dashlet_spec.setdefault( "title_format", default_dashlet_graph_render_options["title_format"]) self._dashlet_spec["graph_render_options"].setdefault("title_format", title_format) self._dashlet_spec["_graph_identification"] = self.graph_identification() graph_recipes = resolve_graph_recipe(self._dashlet_spec["_graph_identification"]) if not isinstance(graph_recipes, list): return if graph_recipes: self._dashlet_spec["_graph_title"] = graph_recipes[0]["title"] else: raise MKGeneralException(_("Failed to calculate a graph recipe.")) # New graphs which have been added via "add to visual" option don't have a timerange # configured. So we assume the default timerange here by default. self._dashlet_spec.setdefault('timerange', '1')
def _transform_dashlets_mut(dashlet_spec: DashletConfig) -> DashletConfig: # abusing pass by reference to mutate dashlet if dashlet_spec["type"] == "view": transform_painter_spec(dashlet_spec) # ->2014-10 if dashlet_spec["type"] == "pnpgraph": if "service" not in dashlet_spec["single_infos"]: dashlet_spec["single_infos"].append("service") if "host" not in dashlet_spec["single_infos"]: dashlet_spec["single_infos"].append("host") # The service context has to be set, otherwise the pnpgraph dashlet would # complain about missing context information when displaying host graphs. dashlet_spec["context"].setdefault("service", "_HOST_") if dashlet_spec["type"] in ["pnpgraph", "custom_graph"]: # -> 1.5.0i2 if "graph_render_options" not in dashlet_spec: dashlet_spec["graph_render_options"] = { "show_legend": dashlet_spec.pop("show_legend", False), "show_service": dashlet_spec.pop("show_service", True), } # -> 2.0.0b6 transform_graph_render_options(dashlet_spec["graph_render_options"]) dashlet_spec["graph_render_options"].pop("show_title", None) # title_format is not used in Dashlets (Custom tiltle instead, field 'title') dashlet_spec["graph_render_options"].pop("title_format", None) if dashlet_spec["type"] == "network_topology": # -> 2.0.0i Removed network topology dashlet type transform_topology_dashlet(dashlet_spec) if dashlet_spec["type"] in ["notifications_bar_chart", "alerts_bar_chart"]: # -> v2.0.0b6 introduced the different render modes _transform_event_bar_chart_dashlet(dashlet_spec) return dashlet_spec
def test_transform_graph_render_options(entry, result): assert valuespecs.transform_graph_render_options(entry) == result