Class: Metrics::Dashboard::DatasourceNameParser

Inherits:
Object
  • Object
show all
Defined in:
app/services/metrics/dashboard/grafana_metric_embed_service.rb

Overview

Identifies the name of the datasource for a dashboard based on the panelId query parameter found in the url.

If no panel is specified, defaults to the first valid panel.

Instance Method Summary collapse

Constructor Details

#initialize(grafana_url, grafana_dashboard) ⇒ DatasourceNameParser

Returns a new instance of DatasourceNameParser.


147
148
149
# File 'app/services/metrics/dashboard/grafana_metric_embed_service.rb', line 147

def initialize(grafana_url, grafana_dashboard)
  @grafana_url, @grafana_dashboard = grafana_url, grafana_dashboard
end

Instance Method Details

#parseObject


151
152
153
154
155
# File 'app/services/metrics/dashboard/grafana_metric_embed_service.rb', line 151

def parse
  @grafana_dashboard[:dashboard][:panels]
    .find { |panel| panel_id ? matching_panel?(panel) : valid_panel?(panel) }
    .try(:[], :datasource)
end