]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | # -*- coding: utf-8 -*- |
2 | from __future__ import absolute_import | |
3 | ||
81eedcae TL |
4 | from . import (ApiController, BaseController, Endpoint, ReadPermission, |
5 | UpdatePermission) | |
6 | from ..exceptions import DashboardException | |
7 | from ..grafana import GrafanaRestClient, push_local_dashboards | |
11fdf7f2 TL |
8 | from ..security import Scope |
9 | from ..settings import Settings | |
10 | ||
11 | ||
11fdf7f2 TL |
12 | @ApiController('/grafana', Scope.GRAFANA) |
13 | class Grafana(BaseController): | |
14 | ||
15 | @Endpoint() | |
16 | @ReadPermission | |
17 | def url(self): | |
18 | response = {'instance': Settings.GRAFANA_API_URL} | |
19 | return response | |
20 | ||
21 | @Endpoint() | |
22 | @ReadPermission | |
23 | def validation(self, params): | |
24 | grafana = GrafanaRestClient() | |
25 | method = 'GET' | |
26 | url = Settings.GRAFANA_API_URL.rstrip('/') + \ | |
27 | '/api/dashboards/uid/' + params | |
28 | response = grafana.url_validation(method, url) | |
29 | return response | |
81eedcae TL |
30 | |
31 | @Endpoint(method='POST') | |
32 | @UpdatePermission | |
33 | def dashboards(self): | |
34 | response = dict() | |
35 | try: | |
36 | response['success'] = push_local_dashboards() | |
37 | except Exception as e: # pylint: disable=broad-except | |
38 | raise DashboardException( | |
39 | msg=e.message, | |
40 | component='grafana', | |
41 | http_status_code=500, | |
42 | ) | |
43 | return response |