Module: Grafana::Modules::Dashboard
- Included in:
- Dashboards
- Defined in:
- lib/grafana/modules/dashboard.rb
Instance Method Summary collapse
- #create_dashboard(dashboard:, **options) ⇒ Object
- #dashboard(uid:) ⇒ Object
- #dashboard_permissions(dashboard_id:) ⇒ Object
- #dashboard_search(**options) ⇒ Object
- #dashboard_tags ⇒ Object
- #dashboard_version(dashboard_id:, version_id:) ⇒ Object
- #dashboard_versions(dashboard_id:) ⇒ Object
- #delete_dashboard(uid:) ⇒ Object
- #diff_dashboards(base_id:, base_version:, new_version:, new_id: nil, diff_type: 'json') ⇒ Object
- #home_dashboard ⇒ Object
- #overwrite_dashboard(dashboard:, **options) ⇒ Object
- #restore_dashboard_version(dashboard_id:, version_id:) ⇒ Object
- #update_dashboard(uid:, **options) ⇒ Object
- #update_dashboard_permissions(dashboard_id:, permissions:) ⇒ Object
Instance Method Details
#create_dashboard(dashboard:, **options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/grafana/modules/dashboard.rb', line 10 def create_dashboard(dashboard:, **) # TODO: Error if dashboard is not hash specification # TODO: error if dashboard IDs are set (should be an update if so) req_body = { dashboard: dashboard, message: [:message], folderId: [:folder_id], overwrite: false # Creating new dashboard should not overwrite existing dashboards } post('/api/dashboards/db', req_body) end |
#dashboard(uid:) ⇒ Object
68 69 70 |
# File 'lib/grafana/modules/dashboard.rb', line 68 def dashboard(uid:) get("/api/dashboards/uid/#{uid}") end |
#dashboard_permissions(dashboard_id:) ⇒ Object
80 81 82 |
# File 'lib/grafana/modules/dashboard.rb', line 80 def (dashboard_id:) get("/api/dashboards/id/#{dashboard_id}/permissions") end |
#dashboard_search(**options) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/grafana/modules/dashboard.rb', line 51 def dashboard_search(**) = .slice(:query, :tag, :dashboard_ids, :folder_ids, :starred, :limit, :page) [:folderIds] = Array.wrap(.delete(:folder_ids)) if [:folder_ids].present? [:dashboardIds] = Array.wrap(.delete(:dashboard_ids)) if [:dashboard_ids].present? .delete(:starred) unless [:starred].is_a?(Boolean) .delete(:limit) unless [:limit].is_a?(Integer) && [:limit] <= 5000 .delete(:page) unless [:page].is_a?(Integer) .merge({ type: 'dash-db' }) search_url = '/api/search' search_url = "?#{URI.encode_www_form()}" get(search_url) end |
#dashboard_tags ⇒ Object
76 77 78 |
# File 'lib/grafana/modules/dashboard.rb', line 76 def get('/api/dashboards/tags') end |
#dashboard_version(dashboard_id:, version_id:) ⇒ Object
93 94 95 |
# File 'lib/grafana/modules/dashboard.rb', line 93 def dashboard_version(dashboard_id:, version_id:) get("/api/dashboards/id/#{dashboard_id}/versions/#{version_id}") end |
#dashboard_versions(dashboard_id:) ⇒ Object
89 90 91 |
# File 'lib/grafana/modules/dashboard.rb', line 89 def dashboard_versions(dashboard_id:) get("/api/dashboards/id/#{dashboard_id}/versions") end |
#delete_dashboard(uid:) ⇒ Object
72 73 74 |
# File 'lib/grafana/modules/dashboard.rb', line 72 def delete_dashboard(uid:) delete("/api/dashboards/uid/#{uid}") end |
#diff_dashboards(base_id:, base_version:, new_version:, new_id: nil, diff_type: 'json') ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/grafana/modules/dashboard.rb', line 101 def diff_dashboards(base_id:, base_version:, new_version:, new_id: nil, diff_type: 'json') req_body = { base: { dashboardId: base_id, version: base_version }, new: { dashboardId: new_id || base_id, version: new_version }, diffType: diff_type } post('/api/dashboards/calculate-diff', req_body) end |
#home_dashboard ⇒ Object
6 7 8 |
# File 'lib/grafana/modules/dashboard.rb', line 6 def home_dashboard get('/api/dashboards/home') end |
#overwrite_dashboard(dashboard:, **options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/grafana/modules/dashboard.rb', line 40 def overwrite_dashboard(dashboard:, **) req_body = { dashboard: dashboard, message: [:message], folderId: [:folder_id], overwrite: true # Overwriting dashboard (if exists) } post('/api/dashboards/db', req_body) end |
#restore_dashboard_version(dashboard_id:, version_id:) ⇒ Object
97 98 99 |
# File 'lib/grafana/modules/dashboard.rb', line 97 def restore_dashboard_version(dashboard_id:, version_id:) post("/api/dashboards/id/#{dashboard_id}/restore", { version: version_id }) end |
#update_dashboard(uid:, **options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/grafana/modules/dashboard.rb', line 24 def update_dashboard(uid:, **) = .delete(:message) folder_id = .delete(:folder_id) old_dashboard = dashboard(uid: uid) req_body = { dashboard: old_dashboard.merge(), message: , folderId: folder_id, overwrite: true # Updating dashboard should overwrite existing dashboards } post('/api/dashboards/db', req_body) end |
#update_dashboard_permissions(dashboard_id:, permissions:) ⇒ Object
84 85 86 87 |
# File 'lib/grafana/modules/dashboard.rb', line 84 def (dashboard_id:, permissions:) # TODO: error if permissions is not array of hashes post("/api/dashboards/id/#{dashboard_id}/permissions", { items: }) end |