コード例 #1
0
    def create_graph_recipes(self, ident_info, destination=None):
        graph_identification_info = ident_info

        def get_info(key):
            try:
                return graph_identification_info[key]
            except KeyError:
                raise MKUserError(
                    None,
                    _("Graph identification: The '%s' attribute is missing") %
                    key)

        site = get_info('site')
        host_name = get_info('host_name')
        service_description = get_info('service_description')
        row = get_graph_data_from_livestatus(site, host_name,
                                             service_description)
        translated_metrics = translated_metrics_from_row(row)

        graph_recipes = []
        for index, graph_template in matching_graph_templates(
                graph_identification_info,
                translated_metrics,
        ):
            graph_recipe = create_graph_recipe_from_template(
                graph_template,
                translated_metrics,
                row,
            )
            # Put the specification of this graph into the graph_recipe
            spec_info = graph_identification_info.copy()
            spec_info["graph_index"] = index
            graph_recipe["specification"] = ("template", spec_info)
            graph_recipes.append(graph_recipe)
        return graph_recipes
コード例 #2
0
ファイル: autocompleters.py プロジェクト: troelsarvin/checkmk
def _graph_choices_from_livestatus_row(row) -> Iterable[Tuple[str, str]]:
    def _metric_title_from_id(metric_or_graph_id: MetricName) -> str:
        metric_id = metric_or_graph_id.replace("METRIC_", "")
        return str(metric_info.get(metric_id, {}).get("title", metric_id))

    def _graph_template_title(graph_template: Mapping) -> str:
        return str(graph_template.get("title")) or _metric_title_from_id(
            graph_template["id"])

    yield from ((
        template["id"],
        _graph_template_title(template),
    ) for template in get_graph_templates(translated_metrics_from_row(row)))
コード例 #3
0
    def create_graph_recipes(self,
                             ident_info,
                             destination=None) -> Sequence[GraphRecipe]:
        graph_identification_info = ident_info

        def get_info(key):
            try:
                return graph_identification_info[key]
            except KeyError:
                raise MKUserError(
                    None,
                    _("Graph identification: The '%s' attribute is missing") %
                    key)

        site = get_info("site")
        host_name = get_info("host_name")
        service_description = get_info("service_description")
        row = get_graph_data_from_livestatus(site, host_name,
                                             service_description)
        translated_metrics = translated_metrics_from_row(row)

        graph_recipes = []
        for index, graph_template in matching_graph_templates(
                graph_identification_info,
                translated_metrics,
        ):
            graph_template_tuned = self.template_tuning(
                graph_template,
                site=site,
                host_name=host_name,
                service_description=service_description,
                destination=destination,
            )
            if graph_template_tuned is None:
                continue

            graph_recipe = create_graph_recipe_from_template(
                graph_template_tuned,
                translated_metrics,
                row,
            )
            # Put the specification of this graph into the graph_recipe
            spec_info = graph_identification_info.copy()
            # Performance graph dashlets already use graph_id, but for example in reports, we still
            # use graph_index. We should switch to graph_id everywhere (CMK-7308). Once this is
            # done, we can remove the line below.
            spec_info["graph_index"] = index
            spec_info["graph_id"] = graph_template_tuned["id"]
            graph_recipe["specification"] = ("template", spec_info)
            graph_recipes.append(graph_recipe)
        return graph_recipes