# -*- coding: utf-8 -*-
-# Copyright 2018 Whitestack, LLC
+# Copyright 2021 Whitestack, LLC
# *************************************************************
# This file is part of OSM Monitoring module
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
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
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)