Class: MonitorType_Threshold

Inherits:
MonitorType show all
Defined in:
lib/MonitorType/Threshold.rb

Overview

A base class for checking a number against a min and/or max value

Instance Method Summary collapse

Methods inherited from MonitorType

#alert, #process, #run, #sanitise

Constructor Details

#initialize(params) ⇒ MonitorType_Threshold

See super method for generic description



6
7
8
9
10
# File 'lib/MonitorType/Threshold.rb', line 6

def initialize( params )
       @min = params[:min] ||= 0
       @max = params[:max]
	super( params )
end

Instance Method Details

#check(value, context_sentence) ⇒ Object

Provides the means to check a value against thresholds



13
14
15
16
17
18
19
20
21
22
# File 'lib/MonitorType/Threshold.rb', line 13

def check( value, context_sentence )
       value = value.to_i
       if !@min.nil? && value < @min then
           self.alert( "#{context_sentence}\nMinimum threshold exceeded. Minimum: #{@min}, Actual: #{value}" )
       end
       if !@max.nil? && value > @max then
           self.alert( "#{context_sentence}\nMaximum threshold exceeded. Maximum: #{@max}, Actual: #{value}" )
       end
       
end