class Grafana::Dashboard
Representation of one specific dashboard in a {Grafana} instance.
Attributes
grafana[R]
@return [Grafana] parent {Grafana} object
panels[R]
variables[R]
Public Class Methods
new(model, grafana)
click to toggle source
@param model [Hash] converted JSON Hash of the grafana dashboard @param grafana [Grafana] parent {Grafana} object
# File lib/grafana/dashboard.rb, line 12 def initialize(model, grafana) @grafana = grafana @model = model init_panels init_variables end
Public Instance Methods
from_time()
click to toggle source
@return [String] from
time configured in the dashboard.
# File lib/grafana/dashboard.rb, line 21 def from_time return @model['time']['from'] if @model['time'] nil end
id()
click to toggle source
@return [String] dashboard UID
# File lib/grafana/dashboard.rb, line 34 def id @model['uid'] end
panel(id)
click to toggle source
@return [Panel] panel for the specified ID
# File lib/grafana/dashboard.rb, line 39 def panel(id) panels = @panels.select { |item| item.field('id') == id.to_i } raise PanelDoesNotExistError.new(id, self) if panels.empty? panels.first end
to_time()
click to toggle source
@return [String] to
time configured in the dashboard.
# File lib/grafana/dashboard.rb, line 28 def to_time @model['time']['to'] if @model['time'] nil end
Private Instance Methods
init_panels()
click to toggle source
read panels
# File lib/grafana/dashboard.rb, line 60 def init_panels @panels = [] return unless @model.key?('panels') @model['panels'].each do |panel| if panel.key?('panels') panel['panels'].each do |subpanel| @panels << Panel.new(subpanel, self) end else @panels << Panel.new(panel, self) end end end
init_variables()
click to toggle source
store variables in array as objects of type Variable
# File lib/grafana/dashboard.rb, line 49 def init_variables @variables = [] return unless @model.key?('templating') list = @model['templating']['list'] return unless list.is_a? Array list.each { |item| @variables << Variable.new(item) } end