]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/grafana.py
import 15.2.9
[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 .. import mgr
7 from ..exceptions import DashboardException
8 from ..grafana import GrafanaRestClient, push_local_dashboards
9 from ..security import Scope
10 from ..settings import Settings
11
12
13 @ApiController('/grafana', Scope.GRAFANA)
14 class Grafana(BaseController):
15 @Endpoint()
16 @ReadPermission
17 def url(self):
18 grafana_url = mgr.get_module_option('GRAFANA_API_URL')
19 grafana_frontend_url = mgr.get_module_option('GRAFANA_FRONTEND_API_URL')
20 if grafana_frontend_url != '' and grafana_url == '':
21 url = ''
22 else:
23 url = (mgr.get_module_option('GRAFANA_FRONTEND_API_URL')
24 or mgr.get_module_option('GRAFANA_API_URL')).rstrip('/')
25 response = {'instance': url}
26 return response
27
28 @Endpoint()
29 @ReadPermission
30 def validation(self, params):
31 grafana = GrafanaRestClient()
32 method = 'GET'
33 url = str(Settings.GRAFANA_API_URL).rstrip('/') + \
34 '/api/dashboards/uid/' + params
35 response = grafana.url_validation(method, url)
36 return response
37
38 @Endpoint(method='POST')
39 @UpdatePermission
40 def dashboards(self):
41 response = dict()
42 try:
43 response['success'] = push_local_dashboards()
44 except Exception as e: # pylint: disable=broad-except
45 raise DashboardException(
46 msg=str(e),
47 component='grafana',
48 http_status_code=500,
49 )
50 return response