module Grafana::Modules::Dashboard

Public Instance Methods

create_dashboard(dashboard:, **options) click to toggle source
# File lib/grafana/modules/dashboard.rb, line 10
def create_dashboard(dashboard:, **options)
  # 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: options[:message],
    folderId: options[:folder_id],
    overwrite: false # Creating new dashboard should not overwrite existing dashboards
  }

  post('/api/dashboards/db', req_body)
end
dashboard(uid:) click to toggle source
# File lib/grafana/modules/dashboard.rb, line 68
def dashboard(uid:)
  get("/api/dashboards/uid/#{uid}")
end
dashboard_permissions(dashboard_id:) click to toggle source
# File lib/grafana/modules/dashboard.rb, line 80
def dashboard_permissions(dashboard_id:)
  get("/api/dashboards/id/#{dashboard_id}/permissions")
end
dashboard_tags() click to toggle source
# File lib/grafana/modules/dashboard.rb, line 76
def dashboard_tags
  get('/api/dashboards/tags')
end
dashboard_version(dashboard_id:, version_id:) click to toggle source
# 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:) click to toggle source
# File lib/grafana/modules/dashboard.rb, line 89
def dashboard_versions(dashboard_id:)
  get("/api/dashboards/id/#{dashboard_id}/versions")
end
delete_dashboard(uid:) click to toggle source
# 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') click to toggle source
# 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() click to toggle source
# File lib/grafana/modules/dashboard.rb, line 6
def home_dashboard
  get('/api/dashboards/home')
end
overwrite_dashboard(dashboard:, **options) click to toggle source
# File lib/grafana/modules/dashboard.rb, line 40
def overwrite_dashboard(dashboard:, **options)
  req_body = {
    dashboard: dashboard,
    message: options[:message],
    folderId: options[:folder_id],
    overwrite: true # Overwriting dashboard (if exists)
  }

  post('/api/dashboards/db', req_body)
end
restore_dashboard_version(dashboard_id:, version_id:) click to toggle source
# 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) click to toggle source
# File lib/grafana/modules/dashboard.rb, line 24
def update_dashboard(uid:, **options)
  message = options.delete(:message)
  folder_id = options.delete(:folder_id)

  old_dashboard = dashboard(uid: uid)

  req_body = {
    dashboard: old_dashboard.merge(options),
    message: 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:) click to toggle source
# File lib/grafana/modules/dashboard.rb, line 84
def update_dashboard_permissions(dashboard_id:, permissions:)
  # TODO: error if permissions is not array of hashes
  post("/api/dashboards/id/#{dashboard_id}/permissions", { items: permissions })
end