diff --git a/MANIFEST.in b/MANIFEST.in index 1842a72e0920e258d37be3cfd645fda7a4f9da39..cff7aadeb2cf4ea2296ae9e5e8c3b22045952df7 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,5 +2,4 @@ include brian_dashboard_manager/logging_default_config.json include brian_dashboard_manager/dashboards/* include brian_dashboard_manager/datasources/* include config.json.example -recursive-include brian_dashboard_manager/templating/templates * recursive-exclude test * \ No newline at end of file diff --git a/brian_dashboard_manager/grafana/organization.py b/brian_dashboard_manager/grafana/organization.py index 7115b83ff00c0407a8f54fe9a51217cd295c9b4d..32d458325b5680bb6f3afdc3f590b11d53d945ad 100644 --- a/brian_dashboard_manager/grafana/organization.py +++ b/brian_dashboard_manager/grafana/organization.py @@ -2,17 +2,16 @@ Grafana Organization management helpers. """ + +import logging import random import string -import logging -import jinja2 -import json -import os -from typing import Dict, List, Union from datetime import datetime -from brian_dashboard_manager.grafana.utils.request import AdminRequest, \ - TokenRequest +from typing import Dict, List, Union + from brian_dashboard_manager.grafana.dashboard import create_dashboard +from brian_dashboard_manager.grafana.utils.request import AdminRequest, TokenRequest +from brian_dashboard_manager.templating.homedashboard import render_homedashboard logger = logging.getLogger(__name__) @@ -146,19 +145,8 @@ def set_home_dashboard(request: TokenRequest, is_staff): :param is_staff: True if the organization is the staff organization :return: True if successful """ - - file = os.path.abspath(os.path.join( - os.path.dirname(__file__), - '..', - 'templating', - 'templates', - 'homedashboard.json.j2')) - - with open(file) as f: - template = jinja2.Template(f.read()) - rendered = template.render({'staff': is_staff}) - rendered = json.loads(rendered) - dashboard = create_dashboard(request, rendered) + payload = render_homedashboard(staff=is_staff) + dashboard = create_dashboard(request, payload) r = request.put('api/org/preferences', json={ 'homeDashboardId': dashboard.get('id') }).json() diff --git a/brian_dashboard_manager/templating/eumetsat.py b/brian_dashboard_manager/templating/eumetsat.py index 45cf2472a3eaa0327165948f1f581de99edf7283..e2717f2578566523a5795b37ecd5f88e588461f9 100644 --- a/brian_dashboard_manager/templating/eumetsat.py +++ b/brian_dashboard_manager/templating/eumetsat.py @@ -57,16 +57,16 @@ def get_panel_fields(panel, panel_type, datasource): # 'percentile': 'percentile' in alias.lower(), } - targets = [('Multicast Traffic', 'octets')] - - return create_panel({ + targets = [("Multicast Traffic", "octets")] + title = panel.pop("title").format(panel_type) + return create_panel( **panel, - 'datasource': datasource, - 'linewidth': 1, - 'title': panel['title'].format(panel_type), - 'panel_targets': [get_target_data(*target) for target in targets], - 'y_axis_type': 'bits', - }) + datasource=datasource, + linewidth=1, + title=title, + panel_targets=[get_target_data(*target) for target in targets], + y_axis_type="bits", + ) def subscription_panel_generator(gridPos): diff --git a/brian_dashboard_manager/templating/helpers.py b/brian_dashboard_manager/templating/helpers.py index c9bba091cf88b506a33d3ba4db7e1cf65057c3d2..b4ccaceb9135dc056d099dfc1bf1ff7c8d31c143 100644 --- a/brian_dashboard_manager/templating/helpers.py +++ b/brian_dashboard_manager/templating/helpers.py @@ -5,7 +5,6 @@ necessary data to generate the dashboards from templates. from collections import defaultdict from concurrent.futures import ProcessPoolExecutor import logging -import json from itertools import product from functools import partial, reduce from string import ascii_uppercase @@ -432,8 +431,8 @@ def get_aggregate_targets(targets): 'refId': ref_id, 'select_field': 'egress' } - ingress_target = create_panel_target(in_data) - egress_target = create_panel_target(out_data) + ingress_target = create_panel_target(**in_data) + egress_target = create_panel_target(**out_data) ingress.append(ingress_target) egress.append(egress_target) @@ -484,15 +483,16 @@ def get_panel_fields(panel, panel_type, datasource): fields = [*product(ingress, [in_field]), *product(egress, [out_field])] targets = error_fields if is_error else fields + title = panel.pop("title").format(panel_type) - return create_panel({ + return create_panel( **panel, - 'datasource': datasource, - 'linewidth': 1, - 'title': panel['title'].format(panel_type), - 'panel_targets': [get_target_data(*target) for target in targets], - 'y_axis_type': 'errors' if is_error else 'bits', - }) + datasource=datasource, + linewidth=1, + title=title, + panel_targets=[get_target_data(*target) for target in targets], + y_axis_type="errors" if is_error else "bits", + ) def default_interface_panel_generator(gridPos, use_all_traffic=True, use_ipv6=True): @@ -743,8 +743,7 @@ def create_aggregate_panel(title, gridpos, targets, datasource): is_total = 'totals' in title.lower() def reduce_alias(prev, curr): - d = json.loads(curr) - alias = d['alias'] + alias = curr['alias'] if 'egress' in alias.lower(): prev[alias] = '#0000FF' else: @@ -754,27 +753,27 @@ def create_aggregate_panel(title, gridpos, targets, datasource): ingress_colors = reduce(reduce_alias, ingress_targets, {}) egress_colors = reduce(reduce_alias, egress_targets, {}) - ingress = create_panel({ + ingress = create_panel( **ingress_pos, - 'stack': True, - 'linewidth': 0 if is_total else 1, - 'datasource': datasource, - 'title': title + ' - ingress', - 'targets': ingress_targets, - 'y_axis_type': 'bits', - 'alias_colors': json.dumps(ingress_colors) if is_total else {} - }) + stack=True, + linewidth=0 if is_total else 1, + datasource=datasource, + title=title + " - ingress", + targets=ingress_targets, + y_axis_type="bits", + alias_colors=ingress_colors if is_total else {}, + ) - egress = create_panel({ + egress = create_panel( **egress_pos, - 'stack': True, - 'linewidth': 0 if is_total else 1, - 'datasource': datasource, - 'title': title + ' - egress', - 'targets': egress_targets, - 'y_axis_type': 'bits', - 'alias_colors': json.dumps(egress_colors) if is_total else {} - }) + stack=True, + linewidth=0 if is_total else 1, + datasource=datasource, + title=title + " - egress", + targets=egress_targets, + y_axis_type="bits", + alias_colors=egress_colors if is_total else {}, + ) return ingress, egress diff --git a/brian_dashboard_manager/templating/homedashboard.py b/brian_dashboard_manager/templating/homedashboard.py new file mode 100644 index 0000000000000000000000000000000000000000..d28e732e52f434c9672911917563c5a16ef69778 --- /dev/null +++ b/brian_dashboard_manager/templating/homedashboard.py @@ -0,0 +1,1154 @@ +def render_homedashboard(staff): + return { + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": True, + "hide": True, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard", + } + ] + }, + "editable": True, + "gnetId": None, + "graphTooltip": 0, + "id": 49, + "uid": "home", + "iteration": 1595947519970, + "links": _render_links(staff), + "panels": _render_panels(staff), + "schemaVersion": 26, + "style": "dark", + "tags": [], + "templating": { + "list": ( + [ + { + "allValue": None, + "datasource": "PollerInfluxDB", + "definition": "SHOW TAG VALUES WITH KEY=hostname", + "hide": 0, + "includeAll": False, + "label": "Router:", + "multi": False, + "name": "hostname", + "options": [], + "query": "SHOW TAG VALUES WITH KEY=hostname", + "refresh": 1, + "regex": "", + "skipUrlSync": False, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": False, + }, + { + "allValue": None, + "datasource": "PollerInfluxDB", + "definition": "SHOW TAG VALUES WITH KEY IN (interface_name) WHERE hostname =~ /$hostname/ ", + "hide": 0, + "includeAll": False, + "label": "Interface :", + "multi": False, + "name": "interface_name", + "options": [], + "query": "SHOW TAG VALUES WITH KEY IN (interface_name) WHERE hostname =~ /$hostname/ ", + "refresh": 1, + "regex": "", + "skipUrlSync": False, + "sort": 0, + "tagValuesQuery": "", + "tags": [], + "tagsQuery": "", + "type": "query", + "useTags": False, + }, + ] + if staff + else [] + ) + }, + "time": {"from": "now-6h", "to": "now"}, + "timepicker": { + "refresh_intervals": [ + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d", + ] + }, + "timezone": "", + "title": "Home", + "version": 1, + } + + +def _render_links(staff): + result = [ + { + "asDropdown": True, + "icon": "external link", + "tags": ["services"], + "targetBlank": True, + "title": "Services", + "type": "dashboards", + }, + { + "asDropdown": True, + "icon": "external link", + "tags": ["infrastructure"], + "targetBlank": True, + "title": "Infrastructure", + "type": "dashboards", + }, + { + "asDropdown": True, + "icon": "external link", + "tags": ["customers"], + "targetBlank": True, + "title": "NREN Access", + "type": "dashboards", + }, + ] + if staff: + result.append( + { + "asDropdown": True, + "icon": "external link", + "tags": ["customersbeta"], + "targetBlank": True, + "title": "NREN Access BETA", + "type": "dashboards", + } + ) + result.append( + { + "asDropdown": True, + "icon": "external link", + "tags": ["peers"], + "targetBlank": True, + "title": "Peers", + "type": "dashboards", + } + ) + return result + + +def _render_panels(staff): + if staff: + return [ + { + "aliasColors": {}, + "bars": False, + "dashLength": 10, + "dashes": False, + "datasource": "PollerInfluxDB", + "fieldConfig": {"defaults": {"custom": {}}, "overrides": []}, + "fill": 1, + "fillGradient": 3, + "gridPos": {"h": 14, "w": 12, "x": 0, "y": 0}, + "hiddenSeries": False, + "id": 2, + "legend": { + "alignAsTable": True, + "avg": True, + "current": True, + "max": True, + "min": False, + "rightSide": False, + "show": True, + "total": False, + "values": True, + }, + "lines": True, + "linewidth": 1, + "nullPointMode": "null", + "percentage": False, + "pluginVersion": "7.1.1", + "pointradius": 2, + "points": False, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": False, + "steppedLine": False, + "targets": [ + { + "alias": "Ingress Traffic", + "groupBy": [ + {"params": ["5m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["ingress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + { + "alias": "Egress Traffic", + "groupBy": [ + {"params": ["5m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["egress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + { + "alias": "Ingress 95th Percentile", + "groupBy": [], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "C", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["ingress"], "type": "field"}, + {"params": [95], "type": "percentile"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "condition": None, + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + { + "alias": "Egress 95th Percentile", + "groupBy": [], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "D", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["egress"], "type": "field"}, + {"params": [95], "type": "percentile"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "condition": None, + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + ], + "thresholds": [], + "timeFrom": None, + "timeRegions": [], + "timeShift": None, + "title": "$hostname - $interface_name - Traffic", + "tooltip": {"shared": True, "sort": 0, "value_type": "individual"}, + "type": "graph", + "xaxis": { + "buckets": None, + "mode": "time", + "name": None, + "show": True, + "values": [], + }, + "yaxes": [ + { + "format": "bps", + "label": "bits per second", + "logBase": 1, + "max": None, + "min": None, + "show": True, + }, + { + "format": "bps", + "label": "bits per second", + "logBase": 1, + "max": None, + "min": None, + "show": True, + }, + ], + "yaxis": {"align": False, "alignLevel": None}, + }, + { + "aliasColors": {}, + "bars": False, + "dashLength": 10, + "dashes": False, + "datasource": "PollerInfluxDB", + "fieldConfig": {"defaults": {"custom": {}}, "overrides": []}, + "fill": 1, + "fillGradient": 3, + "gridPos": {"h": 14, "w": 12, "x": 12, "y": 0}, + "hiddenSeries": False, + "id": 3, + "legend": { + "alignAsTable": True, + "avg": True, + "current": True, + "max": True, + "min": False, + "rightSide": False, + "show": True, + "total": False, + "values": True, + }, + "lines": True, + "linewidth": 1, + "nullPointMode": "null", + "percentage": False, + "pluginVersion": "7.1.1", + "pointradius": 2, + "points": False, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": False, + "steppedLine": False, + "targets": [ + { + "alias": "Inbound", + "groupBy": [ + {"params": ["5m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["ingressv6"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + { + "alias": "Outbound", + "groupBy": [ + {"params": ["5m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["egressv6"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + { + "alias": "Ingress 95th Percentile", + "groupBy": [], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "C", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["ingressv6"], "type": "field"}, + {"params": [95], "type": "percentile"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "condition": None, + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + { + "alias": "Egress 95th Percentile", + "groupBy": [], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "D", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["egressv6"], "type": "field"}, + {"params": [95], "type": "percentile"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "condition": None, + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + ], + "thresholds": [], + "timeFrom": None, + "timeRegions": [], + "timeShift": None, + "title": "$hostname - $interface_name - IPv6 Traffic", + "tooltip": {"shared": True, "sort": 0, "value_type": "individual"}, + "type": "graph", + "xaxis": { + "buckets": None, + "mode": "time", + "name": None, + "show": True, + "values": [], + }, + "yaxes": [ + { + "format": "bps", + "label": "bits per second", + "logBase": 1, + "max": None, + "min": None, + "show": True, + }, + { + "format": "bps", + "label": "bits per second", + "logBase": 1, + "max": None, + "min": None, + "show": True, + }, + ], + "yaxis": {"align": False, "alignLevel": None}, + }, + { + "aliasColors": {}, + "bars": False, + "dashLength": 10, + "dashes": False, + "datasource": "PollerInfluxDB", + "decimals": 2, + "fill": 1, + "fillGradient": 10, + "gridPos": {"h": 14, "w": 12, "x": 0, "y": 14}, + "hiddenSeries": False, + "id": 4, + "legend": { + "alignAsTable": True, + "avg": True, + "current": True, + "max": True, + "min": False, + "rightSide": False, + "show": True, + "total": False, + "values": True, + }, + "lines": True, + "linewidth": 1, + "nullPointMode": "null", + "options": {"alertThreshold": True}, + "percentage": False, + "pluginVersion": "8.2.5", + "pointradius": 2, + "points": False, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": False, + "steppedLine": False, + "targets": [ + { + "alias": "Ingress Errors", + "groupBy": [ + {"params": ["5m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["errorsIn"], "type": "field"}, + {"params": [], "type": "mean"}, + ] + ], + "tags": [ + { + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + { + "alias": "Egress Errors", + "groupBy": [ + {"params": ["5m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["errorsOut"], "type": "field"}, + {"params": [], "type": "mean"}, + ] + ], + "tags": [ + { + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + { + "alias": "Ingress Discards", + "groupBy": [ + {"params": ["5m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "C", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["discardsIn"], "type": "field"}, + {"params": [], "type": "mean"}, + ] + ], + "tags": [ + { + "condition": None, + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + { + "alias": "Egress Discards", + "groupBy": [ + {"params": ["5m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "hide": False, + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "D", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["discardsOut"], "type": "field"}, + {"params": [], "type": "mean"}, + ] + ], + "tags": [ + { + "condition": None, + "key": "hostname", + "operator": "=~", + "value": "/^$hostname$/", + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=~", + "value": "/^$interface_name$/", + }, + ], + }, + ], + "thresholds": [], + "timeFrom": None, + "timeRegions": [], + "timeShift": None, + "title": "$hostname - $interface_name - errors", + "tooltip": {"shared": True, "sort": 0, "value_type": "individual"}, + "type": "graph", + "xaxis": { + "buckets": None, + "mode": "time", + "name": None, + "show": True, + "values": [], + }, + "yaxes": [ + { + "$$hashKey": "object:45", + "format": "none", + "label": "errors and discards per second", + "logBase": 1, + "max": None, + "min": "0", + "show": True, + }, + { + "$$hashKey": "object:46", + "format": "none", + "label": "errors and discards per second", + "logBase": 1, + "max": None, + "min": "0", + "show": True, + }, + ], + "yaxis": {"align": False, "alignLevel": None}, + }, + ] + return [ + { + "aliasColors": {}, + "bars": False, + "dashLength": 10, + "dashes": False, + "datasource": None, + "fieldConfig": {"defaults": {"custom": {}}, "overrides": []}, + "fill": 1, + "fillGradient": 0, + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 0}, + "hiddenSeries": False, + "id": 6, + "legend": { + "avg": False, + "current": False, + "max": False, + "min": False, + "show": True, + "total": False, + "values": False, + }, + "lines": True, + "linewidth": 1, + "nullPointMode": "null", + "options": {"alertThreshold": True}, + "percentage": False, + "pluginVersion": "7.2.1", + "pointradius": 2, + "points": False, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": True, + "steppedLine": False, + "targets": [ + { + "alias": "Private", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["ingress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_PRIVATE", + } + ], + }, + { + "alias": "R&E Interconnect", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["null"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "C", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["ingress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["* 8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_RE_INTERCONNECT", + } + ], + }, + { + "alias": "Public", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["null"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "D", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["ingress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["* 8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_PUBLIC", + } + ], + }, + { + "alias": "Upstream", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["null"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "E", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["ingress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["* 8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_UPSTREAM", + } + ], + }, + { + "alias": "Customer", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "query": ( + 'SELECT mean("ingress") *8 FROM "interface_rates" WHERE ("interface_name" =' + " 'PHY_CUSTOMER') AND $timeFilter GROUP BY time($__interval) fill(linear)" + ), + "rawQuery": False, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["ingress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_CUSTOMER", + } + ], + }, + ], + "thresholds": [], + "timeFrom": None, + "timeRegions": [], + "timeShift": None, + "title": "Network Aggregate (Ingress)", + "tooltip": {"shared": True, "sort": 0, "value_type": "individual"}, + "type": "graph", + "xaxis": { + "buckets": None, + "mode": "time", + "name": None, + "show": True, + "values": [], + }, + "yaxes": [ + { + "format": "bps", + "label": None, + "logBase": 1, + "max": None, + "min": None, + "show": True, + }, + { + "format": "short", + "label": None, + "logBase": 1, + "max": None, + "min": None, + "show": True, + }, + ], + "yaxis": {"align": False, "alignLevel": None}, + }, + { + "aliasColors": {}, + "bars": False, + "dashLength": 10, + "dashes": False, + "datasource": None, + "fieldConfig": {"defaults": {"custom": {}}, "overrides": []}, + "fill": 1, + "fillGradient": 0, + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 0}, + "hiddenSeries": False, + "id": 7, + "legend": { + "avg": False, + "current": False, + "max": False, + "min": False, + "show": True, + "total": False, + "values": False, + }, + "lines": True, + "linewidth": 1, + "nullPointMode": "null", + "options": {"alertThreshold": True}, + "percentage": False, + "pluginVersion": "7.2.1", + "pointradius": 2, + "points": False, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": True, + "steppedLine": False, + "targets": [ + { + "alias": "Private", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "B", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["egress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_PRIVATE", + } + ], + }, + { + "alias": "R&E Interconnect", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["null"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "C", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["egress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["* 8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_RE_INTERCONNECT", + } + ], + }, + { + "alias": "Public", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["null"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "D", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["egress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["* 8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_PUBLIC", + } + ], + }, + { + "alias": "Upstream", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["null"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "refId": "E", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["egress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["* 8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_UPSTREAM", + } + ], + }, + { + "alias": "Customer", + "groupBy": [ + {"params": ["15m"], "type": "time"}, + {"params": ["linear"], "type": "fill"}, + ], + "measurement": "interface_rates", + "orderByTime": "ASC", + "policy": "default", + "query": ( + 'SELECT mean("ingress") *8 FROM "interface_rates" WHERE ("interface_name" =' + " 'PHY_CUSTOMER') AND $timeFilter GROUP BY time($__interval) fill(linear)" + ), + "rawQuery": False, + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + {"params": ["egress"], "type": "field"}, + {"params": [], "type": "mean"}, + {"params": ["*8"], "type": "math"}, + ] + ], + "tags": [ + { + "key": "interface_name", + "operator": "=", + "value": "PHY_CUSTOMER", + } + ], + }, + ], + "thresholds": [], + "timeFrom": None, + "timeRegions": [], + "timeShift": None, + "title": "Network Aggregate (Egress)", + "tooltip": {"shared": True, "sort": 0, "value_type": "individual"}, + "type": "graph", + "xaxis": { + "buckets": None, + "mode": "time", + "name": None, + "show": True, + "values": [], + }, + "yaxes": [ + { + "format": "bps", + "label": None, + "logBase": 1, + "max": None, + "min": None, + "show": True, + }, + { + "format": "short", + "label": None, + "logBase": 1, + "max": None, + "min": None, + "show": True, + }, + ], + "yaxis": {"align": False, "alignLevel": None}, + }, + ] diff --git a/brian_dashboard_manager/templating/render.py b/brian_dashboard_manager/templating/render.py index 1885f3ed488452de1f580aa63e4bc5de66f145a7..e77573a2343c884a57b5fc3e55973c2b53bf9756 100644 --- a/brian_dashboard_manager/templating/render.py +++ b/brian_dashboard_manager/templating/render.py @@ -1,80 +1,35 @@ -""" -Methods for rendering of the -various Jinja templates from the given data. -""" -import os -import json -import jinja2 - - -def _read_template(filename): - """ - Reads the template from the given filename. - - :param filename: path to the template file - - :return: template - """ - with open(filename) as f: - return jinja2.Template(f.read()) - - -dropdown_template_file = os.path.abspath(os.path.join( - os.path.dirname(__file__), - 'templates', - 'shared', - 'dropdown.json.j2')) - -yaxes_template_file = os.path.abspath(os.path.join( - os.path.dirname(__file__), - 'templates', - 'shared', - 'yaxes.json.j2')) - -panel_template_file = file = os.path.abspath(os.path.join( - os.path.dirname(__file__), - 'templates', - 'shared', - 'panel.json.j2')) - -panel_target_template_file = os.path.abspath(os.path.join( - os.path.dirname(__file__), - 'templates', - 'shared', - 'panel_target.json.j2')) - -nren_dashboard_template_file = os.path.abspath(os.path.join( - os.path.dirname(__file__), - 'templates', - 'nren_access', - 'nren-dashboard.json.j2')) - -dashboard_template_file = os.path.abspath(os.path.join( - os.path.dirname(__file__), - 'templates', - 'shared', - 'dashboard.json.j2')) - - -DROPDOWN_TEMPLATE = _read_template(dropdown_template_file) -YAXES_TEMPLATE = _read_template(yaxes_template_file) -PANEL_TEMPLATE = _read_template(panel_template_file) -PANEL_TARGET_TEMPLATE = _read_template(panel_target_template_file) -NREN_DASHBOARD_TEMPLATE = _read_template(nren_dashboard_template_file) -DASHBOARD_TEMPLATE = _read_template(dashboard_template_file) - - -def create_dropdown_panel(title, **kwargs): +def create_dropdown_panel(title, id, y, **kwargs): """ Creates a dropdown panel from the given data. :param title: title of the dropdown panel + :param id: id of the dropdown panel + :param y: y of the dropdown panel :param kwargs: data to be used in the template :return: rendered dropdown panel JSON """ - - return DROPDOWN_TEMPLATE.render({**kwargs, 'title': title}) + return { + "aliasColors": {}, + "collapsed": False, + "datasource": None, + "fill": None, + "fillGradient": None, + "gridPos": {"h": 1, "w": 24, "x": 0, "y": y}, + "id": id, + "legend": None, + "lines": None, + "linewidth": None, + "search": None, + "stack": None, + "tags": None, + "targets": None, + "title": title, + "type": "row", + "xaxis": None, + "yaxes": None, + "yaxis": None, + } def create_yaxes(type): @@ -85,11 +40,62 @@ def create_yaxes(type): :return: rendered yaxes JSON """ - - return YAXES_TEMPLATE.render({'type': type}) - - -def create_panel_target(data): + if type == "errors": + return [ + { + "format": "none", + "label": "errors and discards per second", + "logBase": 1, + "max": None, + "min": 0, + "show": True, + }, + { + "format": "none", + "label": "errors and discards per second", + "logBase": 1, + "max": None, + "min": 0, + "show": True, + }, + ] + else: + return [ + { + "format": "bps", + "label": "bits per second", + "logBase": 1, + "max": None, + "min": "", + "show": True, + }, + { + "format": "bps", + "label": "bits per second", + "logBase": 1, + "max": None, + "min": "", + "show": True, + }, + ] + + +def create_panel_target( + alias, + select_field, + refId, + percentile=False, + measurement="interface_rates", + errors=False, + isp=None, + subscription=None, + scid=None, + interface_tag=None, + nren=None, + hostname=None, + interface=None, + **_ +): """ Creates a panel target from the given data. A panel target defines how to query data for a single timeseries. @@ -98,11 +104,85 @@ def create_panel_target(data): :return: rendered panel target JSON """ - - return PANEL_TARGET_TEMPLATE.render(data) - - -def create_panel(data): + select = [{"params": [select_field], "type": "field"}] + select.append( + {"params": [95], "type": "percentile"} + if percentile + else {"params": [], "type": "max"} + ) + if not errors: + select.append({"params": ["*8"], "type": "math"}) + if isp: + tags = [ + {"condition": None, "key": "tag", "operator": "=", "value": interface_tag}, + {"condition": "AND", "key": "isp", "operator": "=", "value": isp}, + {"condition": "AND", "key": "nren", "operator": "=", "value": nren}, + ] + elif subscription: + tags = [ + {"condition": None, "key": "hostname", "operator": "=", "value": hostname}, + { + "condition": "AND", + "key": "subscription", + "operator": "=", + "value": subscription, + }, + ] + elif scid: + tags = [{"condition": None, "key": "scid", "operator": "=", "value": scid}] + else: + tags = [ + { + "condition": None, + "key": "hostname", + "operator": "=", + "value": hostname, + }, + { + "condition": "AND", + "key": "interface_name", + "operator": "=", + "value": interface, + }, + ] + result = { + "alias": alias, + "groupBy": ( + [] + if percentile + else [ + {"params": ["$__interval"], "type": "time"}, + {"params": ["null"], "type": "fill"}, + ] + ), + "measurement": measurement, + "orderByTime": None, + "policy": None, + "refId": refId, + "resultFormat": "time_series", + "select": [select], + "tags": tags, + } + return result + + +def create_panel( + title, + height, + width, + linewidth, + y, + id, + datasource, + x=0, + alias_colors=None, + disable_legend=False, + stack=False, + y_axis_type="bits", + targets=None, + panel_targets=None, + **_ +): """ Creates a panel from the given data. Constructs the yaxes and panel targets and renders the panel template using these. @@ -111,12 +191,72 @@ def create_panel(data): :return: rendered panel JSON """ - - yaxes = create_yaxes(data.get('y_axis_type', 'bits')) - targets = data.get('targets', []) - for target in data.get('panel_targets', []): - targets.append(create_panel_target(target)) - return PANEL_TEMPLATE.render({**data, 'yaxes': yaxes, 'targets': targets}) + yaxes = create_yaxes(y_axis_type) + + result = { + "aliasColors": alias_colors or {}, + "bars": False, + "collapsed": None, + "dashLength": 10, + "dashes": False, + "datasource": datasource, + "decimals": 2, + "fieldConfig": {"defaults": {"custom": {}}, "overrides": []}, + "fill": 1, + "fillGradient": 10, + "gridPos": {"h": height, "w": width, "x": x, "y": y}, + "hiddenSeries": False, + "id": id, + "lines": True, + "linewidth": linewidth, + "nullPointMode": "null", + "options": {"alertThreshold": True}, + "percentage": False, + "pointradius": 2, + "points": False, + "renderer": "flot", + "search": None, + "seriesOverrides": [], + "spaceLength": 10, + "stack": stack, + "steppedLine": False, + "tags": None, + "thresholds": [], + "timeFrom": None, + "timeRegions": [], + "timeShift": None, + "title": title, + "tooltip": {"shared": True, "sort": 0, "value_type": "individual"}, + "type": "graph", + "xaxis": { + "buckets": None, + "mode": "time", + "name": None, + "show": True, + "values": None, + }, + "yaxes": yaxes, + "yaxis": {"align": False, "alignLevel": None}, + "targets": [], + } + if not disable_legend: + result["legend"] = { + "alignAsTable": True, + "avg": True, + "current": True, + "max": True, + "min": False, + "rightSide": None, + "show": True, + "total": False, + "values": True, + } + + targets = targets or [] + for target in panel_targets or []: + targets.append(create_panel_target(**target)) + result["targets"] = targets + return result def render_dashboard(dashboard, nren=False): @@ -132,12 +272,105 @@ def render_dashboard(dashboard, nren=False): """ if nren: - template = NREN_DASHBOARD_TEMPLATE + return render_nren_dashboard(**dashboard) else: - template = DASHBOARD_TEMPLATE - - rendered = template.render(dashboard) - rendered = json.loads(rendered) - rendered['uid'] = None - rendered['id'] = None - return rendered + return render_standard_dashboard(**dashboard) + + +def render_nren_dashboard( + nren_name, aggregate_panels, dropdown_groups, tag=None, tags=None, **_ +): + assert tag or tags + panels = [ + { + "datasource": None, + "gridPos": {"h": 1, "w": 24, "x": 0, "y": 0}, + "id": 1, + "options": {"content": "", "mode": "html"}, + "pluginVersion": "8.2.5", + "title": "INFO: The average values displayed are only mean values for timescales of 2 days or less", + "type": "text", + } + ] + panels.extend(aggregate_panels) + for group in dropdown_groups: + panels.append(group["dropdown"]) + panels.extend(group["panels"]) + + return { + "id": None, + "uid": None, + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": True, + "hide": True, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard", + } + ] + }, + "editable": False, + "gnetId": None, + "graphTooltip": 0, + "schemaVersion": 27, + "style": "dark", + "tags": tags or [tag], + "templating": {"list": []}, + "time": {"from": "now-24h", "to": "now"}, + "timepicker": {}, + "timezone": "", + "title": nren_name, + "version": 1, + "links": [], + "panels": panels, + } + + +def render_standard_dashboard(title, tag=None, tags=None, panels=None, **_): + assert tag or tags + return { + "id": None, + "uid": None, + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": True, + "hide": True, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard", + } + ] + }, + "editable": False, + "gnetId": None, + "graphTooltip": 0, + "schemaVersion": 27, + "style": "dark", + "tags": tags or [tag], + "templating": {"list": []}, + "time": {"from": "now-24h", "to": "now"}, + "timepicker": {}, + "timezone": "", + "title": title, + "version": 1, + "links": [], + "panels": [ + { + "datasource": None, + "gridPos": {"h": 1, "w": 24, "x": 0, "y": 0}, + "id": 1, + "options": {"content": "", "mode": "html"}, + "pluginVersion": "8.2.5", + "title": "INFO: The average values displayed are only mean values for timescales of 2 days or less", + "type": "text", + }, + *(panels or []), + ], + } diff --git a/brian_dashboard_manager/templating/templates/homedashboard.json.j2 b/brian_dashboard_manager/templating/templates/homedashboard.json.j2 deleted file mode 100644 index d29f738a29a70e797cf521ce556be9a88f0a2e76..0000000000000000000000000000000000000000 --- a/brian_dashboard_manager/templating/templates/homedashboard.json.j2 +++ /dev/null @@ -1,1686 +0,0 @@ -{ - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": "-- Grafana --", - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "type": "dashboard" - } - ] - }, - "editable": true, - "gnetId": null, - "graphTooltip": 0, - "id": 49, - "uid": "home", - "iteration": 1595947519970, - "links": [ - { - "asDropdown": true, - "icon": "external link", - "tags": [ - "services" - ], - "targetBlank": true, - "title": "Services", - "type": "dashboards" - }, - { - "asDropdown": true, - "icon": "external link", - "tags": [ - "infrastructure" - ], - "targetBlank": true, - "title": "Infrastructure", - "type": "dashboards" - }, - { - "asDropdown": true, - "icon": "external link", - "tags": [ - "customers" - ], - "targetBlank": true, - "title": "NREN Access", - "type": "dashboards" - }, - {% if staff %} - { - "asDropdown": true, - "icon": "external link", - "tags": [ - "customersbeta" - ], - "targetBlank": true, - "title": "NREN Access BETA", - "type": "dashboards" - }, - {% endif %} - { - "asDropdown": true, - "icon": "external link", - "tags": [ - "peers" - ], - "targetBlank": true, - "title": "Peers", - "type": "dashboards" - } - ], - "panels": [ - {% if staff %} - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PollerInfluxDB", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 3, - "gridPos": { - "h": 14, - "w": 12, - "x": 0, - "y": 0 - }, - "hiddenSeries": false, - "id": 2, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "max": true, - "min": false, - "rightSide": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "percentage": false, - "pluginVersion": "7.1.1", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "alias": "Ingress Traffic", - "groupBy": [ - { - "params": [ - "5m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "A", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "ingress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - }, - { - "alias": "Egress Traffic", - "groupBy": [ - { - "params": [ - "5m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "B", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "egress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - }, - { - "alias": "Ingress 95th Percentile", - "groupBy": [], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "C", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "ingress" - ], - "type": "field" - }, - { - "params": [ - 95 - ], - "type": "percentile" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "condition": null, - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - }, - { - "alias": "Egress 95th Percentile", - "groupBy": [], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "D", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "egress" - ], - "type": "field" - }, - { - "params": [ - 95 - ], - "type": "percentile" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "condition": null, - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "$hostname - $interface_name - Traffic", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "bps", - "label": "bits per second", - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "bps", - "label": "bits per second", - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PollerInfluxDB", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 3, - "gridPos": { - "h": 14, - "w": 12, - "x": 12, - "y": 0 - }, - "hiddenSeries": false, - "id": 3, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "max": true, - "min": false, - "rightSide": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "percentage": false, - "pluginVersion": "7.1.1", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "alias": "Inbound", - "groupBy": [ - { - "params": [ - "5m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "A", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "ingressv6" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - }, - { - "alias": "Outbound", - "groupBy": [ - { - "params": [ - "5m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "B", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "egressv6" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - }, - { - "alias": "Ingress 95th Percentile", - "groupBy": [], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "C", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "ingressv6" - ], - "type": "field" - }, - { - "params": [ - 95 - ], - "type": "percentile" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "condition": null, - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - }, - { - "alias": "Egress 95th Percentile", - "groupBy": [], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "D", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "egressv6" - ], - "type": "field" - }, - { - "params": [ - 95 - ], - "type": "percentile" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "condition": null, - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "$hostname - $interface_name - IPv6 Traffic", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "bps", - "label": "bits per second", - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "bps", - "label": "bits per second", - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "PollerInfluxDB", - "decimals": 2, - "fill": 1, - "fillGradient": 10, - "gridPos": { - "h": 14, - "w": 12, - "x": 0, - "y": 14 - }, - "hiddenSeries": false, - "id": 4, - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "max": true, - "min": false, - "rightSide": false, - "show": true, - "total": false, - "values": true - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pluginVersion": "8.2.5", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "alias": "Ingress Errors", - "groupBy": [ - { - "params": [ - "5m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "A", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "errorsIn" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - } - ] - ], - "tags": [ - { - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - }, - { - "alias": "Egress Errors", - "groupBy": [ - { - "params": [ - "5m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "B", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "errorsOut" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - } - ] - ], - "tags": [ - { - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - }, - { - "alias": "Ingress Discards", - "groupBy": [ - { - "params": [ - "5m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "C", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "discardsIn" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - } - ] - ], - "tags": [ - { - "condition": null, - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - }, - { - "alias": "Egress Discards", - "groupBy": [ - { - "params": [ - "5m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "hide": false, - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "D", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "discardsOut" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - } - ] - ], - "tags": [ - { - "condition": null, - "key": "hostname", - "operator": "=~", - "value": "/^$hostname$/" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=~", - "value": "/^$interface_name$/" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "$hostname - $interface_name - errors", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "$$hashKey": "object:45", - "format": "none", - "label": "errors and discards per second", - "logBase": 1, - "max": null, - "min": "0", - "show": true - }, - { - "$$hashKey": "object:46", - "format": "none", - "label": "errors and discards per second", - "logBase": 1, - "max": null, - "min": "0", - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - } - {% else %} - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": null, - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 12, - "x": 0, - "y": 0 - }, - "hiddenSeries": false, - "id": 6, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pluginVersion": "7.2.1", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": true, - "steppedLine": false, - "targets": [ - { - "alias": "Private", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "B", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "ingress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_PRIVATE" - } - ] - }, - { - "alias": "R&E Interconnect", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "null" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "C", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "ingress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "* 8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_RE_INTERCONNECT" - } - ] - }, - { - "alias": "Public", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "null" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "D", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "ingress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "* 8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_PUBLIC" - } - ] - }, - { - "alias": "Upstream", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "null" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "E", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "ingress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "* 8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_UPSTREAM" - } - ] - }, - { - "alias": "Customer", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "query": "SELECT mean(\"ingress\") *8 FROM \"interface_rates\" WHERE (\"interface_name\" = 'PHY_CUSTOMER') AND $timeFilter GROUP BY time($__interval) fill(linear)", - "rawQuery": false, - "refId": "A", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "ingress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_CUSTOMER" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Network Aggregate (Ingress)", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "bps", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": null, - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 12, - "x": 12, - "y": 0 - }, - "hiddenSeries": false, - "id": 7, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pluginVersion": "7.2.1", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": true, - "steppedLine": false, - "targets": [ - { - "alias": "Private", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "B", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "egress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_PRIVATE" - } - ] - }, - { - "alias": "R&E Interconnect", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "null" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "C", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "egress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "* 8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_RE_INTERCONNECT" - } - ] - }, - { - "alias": "Public", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "null" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "D", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "egress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "* 8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_PUBLIC" - } - ] - }, - { - "alias": "Upstream", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "null" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "refId": "E", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "egress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "* 8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_UPSTREAM" - } - ] - }, - { - "alias": "Customer", - "groupBy": [ - { - "params": [ - "15m" - ], - "type": "time" - }, - { - "params": [ - "linear" - ], - "type": "fill" - } - ], - "measurement": "interface_rates", - "orderByTime": "ASC", - "policy": "default", - "query": "SELECT mean(\"ingress\") *8 FROM \"interface_rates\" WHERE (\"interface_name\" = 'PHY_CUSTOMER') AND $timeFilter GROUP BY time($__interval) fill(linear)", - "rawQuery": false, - "refId": "A", - "resultFormat": "time_series", - "select": [ - [ - { - "params": [ - "egress" - ], - "type": "field" - }, - { - "params": [], - "type": "mean" - }, - { - "params": [ - "*8" - ], - "type": "math" - } - ] - ], - "tags": [ - { - "key": "interface_name", - "operator": "=", - "value": "PHY_CUSTOMER" - } - ] - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Network Aggregate (Egress)", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "bps", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } - } - {% endif %} - ], - "schemaVersion": 26, - "style": "dark", - "tags": [], - "templating": { - "list": [ - {% if staff %} - { - "allValue": null, - "datasource": "PollerInfluxDB", - "definition": "SHOW TAG VALUES WITH KEY=hostname", - "hide": 0, - "includeAll": false, - "label": "Router:", - "multi": false, - "name": "hostname", - "options": [], - "query": "SHOW TAG VALUES WITH KEY=hostname", - "refresh": 1, - "regex": "", - "skipUrlSync": false, - "sort": 0, - "tagValuesQuery": "", - "tags": [], - "tagsQuery": "", - "type": "query", - "useTags": false - }, - { - "allValue": null, - "datasource": "PollerInfluxDB", - "definition": "SHOW TAG VALUES WITH KEY IN (interface_name) WHERE hostname =~ /$hostname/ ", - "hide": 0, - "includeAll": false, - "label": "Interface :", - "multi": false, - "name": "interface_name", - "options": [], - "query": "SHOW TAG VALUES WITH KEY IN (interface_name) WHERE hostname =~ /$hostname/ ", - "refresh": 1, - "regex": "", - "skipUrlSync": false, - "sort": 0, - "tagValuesQuery": "", - "tags": [], - "tagsQuery": "", - "type": "query", - "useTags": false - } - {% endif %} - ] - }, - "time": { - "from": "now-6h", - "to": "now" - }, - "timepicker": { - "refresh_intervals": [ - "10s", - "30s", - "1m", - "5m", - "15m", - "30m", - "1h", - "2h", - "1d" - ] - }, - "timezone": "", - "title": "Home", - "version": 1 -} \ No newline at end of file diff --git a/brian_dashboard_manager/templating/templates/nren_access/nren-dashboard.json.j2 b/brian_dashboard_manager/templating/templates/nren_access/nren-dashboard.json.j2 deleted file mode 100644 index eeb9dbb9fb0151e4f25a0f100e495796bad1e2ff..0000000000000000000000000000000000000000 --- a/brian_dashboard_manager/templating/templates/nren_access/nren-dashboard.json.j2 +++ /dev/null @@ -1,73 +0,0 @@ -{ - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": "-- Grafana --", - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "type": "dashboard" - } - ] - }, - "editable": false, - "gnetId": null, - "graphTooltip": 0, - "schemaVersion": 27, - "style": "dark", - {% if not tags %} - "tags": ["{{ tag }}"], - {% else %} - "tags": [ - {% for tag in tags %} - "{{ tag }}"{{ "," if not loop.last }} - {% endfor %} - ], - {% endif %} - "templating": { - "list": [] - }, - "time": { - "from": "now-24h", - "to": "now" - }, - "timepicker": {}, - "timezone": "", - "title": "{{ nren_name }}", - "version": 1, - "links": [], - "panels": [ - { - "datasource": null, - "gridPos": { - "h": 1, - "w": 24, - "x": 0, - "y": 0 - }, - "id": 1, - "options": { - "content": "", - "mode": "html" - }, - "pluginVersion": "8.2.5", - "title": "INFO: The average values displayed are only mean values for timescales of 2 days or less", - "type": "text" - }, - {% for panel in aggregate_panels %} - {{ panel }}, - {% endfor %} - {% for group in dropdown_groups %} - {{ group.dropdown }} - {% if group.panels|length > 0 %} - , - {% endif %} - {% for panel in group.panels %} - {{ panel }}{{ "," if not loop.last }} - {% endfor %} - {{ "," if not loop.last }} - {% endfor %} - ] -} \ No newline at end of file diff --git a/brian_dashboard_manager/templating/templates/shared/dashboard.json.j2 b/brian_dashboard_manager/templating/templates/shared/dashboard.json.j2 deleted file mode 100644 index bbefccc38a500ec4bd4656e586cbf7d11b7aab4f..0000000000000000000000000000000000000000 --- a/brian_dashboard_manager/templating/templates/shared/dashboard.json.j2 +++ /dev/null @@ -1,63 +0,0 @@ -{ - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": "-- Grafana --", - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "type": "dashboard" - } - ] - }, - "editable": false, - "gnetId": null, - "graphTooltip": 0, - "schemaVersion": 27, - "style": "dark", - {% if not tags %} - "tags": ["{{ tag }}"], - {% else %} - "tags": [ - {% for tag in tags %} - "{{ tag }}"{{ "," if not loop.last }} - {% endfor %} - ], - {% endif %} - "templating": { - "list": [] - }, - "time": { - "from": "now-24h", - "to": "now" - }, - "timepicker": {}, - "timezone": "", - "title": "{{ title }}", - "version": 1, - "links": [], - "panels": [ - { - "datasource": null, - "gridPos": { - "h": 1, - "w": 24, - "x": 0, - "y": 0 - }, - "id": 1, - "options": { - "content": "", - "mode": "html" - }, - "pluginVersion": "8.2.5", - "title": "INFO: The average values displayed are only mean values for timescales of 2 days or less", - "type": "text" - }{{ "," if panels }} - {% for panel in panels %} - {{ panel }}{{ "," if not loop.last }} - {% endfor %} - ] -} \ No newline at end of file diff --git a/brian_dashboard_manager/templating/templates/shared/dropdown.json.j2 b/brian_dashboard_manager/templating/templates/shared/dropdown.json.j2 deleted file mode 100644 index ec3c1b8e7b17644c3a4caa60b6d3a95f9af48ea1..0000000000000000000000000000000000000000 --- a/brian_dashboard_manager/templating/templates/shared/dropdown.json.j2 +++ /dev/null @@ -1,26 +0,0 @@ -{ - "aliasColors": {}, - "collapsed": false, - "datasource": null, - "fill": null, - "fillGradient": null, - "gridPos": { - "h": 1, - "w": 24, - "x": 0, - "y": {{ y }} - }, - "id": {{ id }}, - "legend": null, - "lines": null, - "linewidth": null, - "search": null, - "stack": null, - "tags": null, - "targets": null, - "title": "{{ title }}", - "type": "row", - "xaxis": null, - "yaxes": null, - "yaxis": null -} \ No newline at end of file diff --git a/brian_dashboard_manager/templating/templates/shared/panel.json.j2 b/brian_dashboard_manager/templating/templates/shared/panel.json.j2 deleted file mode 100644 index 005e069176752e00082ad58c14348d5edd185b09..0000000000000000000000000000000000000000 --- a/brian_dashboard_manager/templating/templates/shared/panel.json.j2 +++ /dev/null @@ -1,96 +0,0 @@ -{ - {% if alias_colors %} - "aliasColors": {{ alias_colors }}, - {% else %} - "aliasColors": {}, - {% endif %} - "bars": false, - "collapsed": null, - "dashLength": 10, - "dashes": false, - "datasource": "{{ datasource }}", - "decimals": 2, - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 10, - "gridPos": { - "h": {{ height }}, - "w": {{ width }}, - {% if x %} - "x": {{ x }}, - {% else %} - "x": 0, - {% endif %} - "y": {{ y }} - }, - "hiddenSeries": false, - "id": {{ id }}, - {% if not disable_legend %} - "legend": { - "alignAsTable": true, - "avg": true, - "current": true, - "max": true, - "min": false, - "rightSide": null, - "show": true, - "total": false, - "values": true - }, - {% endif %} - "lines": true, - "linewidth": {{ linewidth }}, - "nullPointMode": "null", - "options": { - "alertThreshold": true - }, - "percentage": false, - "pointradius": 2, - "points": false, - "renderer": "flot", - "search": null, - "seriesOverrides": [], - "spaceLength": 10, - {% if stack %} - "stack": true, - {% else %} - "stack": false, - {% endif %} - "steppedLine": false, - "tags": null, - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "{{ title }}", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": null - }, - "yaxes": [ - {{ yaxes }} - ], - "yaxis": { - "align": false, - "alignLevel": null - }, - "targets": [ - {% for target in targets %} - {{ target }}{{ "," if not loop.last }} - {% endfor %} - ] -} \ No newline at end of file diff --git a/brian_dashboard_manager/templating/templates/shared/panel_target.json.j2 b/brian_dashboard_manager/templating/templates/shared/panel_target.json.j2 deleted file mode 100644 index b140cc06b9c64f79114c06cccc081b507e32b9a9..0000000000000000000000000000000000000000 --- a/brian_dashboard_manager/templating/templates/shared/panel_target.json.j2 +++ /dev/null @@ -1,104 +0,0 @@ -{ - "alias": "{{ alias }}", - "groupBy": [ - {% if not percentile %} - { - "params": ["$__interval"], - "type": "time" - }, - { - "params": ["null"], - "type": "fill" - } - {% endif %} - ], - {% if measurement %} - "measurement": "{{ measurement }}", - {% else %} - "measurement": "interface_rates", - {% endif %} - "orderByTime": null, - "policy": null, - "refId": "{{ refId }}", - "resultFormat": "time_series", - "select": [ - [ - { - "params": ["{{ select_field }}"], - "type": "field" - }, - {% if not percentile %} - { - "params": [], - "type": "max" - } - {% else %} - { - "params": [95], - "type": "percentile" - } - {% endif %} - {% if not errors %} - ,{ - "params": ["*8"], - "type": "math" - } - {% endif %} - ] - ], - "tags": [ - {% if isp %} - { - "condition": null, - "key": "tag", - "operator": "=", - "value": "{{ interface_tag }}" - }, - { - "condition": "AND", - "key": "isp", - "operator": "=", - "value": "{{ isp }}" - }, - { - "condition": "AND", - "key": "nren", - "operator": "=", - "value": "{{ nren }}" - } - {% elif subscription %} - { - "condition": null, - "key": "hostname", - "operator": "=", - "value": "{{ hostname }}" - }, - { - "condition": "AND", - "key": "subscription", - "operator": "=", - "value": "{{ subscription }}" - } - {% elif scid %} - { - "condition": null, - "key": "scid", - "operator": "=", - "value": "{{ scid }}" - } - {% else %} - { - "condition": null, - "key": "hostname", - "operator": "=", - "value": "{{ hostname }}" - }, - { - "condition": "AND", - "key": "interface_name", - "operator": "=", - "value": "{{ interface }}" - } - {% endif %} - ] -} \ No newline at end of file diff --git a/brian_dashboard_manager/templating/templates/shared/yaxes.json.j2 b/brian_dashboard_manager/templating/templates/shared/yaxes.json.j2 deleted file mode 100644 index 94e4555f92e15d1cb3bd91f7c988b73255a74ffe..0000000000000000000000000000000000000000 --- a/brian_dashboard_manager/templating/templates/shared/yaxes.json.j2 +++ /dev/null @@ -1,35 +0,0 @@ -{% if type == 'errors' %} -{ - "format": "none", - "label": "errors and discards per second", - "logBase": 1, - "max": null, - "min": 0, - "show": true -}, -{ - "format": "none", - "label": "errors and discards per second", - "logBase": 1, - "max": null, - "min": 0, - "show": true -} -{% else %} -{ - "format": "bps", - "label": "bits per second", - "logBase": 1, - "max": null, - "min": "", - "show": true -}, -{ - "format": "bps", - "label": "bits per second", - "logBase": 1, - "max": null, - "min": "", - "show": true -} -{% endif %} diff --git a/requirements.txt b/requirements.txt index b650084178d47fa18e888ba4ae3ffe970e1d9712..d7ef2533a16044f57822ee6681251830dc753982 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,6 @@ requests jsonschema flask -jinja2 pytest pytest-mock diff --git a/setup.py b/setup.py index c9a01c086022a621eb623aa34605f40c9bc0539d..9b630b2b1f3658bb3cc9882a3e6887a286e526ab 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,6 @@ setup( 'requests', 'jsonschema', 'flask', - 'jinja2', 'sentry-sdk[flask]' ], include_package_data=True, diff --git a/test/test_update.py b/test/test_update.py index 57b09f2057e5dfb234d0de0d59d8749d05104c7e..93b5badf5290a36c6635307b2017a80fb57c3d9c 100644 --- a/test/test_update.py +++ b/test/test_update.py @@ -1,3 +1,4 @@ +import pytest import responses import json @@ -603,104 +604,91 @@ def generate_folder(data): @responses.activate -def test_provision_folder(data_config, mocker): +@pytest.mark.parametrize( + "folder_name, excluded_nrens, expected_nrens", + [ + ("NREN Access", [], ["GEANT", "KIAE", "SWITCH"]), + ("NREN Access", ["GEANT", "KIAE"], ["SWITCH"]), + ( + "NREN Access BETA", + [], + ["ASNET-AM", "LITNET", "CESNET", "GEANT", "KIAE", "SWITCH"], + ), + ( + "NREN Access BETA", + ["ASNET-AM", "GEANT"], + ["LITNET", "CESNET", "KIAE", "SWITCH"], + ), + ("testfolder", ["GEANT"], ["KIAE", "SWITCH"]), + ], +) +def test_provision_nren_folder( + folder_name, excluded_nrens, expected_nrens, data_config, mocker +): dashboards = { - 'NREN': { - 'tag': ['customers'], - 'folder_name': 'NREN Access', - 'interfaces': [ - iface for iface in TEST_INTERFACES - if 'NREN' in iface['dashboards']] + "NREN": { + "tag": ["customers"], + "folder_name": "NREN Access", + "interfaces": [ + iface for iface in TEST_INTERFACES if "NREN" in iface["dashboards"] + ], }, - 'RE_CUST': { - 'tag': 'RE_CUST', - 'folder_name': 'RE Customer', - 'interfaces': [ - iface for iface in TEST_INTERFACES - if 'RE_CUST' in iface['dashboards']] + "RE_CUST": { + "tag": "RE_CUST", + "folder_name": "RE Customer", + "interfaces": [ + iface for iface in TEST_INTERFACES if "RE_CUST" in iface["dashboards"] + ], }, - } - responses.add( method=responses.GET, url=f"{data_config['reporting_provider']}/scid/current", - json=get_test_data('services.json')) + json=get_test_data("services.json"), + ) # just return a generated folder - _mocked_find_folder = mocker.patch( - 'brian_dashboard_manager.grafana.provision.find_folder') - _mocked_find_folder.return_value = generate_folder( - {'uid': 'testfolderuid', 'title': 'testfolder'}) + mocker.patch( + "brian_dashboard_manager.grafana.provision.find_folder", + return_value=generate_folder({"uid": "testfolderuid", "title": "testfolder"}), + ) def create_dashboard(request, dashboard, folder_id=None): return dashboard mocker.patch( - 'brian_dashboard_manager.grafana.provision.create_dashboard', - create_dashboard) + "brian_dashboard_manager.grafana.provision.create_dashboard", create_dashboard + ) def _search_dashboard(request, dashboard, folder_id=None): return None mocker.patch( - 'brian_dashboard_manager.grafana.dashboard._search_dashboard', - _search_dashboard) + "brian_dashboard_manager.grafana.dashboard._search_dashboard", _search_dashboard + ) def delete_dashboard(request, dashboard, folder_id=None): return True mocker.patch( - 'brian_dashboard_manager.grafana.dashboard.delete_dashboard', - delete_dashboard) - - excluded_dashboards = [] - nren_result = provision_folder( - None, 'NREN Access', dashboards['NREN'], - data_config, 'testdatasource', excluded_dashboards) - - assert len(nren_result) == 3 - assert nren_result[0]['title'] == 'GEANT' - assert nren_result[1]['title'] == 'KIAE' - assert nren_result[2]['title'] == 'SWITCH' - - excluded_dashboards = ['KIAE', 'GEANT'] - nren_excluded = provision_folder( - None, 'NREN Access', dashboards['NREN'], - data_config, 'testdatasource', excluded_dashboards) - - assert len(nren_excluded) == 1 - assert nren_excluded[0]['title'] == 'SWITCH' - - excluded_dashboards = [] - nren_result_beta = provision_folder( - None, 'NREN Access BETA', dashboards['NREN'], - data_config, 'testdatasource', excluded_dashboards) - - assert len(nren_result_beta) == 6 - assert nren_result_beta[0]['title'] == 'ASNET-AM' - assert nren_result_beta[1]['title'] == 'LITNET' - assert nren_result_beta[2]['title'] == 'CESNET' - assert nren_result_beta[3]['title'] == 'GEANT' - assert nren_result_beta[4]['title'] == 'KIAE' - assert nren_result_beta[5]['title'] == 'SWITCH' - - excluded_dashboards = ['ASNET-AM', 'GEANT'] - nren_excluded_beta = provision_folder( - None, 'NREN Access BETA', dashboards['NREN'], - data_config, 'testdatasource', excluded_dashboards) - - assert len(nren_excluded_beta) == 4 - assert nren_excluded_beta[0]['title'] == 'LITNET' - assert nren_excluded_beta[1]['title'] == 'CESNET' - assert nren_excluded_beta[2]['title'] == 'KIAE' - assert nren_excluded_beta[3]['title'] == 'SWITCH' - - cust_result = provision_folder(None, 'testfolder', dashboards['RE_CUST'], - data_config, 'testdatasource', ['GEANT']) - assert len(cust_result) == 2 - assert cust_result[0]['title'] == 'KIAE' - assert cust_result[1]['title'] == 'SWITCH' + "brian_dashboard_manager.grafana.dashboard.delete_dashboard", delete_dashboard + ) + + result = provision_folder( + None, + folder_name, + dashboards["NREN"], + data_config, + "testdatasource", + excluded_nrens, + ) + assert len(result) == len(expected_nrens) + for i, nren in enumerate(expected_nrens): + assert result[i]["title"] == nren + if "NREN" in folder_name: + # Every NREN dashboard must have at least 4 panels + # (3 default panels and 1 per ifc) + assert len(result[i]["panels"]) > 3 @responses.activate