X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fdevops.git;a=blobdiff_plain;f=installers%2Fcharm%2Fgrafana%2Fsrc%2Fpod_spec.py;h=8d525f3aba11695ba2ed1f6b7aeb8b2ee4e1067c;hp=9915a9e4469d782cdc7178c061b3c987bab3ac50;hb=7527a6348d19ef4afbc11a20cec7f419aaf59c7d;hpb=b17e76b6df29ad727711175c2b6830a9db984a1d diff --git a/installers/charm/grafana/src/pod_spec.py b/installers/charm/grafana/src/pod_spec.py index 9915a9e4..8d525f3a 100644 --- a/installers/charm/grafana/src/pod_spec.py +++ b/installers/charm/grafana/src/pod_spec.py @@ -24,6 +24,8 @@ import logging from ipaddress import ip_network from typing import Any, Dict, List from urllib.parse import urlparse +from pathlib import Path +from string import Template logger = logging.getLogger(__name__) @@ -224,55 +226,79 @@ def _make_pod_ingress_resources( return [ingress] -def _make_pod_files(relation: Dict[str, Any]) -> List[Dict[str, Any]]: +def _make_pod_files( + config: Dict[str, Any], relation: Dict[str, Any] +) -> List[Dict[str, Any]]: """Generating ConfigMap information Args: + config (Dict[str, Any]): configuration information. relation (Dict[str, Any]): relation information. Returns: List[Dict[str, Any]]: ConfigMap information. """ + template_data = {**config, **relation} + dashboards = [] + + if config.get("osm_dashboards", False): + dashboards.extend( + [ + { + "path": "kafka_exporter_dashboard.yaml", + "content": Template( + Path("files/kafka_exporter_dashboard.yaml").read_text() + ), + }, + { + "path": "mongodb_exporter_dashboard.yaml", + "content": Template( + Path("files/mongodb_exporter_dashboard.yaml").read_text() + ), + }, + { + "path": "mysql_exporter_dashboard.yaml", + "content": Template( + Path("files/mysql_exporter_dashboard.yaml").read_text() + ), + }, + { + "path": "nodes_exporter_dashboard.yaml", + "content": Template( + Path("files/nodes_exporter_dashboard.yaml").read_text() + ), + }, + { + "path": "summary_dashboard.yaml", + "content": Template( + Path("files/summary_dashboard.yaml").read_text() + ), + }, + ] + ) + + dashboards.append( + { + "path": "dashboard_osm.yaml", + "content": Template(Path("files/default_dashboards.yaml").read_text()), + } + ) + files = [ { "name": "dashboards", "mountPath": "/etc/grafana/provisioning/dashboards/", - "files": [ - { - "path": "dashboard-osm.yml", - "content": ( - "apiVersion: 1\n" - "providers:\n" - " - name: 'osm'\n" - " orgId: 1\n" - " folder: ''\n" - " type: file\n" - " options:\n" - " path: /etc/grafana/provisioning/dashboards/\n" - ), - } - ], + "files": dashboards, }, { "name": "datasources", "mountPath": "/etc/grafana/provisioning/datasources/", "files": [ { - "path": "datasource-prometheus.yml", - "content": ( - "datasources:\n" - " - access: proxy\n" - " editable: true\n" - " is_default: true\n" - " name: osm_prometheus\n" - " orgId: 1\n" - " type: prometheus\n" - " version: 1\n" - " url: http://{}:{}\n".format( - relation.get("prometheus_host"), - relation.get("prometheus_port"), - ) - ), + "path": "datasource_prometheus.yaml", + "content": Template( + Path("files/default_dashboards.yaml").read_text() + ).substitute(template_data), } ], },