X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fdashboarder%2Fservice.py;h=32128c2a4733020a6cb89153c21a61f2a2b16075;hb=2fe71f21fe75ee283d39e66391d7d3a094713569;hp=3f83550e06e58e13b19e704d2a0262d6960da645;hpb=9a773323e8cec18fb0f2fa204b0cea4e2370c5dd;p=osm%2FMON.git diff --git a/osm_mon/dashboarder/service.py b/osm_mon/dashboarder/service.py index 3f83550..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