From: Atul Agarwal Date: Tue, 16 Mar 2021 11:02:14 +0000 (+0000) Subject: Fix for bug 1460 Admin dashboard in Grafana not created when using keystone as backend X-Git-Tag: branch-bug1511-start~4 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=282c9c9ecb963ab29bf38e4eab97a7788013b637;p=osm%2FMON.git Fix for bug 1460 Admin dashboard in Grafana not created when using keystone as backend Change-Id: Ia13e86445ba5cef9b5a8b5e9b1507060d345b22e Signed-off-by: Atul Agarwal (cherry picked from commit 7af74e4a511190ed6000ef2812ecf8bfdbc3531c) --- diff --git a/osm_mon/dashboarder/backends/grafana.py b/osm_mon/dashboarder/backends/grafana.py index a1cbcba..73459f7 100644 --- a/osm_mon/dashboarder/backends/grafana.py +++ b/osm_mon/dashboarder/backends/grafana.py @@ -75,12 +75,16 @@ class GrafanaBackend: dashboard_json_data["folderId"] = folder_id dashboard_json_data["overwrite"] = False - response = requests.request( - "POST", self.url + "/api/dashboards/db/", data=json.dumps(dashboard_json_data), headers=self.headers) + response = self.send_request_for_creating_dashboard(dashboard_json_data) - # Don't create the dashboard if already exists. + # Admin dashboard will be created if already exists. Rest will remain same. if json.loads(response.text).get("status") == "name-exists": - return + # Delete any previous project-admin dashboard if it already exist. + if name == 'admin': + self.delete_admin_dashboard() + response = self.send_request_for_creating_dashboard(dashboard_json_data) + else: + return # Get team id if project_name is not None: @@ -101,11 +105,21 @@ class GrafanaBackend: except Exception: log.exception("Exception processing message: ") + def send_request_for_creating_dashboard(self, dashboard_data): + response = requests.request( + "POST", self.url + "/api/dashboards/db/", data=json.dumps(dashboard_data), headers=self.headers) + return response + def delete_dashboard(self, uid): response = requests.request("DELETE", self.url + "/api/dashboards/uid/" + uid, headers=self.headers) log.debug("Dashboard %s deleted from Grafana", uid) return response + def delete_admin_dashboard(self): + requests.request( + "DELETE", self.url + "/api/dashboards/db/osm-project-status-admin", headers=self.headers) + log.debug("Dashboard osm-project-status-admin deleted from Grafana") + def create_grafana_users(self, user): email = "{}@osm.etsi.org".format(user) user_payload = { diff --git a/osm_mon/dashboarder/service.py b/osm_mon/dashboarder/service.py index d791fa9..441f881 100644 --- a/osm_mon/dashboarder/service.py +++ b/osm_mon/dashboarder/service.py @@ -58,9 +58,10 @@ class DashboarderService: ) except Exception: log.error('Cannot retrieve projects from keystone') + else: + projects.extend(self.common_db.get_projects()) # Reads existing project list and creates a dashboard for each - projects.extend(self.common_db.get_projects()) for project in projects: project_id = project['_id'] # Collect Project IDs for periodical dashboard clean-up