Pass in monasca-api endpoint to grafana

Change-Id: Ib87d0176054d9a563ddbf8e36b4b6660326812ca
This commit is contained in:
Rob Raymond 2014-11-11 13:08:34 -07:00
parent 499ace271b
commit 52d883f6a6
4 changed files with 26 additions and 8 deletions

View File

@ -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']

View File

@ -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 = {

View File

@ -9,7 +9,7 @@
{% block main %}
<div style="padding: 3px;">
<a href="{% url 'horizon:monitoring:alarms:alarm' 'all'%}" class="btn btn-default btn-sm showspinner">{% trans 'All Alarms' %}</a>
<a target="dashboard" href="/static/grafana/index.html#/dashboard/file/openstack.json?token={{ token }}" class="btn btn-default btn-sm">
<a target="dashboard" href="/static/grafana/index.html#/dashboard/file/openstack.json?token={{token}}&api={{api}}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-dashboard"></span>
{% trans 'Dashboard' %}
</a>

View File

@ -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