X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fdashboarder%2Fservice.py;h=32128c2a4733020a6cb89153c21a61f2a2b16075;hb=cd89bb46119f6819320827a578a4a7f8b61ae7ff;hp=10508e4ad397e30472a7ecc26ba2309d3b7cea85;hpb=cf0c2e1acdb8b6b188e76716625e09304d6984de;p=osm%2FMON.git diff --git a/osm_mon/dashboarder/service.py b/osm_mon/dashboarder/service.py index 10508e4..32128c2 100644 --- a/osm_mon/dashboarder/service.py +++ b/osm_mon/dashboarder/service.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2018 Whitestack, LLC +# Copyright 2021 Whitestack, LLC # ************************************************************* # This file is part of OSM Monitoring module @@ -24,6 +24,7 @@ import logging from osm_mon.core.common_db import CommonDbClient from osm_mon.core.config import Config +from osm_mon.core.keystone import KeystoneConnection from osm_mon.dashboarder.backends.grafana import GrafanaBackend from osm_mon import __path__ as mon_path from osm_mon.dashboarder.utils import find_in_list @@ -37,14 +38,29 @@ class DashboarderService: self.common_db = CommonDbClient(self.conf) self.grafana = GrafanaBackend(self.conf) + if bool(self.conf.get('keystone', 'enabled')): + self.keystone = KeystoneConnection(self.conf) + else: + self.keystone = None + def create_dashboards(self): # TODO lavado: migrate these methods to mongo change streams # Lists all dashboards and OSM resources for later comparisons dashboard_uids = self.grafana.get_all_dashboard_uids() osm_resource_uids = [] + projects = [] + + # Check if keystone is the auth/projects backend and get projects from there + if self.keystone: + try: + projects.extend( + map(lambda project: {'_id': project.id, 'name': project.name}, self.keystone.getProjects()) + ) + except Exception: + log.error('Cannot retrieve projects from keystone') # Reads existing project list and creates a dashboard for each - projects = self.common_db.get_projects() + projects.extend(self.common_db.get_projects()) for project in projects: project_id = project['_id'] # Collect Project IDs for periodical dashboard clean-up @@ -52,6 +68,7 @@ class DashboarderService: dashboard_path = '{}/dashboarder/templates/project_scoped.json'.format(mon_path[0]) if project_id not in dashboard_uids: project_name = project['name'] + self.grafana.create_grafana_folders(project_name) self.grafana.create_dashboard(project_id, project_name, dashboard_path) log.debug('Created dashboard for Project: %s', project_id)