Ejemplo n.º 1
0
    def _create_single_metric_config(cls, data, metrics, properties, context,
                                     settings):
        plot_definitions = []

        def svc_map(row):
            css_classes, status_name = paint_service_state_short(row)
            return {"style": css_classes, "msg": _("Status: ") + status_name}

        # Historic values are always added as plot_type area
        if properties["time_range"] != "current":
            for row_id, metric, row in metrics:
                plot_definition = {
                    "plot_type": "area",
                    "label": row['host_name'],
                    "id": row_id,
                    "use_tags": [row_id]
                }
                if "color" in metric:
                    plot_definition["color"] = metric["color"]
                plot_definitions.append(plot_definition)

        # The current/last value definition also gets the metric levels
        for row_id, metric, row in metrics:
            plot_definition = {
                "plot_type": "single_value",
                "id": "%s_single" % row_id,
                "use_tags": [row_id],
                "label": row['host_name'],
                "svc_state": svc_map(row),
                "metrics": {
                    "warn": metric["scalar"].get("warn"),
                    "crit": metric["scalar"].get("crit"),
                    "min": metric["scalar"].get("min"),
                    "max": metric["scalar"].get("max"),
                }
            }
            if "color" in metric:
                plot_definition["color"] = metric["color"]

            plot_definitions.append(plot_definition)

        response = {
            "plot_definitions": plot_definitions,
            "data": data,
        }
        title: List[Tuple[str, Optional[str]]] = []
        title_format = settings.get("title_format", ["plain"])

        if settings.get("show_title", True):
            if settings.get("title") and "plain" in title_format:
                title.append((settings.get("title"), ""))
            title.extend(
                title_info_elements(row,
                                    [f for f in title_format if f != "plain"]))

        response["title"] = " / ".join(txt for txt, _ in title)

        return response
Ejemplo n.º 2
0
    def _create_single_metric_config(cls, data, metrics, properties, context,
                                     settings):
        plot_definitions = []

        def svc_map(row):
            css_classes, status_name = paint_service_state_short(row)
            draw_status = properties.get("status_border", "not_ok")
            if draw_status == "not_ok" and css_classes.endswith("state0"):
                draw_status = False

            return {
                "style": css_classes,
                "msg": _("Status: ") + status_name,
                "draw": draw_status
            }

        # Historic values are always added as plot_type area
        if properties["time_range"] != "current":
            for row_id, metric, row in metrics:
                color = metric.get('color', "#008EFF") if properties.get(
                    "color", "default") == "default" else properties.get(
                        'color', "#008EFF")
                plot_definition = {
                    "label": row['host_name'],
                    "id": row_id,
                    "plot_type": "area",
                    "use_tags": [row_id],
                    "color": color,
                    "fill": properties.get("fill", True),
                    "opacity":
                    0.1 if properties.get('fill', True) is True else 0
                }
                plot_definitions.append(plot_definition)

        # The current/last value definition also gets the metric levels
        for row_id, metric, row in metrics:
            plot_definition = {
                "label": row['host_name'],
                "id": "%s_single" % row_id,
                "plot_type": "single_value",
                "use_tags": [row_id],
                "svc_state": svc_map(row),
                "js_render": metric['unit'].get("js_render"),
                "metrics": {
                    "warn": metric["scalar"].get("warn"),
                    "crit": metric["scalar"].get("crit"),
                    "min": metric["scalar"].get("min"),
                    "max": metric["scalar"].get("max"),
                }
            }
            if "color" in metric:
                plot_definition["color"] = metric["color"]

            plot_definitions.append(plot_definition)

        response = {
            "plot_definitions": plot_definitions,
            "data": data,
        }
        title: List[_Tuple[str, Optional[str]]] = []
        title_format = settings.get("title_format", ["plain"])

        if settings.get("show_title", True) and metrics:
            if settings.get("title") and "plain" in title_format:
                title.append((settings.get("title"), ""))
            title.extend(
                title_info_elements(metrics[0][2],
                                    [f for f in title_format if f != "plain"]))

        response["title"] = " / ".join(txt for txt, _ in title)

        return response