From 52d883f6a69f2355a165919634e8295e3cd5f530 Mon Sep 17 00:00:00 2001 From: Rob Raymond Date: Tue, 11 Nov 2014 13:08:34 -0700 Subject: [PATCH] Pass in monasca-api endpoint to grafana Change-Id: Ib87d0176054d9a563ddbf8e36b4b6660326812ca --- monitoring/alarms/tables.py | 8 ++++++-- monitoring/api/monitor.py | 13 +++++++++---- monitoring/overview/templates/overview/index.html | 2 +- monitoring/overview/views.py | 11 ++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/monitoring/alarms/tables.py b/monitoring/alarms/tables.py index 7695f4c5..aa172030 100644 --- a/monitoring/alarms/tables.py +++ b/monitoring/alarms/tables.py @@ -142,9 +142,13 @@ class GraphMetric(tables.LinkAction): def get_link_url(self, datum): name = datum['metrics'][0]['name'] threshold = datum['metrics'] + token = self.table.request.user.token.id + endpoint = api.monitor.monasca_endpoint(self.table.request) self.attrs['target'] = '_blank' - return "/static/grafana/index.html#/dashboard/script/detail.js?token=%s&name=%s&threshold=%s" % \ - (self.table.request.user.token.id, name, threshold) + url = '/static/grafana/index.html#/dashboard/script/detail.js' + query = "?token=%s&name=%s&threshold=%s&api=%s" % \ + (token, name, threshold, endpoint) + return url + query def allowed(self, request, datum=None): return datum['metrics'] diff --git a/monitoring/api/monitor.py b/monitoring/api/monitor.py index e4186051..b0e44ff8 100644 --- a/monitoring/api/monitor.py +++ b/monitoring/api/monitor.py @@ -29,14 +29,19 @@ def format_parameters(params): return parameters -def monascaclient(request, password=None): - api_version = "2_0" - insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) - cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) +def monasca_endpoint(request): service_type = getattr(settings, 'MONITORING_SERVICE_TYPE', 'monitoring') endpoint = base.url_for(request, service_type) if endpoint.endswith('/'): endpoint = endpoint[:-1] + return endpoint + + +def monascaclient(request, password=None): + api_version = "2_0" + insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False) + cacert = getattr(settings, 'OPENSTACK_SSL_CACERT', None) + endpoint = monasca_endpoint(request) LOG.debug('monascaclient connection created using token "%s" , url "%s"' % (request.user.token.id, endpoint)) kwargs = { diff --git a/monitoring/overview/templates/overview/index.html b/monitoring/overview/templates/overview/index.html index 135c36c1..7f0edea8 100644 --- a/monitoring/overview/templates/overview/index.html +++ b/monitoring/overview/templates/overview/index.html @@ -9,7 +9,7 @@ {% block main %}
{% trans 'All Alarms' %} - + {% trans 'Dashboard' %} diff --git a/monitoring/overview/views.py b/monitoring/overview/views.py index a7fda81e..6eb90188 100644 --- a/monitoring/overview/views.py +++ b/monitoring/overview/views.py @@ -20,13 +20,21 @@ import logging from django.conf import settings # noqa from django.http import HttpResponse # noqa from django.views.generic import TemplateView # noqa +from django.utils.translation import ugettext_lazy as _ # noqa from monitoring.overview import constants from monitoring.alarms import tables as alarm_tables from monitoring import api LOG = logging.getLogger(__name__) -SERVICES = getattr(settings, 'MONITORING_SERVICES', []) +OVERVIEW = [ + {'name': _('OpenStack Services'), + 'groupBy': 'service'}, + {'name': _('Servers'), + 'groupBy': 'hostname'} +] + +SERVICES = getattr(settings, 'MONITORING_SERVICES', OVERVIEW) def get_icon(status): @@ -116,6 +124,7 @@ class IndexView(TemplateView): def get_context_data(self, **kwargs): context = super(IndexView, self).get_context_data(**kwargs) context["token"] = self.request.user.token.id + context["api"] = api.monitor.monasca_endpoint(self.request) return context