]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/grafana.py
0d4331ff246372348aafc8378db7b019062dd42c
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / grafana.py
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 from . import (ApiController, BaseController, Endpoint, ReadPermission,
5 UpdatePermission)
6 from ..exceptions import DashboardException
7 from ..grafana import GrafanaRestClient, push_local_dashboards
8 from ..security import Scope
9 from ..settings import Settings
10
11
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
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=str(e),
40 component='grafana',
41 http_status_code=500,
42 )
43 return response