Skip to content

Commit c186c36

Browse files
jgrasslerAdrian Czarnecki
authored andcommitted
Allow raw Grafana links
This commit introduces two configuration changes: * The 'raw' attribute for links in GRAFANA_LINKS which allows the user to point the dashboard URLs specified through GRAFANA_LINKS at arbitrary paths or URLs without further modification. This is False by default, which means the 'fileName' and 'path' attributes are considered to be database or JSON file names to be inserted into a URL. * The SHOW_GRAFANA_HOME setting which controls whether the "Grafana Home" button is displayed or not. By default this is True and the button is shown. Change-Id: I55660f91fd56eb22dd7ad4674af422aeb2ba2ea3
1 parent 201f1ca commit c186c36

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

monitoring/config/local_settings.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,49 @@
5454
# For any Grafana version additional links to specific dashboards can be
5555
# created in two formats.
5656
# Flat:
57-
# GRAFANA_LINKS = [ {'title': _('Dashboard'), 'path': 'openstack'} ]
57+
# GRAFANA_LINKS = [ {'title': _('Dashboard'), 'path': 'openstack', 'raw': False} ]
5858
#
5959
# Per project: '*' will be applied to all projects not explicitly listed.
6060
# GRAFANA_LINKS = [
6161
# {'admin': [
62-
# {'title': _('Dashboard'), 'path': 'openstack'}]},
62+
# {'title': _('Dashboard'), 'path': 'openstack', 'raw': False}]},
6363
# {'*': [
64-
# {'title': _('OpenStack Dashboard'), 'path': 'project'}]}
64+
# {'title': _('OpenStack Dashboard'), 'path': 'project', 'raw': False}]}
6565
# ]
66+
#
67+
# If GRAFANA_URL is specified, the dashboard file name/raw URL must be
68+
# specified through the 'path' attribute as shown above.
69+
#
70+
# Flat:
71+
# GRAFANA_LINKS = [ {'title': _('Dashboard'), 'fileName': 'openstack.json', 'raw': False} ]
72+
#
73+
# GRAFANA_LINKS = [
74+
# {'admin': [
75+
# {'fileName': _('Dashboard'), 'fileName': 'openstack.json', 'raw': False}]},
76+
# {'*': [
77+
# {'title': _('OpenStack Dashboard'), 'fileName': 'project.json': False}]}
78+
# ]
79+
#
80+
# If GRAFANA_URL is unspecified the dashboard file name must be specified
81+
# through the fileName attribute.
82+
#
83+
# Both with and without GRAFANA_URL, the links have an optional 'raw' attribute
84+
# which defaults to False if unspecified. If it is False, the value of 'path'
85+
# (or 'fileName', respectively) is interpreted as a dashboard name and a link
86+
# to the dashboard based on the dashboard's name will be generated. If it is
87+
# True, the value of 'path' or 'fileName' will be treated as a URL to be used
88+
# verbatim.
89+
90+
6691

6792
GRAFANA_URL = getattr(settings, 'GRAFANA_URL', None)
6893

94+
# If GRAFANA_URL is specified, an additional link will be shown that points to
95+
# Grafana's list of dashboards. If you do not wish this, set SHOW_GRAFANA_HOME
96+
# to False (by default this setting is True and the link will thus be shown).
97+
98+
SHOW_GRAFANA_HOME = getattr(settings, 'SHOW_GRAFANA_HOME', True)
99+
69100
ENABLE_KIBANA_BUTTON = getattr(settings, 'ENABLE_KIBANA_BUTTON', False)
70101
KIBANA_POLICY_RULE = getattr(settings, 'KIBANA_POLICY_RULE',
71102
'monitoring:kibana_access')

monitoring/overview/templates/overview/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,29 @@
1616
{% block main %}
1717
<div style="padding: 3px;">
1818
{% if grafana_url %}
19+
{% if show_grafana_home %}
1920
<a target="Grafana Home" href="{{grafana_url}}" class="btn btn-primary">
2021
<span class="fa fa-bar-chart"></span>
2122
Grafana Home
2223
</a>
24+
{% endif %}
2325
{% for dashboard in dashboards %}
26+
{% if dashboard.raw %}
27+
<a target={{ dashboard.title }} href="{{ dashboard.path }}" class="btn btn-default">
28+
{% else %}
2429
<a target={{ dashboard.title }} href="{{grafana_url}}/dashboard/db/{{ dashboard.path }}" class="btn btn-default">
30+
{% endif %}
2531
<span class="fa fa-bar-chart"></span>
2632
{% trans dashboard.title %}
2733
</a>
2834
{% endfor %}
2935
{% else %}
3036
{% for dashboard in dashboards %}
37+
{% if dashboard.raw %}
38+
<a target={{ dashboard.title }} href="{{ dashboard.fileName }}" class="btn btn-default">
39+
{% else %}
3140
<a target={{ dashboard.title }} href="/grafana/index.html#/dashboard/file/{{ dashboard.fileName }}?api={{api}}" class="btn btn-default">
41+
{% endif %}
3242
<span class="fa fa-bar-chart"></span>
3343
{% trans dashboard.title %}
3444
</a>

monitoring/overview/views.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,14 @@ def get_context_data(self, **kwargs):
240240
api_root = self.request.build_absolute_uri(proxy_url_path)
241241
context["api"] = api_root
242242
context["dashboards"] = get_dashboard_links(self.request)
243+
# Ensure all links have a 'raw' attribute
244+
for link in context["dashboards"]:
245+
link['raw'] = link.get('raw', False)
243246
context['can_access_logs'] = policy.check(
244247
((getattr(settings, 'KIBANA_POLICY_SCOPE'), getattr(settings, 'KIBANA_POLICY_RULE')), ), self.request
245248
)
246249
context['enable_kibana_button'] = settings.ENABLE_KIBANA_BUTTON
250+
context['show_grafana_home'] = settings.SHOW_GRAFANA_HOME
247251
return context
248252

249253

@@ -261,7 +265,9 @@ def _convert_dimensions(self, req_kwargs):
261265
dimensions_str = req_kwargs['dimensions'][0]
262266
dimensions_str_array = dimensions_str.split(',')
263267
for dimension in dimensions_str_array:
264-
dimension_name_value = dimension.split(':')
268+
# limit splitting since value may contain a ':' such as in
269+
# the `url` dimension of the service_status check.
270+
dimension_name_value = dimension.split(':', 1)
265271
if len(dimension_name_value) == 2:
266272
name = dimension_name_value[0].encode('utf8')
267273
value = dimension_name_value[1].encode('utf8')

0 commit comments

Comments
 (0)