Class: XymonClient::ServiceItemGauge

Inherits:
ServiceItem show all
Defined in:
lib/xymonclient/serviceitem.rb

Instance Attribute Summary

Attributes inherited from ServiceItem

#attributes, #description, #enabled, #label, #lifetime, #time, #value

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ServiceItemGauge

Returns a new instance of ServiceItemGauge.



72
73
74
75
# File 'lib/xymonclient/serviceitem.rb', line 72

def initialize(config)
  super(config)
  update_config(config)
end

Instance Method Details

#contextObject



102
103
104
105
106
# File 'lib/xymonclient/serviceitem.rb', line 102

def context
  {
    'nan_status' => @nan_status
  }.merge(super)
end

#statusObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/xymonclient/serviceitem.rb', line 77

def status
  @status = \
    if !@enabled
      'clear'
    elsif Time.now - @time > \
          XymonClient.timestring_to_time(@lifetime)
      'purple'
    elsif value.instance_of?(Float) && value.nan?
      @threshold.fetch('nan_status', 'red')
    elsif @threshold.key?('critical') && \
          _threshold_reached?('critical')
      'red'
    elsif @threshold.key?('warning') && \
          _threshold_reached?('warning')
      'yellow'
    else
      'green'
    end
end

#update_config(config) ⇒ Object



97
98
99
100
# File 'lib/xymonclient/serviceitem.rb', line 97

def update_config(config)
  super(config)
  @nan_status = config.fetch('nan_status', 'green')
end