X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Fcharm%2Fgrafana%2Fsrc%2Fcharm.py;h=caa0277969c9ccc3f5cdecbe06dc032a1a025cd2;hb=ee303f97b9afe276076f56220d73c6382aa65c48;hp=36bf69610a92fcc0d2ff97ce715139ca8f57c00d;hpb=540d93716ee0a4c4ffd070120779c1c40f6f353c;p=osm%2Fdevops.git diff --git a/installers/charm/grafana/src/charm.py b/installers/charm/grafana/src/charm.py index 36bf6961..caa02779 100755 --- a/installers/charm/grafana/src/charm.py +++ b/installers/charm/grafana/src/charm.py @@ -145,11 +145,25 @@ class GrafanaCharm(CharmedOsmBase): def _build_datasources_files(self): files_builder = FilesV3Builder() + prometheus_user = self.prometheus_client.user + prometheus_password = self.prometheus_client.password + enable_basic_auth = all([prometheus_user, prometheus_password]) + kwargs = { + "prometheus_host": self.prometheus_client.hostname, + "prometheus_port": self.prometheus_client.port, + "enable_basic_auth": enable_basic_auth, + "user": "", + "password": "", + } + if enable_basic_auth: + kwargs["user"] = f"basic_auth_user: {prometheus_user}" + kwargs[ + "password" + ] = f"secure_json_data:\n basicAuthPassword: {prometheus_password}" files_builder.add_file( "datasource_prometheus.yaml", Template(Path("templates/default_datasources.yaml").read_text()).substitute( - prometheus_host=self.prometheus_client.hostname, - prometheus_port=self.prometheus_client.port, + **kwargs ), ) return files_builder.build() @@ -195,6 +209,8 @@ class GrafanaCharm(CharmedOsmBase): { "admin-password": admin_initial_password, "mysql-url": mysql_config.mysql_uri or self.mysql_client.get_uri(), + "prometheus-user": self.prometheus_client.user, + "prometheus-password": self.prometheus_client.password, }, ) @@ -231,7 +247,6 @@ class GrafanaCharm(CharmedOsmBase): "/etc/grafana/provisioning/datasources/", self._build_datasources_files(), ) - container_builder.add_envs( { "GF_SERVER_HTTP_PORT": config.port, @@ -244,6 +259,8 @@ class GrafanaCharm(CharmedOsmBase): envs={ "GF_SECURITY_ADMIN_PASSWORD": "admin-password", "GF_DATABASE_URL": "mysql-url", + "PROMETHEUS_USER": "prometheus-user", + "PROMETHEUS_PASSWORD": "prometheus-password", }, ) container = container_builder.build()