Class: Grafana::Panel
- Inherits:
-
Object
- Object
- Grafana::Panel
- Defined in:
- lib/grafana/panel.rb
Overview
Representation of one specific panel in a Dashboard instance.
Instance Attribute Summary collapse
-
#dashboard ⇒ Dashboard
readonly
Parent Dashboard object.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#datasource ⇒ Datasource
Datasource object specified for the current panel.
-
#field(field) ⇒ String
Content of the requested field or ” if not found.
-
#id ⇒ String
Panel ID.
-
#initialize(model, dashboard) ⇒ Panel
constructor
A new instance of Panel.
-
#query(query_letter) ⇒ String
Query string for the requested query letter.
-
#render_url ⇒ String
Relative rendering URL for the panel, to create an image out of it.
-
#resolve_variable_datasource(variables) ⇒ Object
This method should always be called before the
datasource
method of a panel is invoked, to ensure that the variable names in the datasource field are resolved.
Constructor Details
#initialize(model, dashboard) ⇒ Panel
Returns a new instance of Panel.
12 13 14 15 16 17 18 19 20 |
# File 'lib/grafana/panel.rb', line 12 def initialize(model, dashboard) @model = model @dashboard = dashboard @datasource_uid_or_name = @model['datasource'] if @model['datasource'].is_a?(Hash) @datasource_uid_or_name = @model['datasource']['uid'] end end |
Instance Attribute Details
#dashboard ⇒ Dashboard (readonly)
Returns parent Dashboard object.
7 8 9 |
# File 'lib/grafana/panel.rb', line 7 def dashboard @dashboard end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/grafana/panel.rb', line 8 def model @model end |
Instance Method Details
#datasource ⇒ Datasource
Returns datasource object specified for the current panel.
44 45 46 47 48 49 50 |
# File 'lib/grafana/panel.rb', line 44 def datasource if datasource_kind_is_uid? dashboard.grafana.datasource_by_uid(@datasource_uid_or_name) else dashboard.grafana.datasource_by_name(@datasource_uid_or_name) end end |
#field(field) ⇒ String
Returns content of the requested field or ” if not found.
23 24 25 26 27 |
# File 'lib/grafana/panel.rb', line 23 def field(field) return @model[field] if @model.key?(field) nil end |
#id ⇒ String
Returns panel ID.
30 31 32 |
# File 'lib/grafana/panel.rb', line 30 def id @model['id'] end |
#query(query_letter) ⇒ String
Returns query string for the requested query letter.
53 54 55 56 57 58 |
# File 'lib/grafana/panel.rb', line 53 def query(query_letter) query_item = @model['targets'].select { |item| item['refId'].to_s == query_letter.to_s }.first raise QueryLetterDoesNotExistError.new(query_letter, self) unless query_item datasource.raw_query_from_panel_model(query_item) end |
#render_url ⇒ String
Returns relative rendering URL for the panel, to create an image out of it.
61 62 63 |
# File 'lib/grafana/panel.rb', line 61 def render_url "/render/d-solo/#{@dashboard.id}?panelId=#{@model['id']}" end |
#resolve_variable_datasource(variables) ⇒ Object
This method should always be called before the datasource
method of a panel is invoked, to ensure that the variable names in the datasource field are resolved.
39 40 41 |
# File 'lib/grafana/panel.rb', line 39 def resolve_variable_datasource(variables) @datasource_uid_or_name = AbstractDatasource.new(nil).replace_variables(@datasource_uid_or_name, variables, 'raw') if @datasource_uid_or_name.is_a?(String) end |