Class: MonitorType_Threshold
- Inherits:
-
MonitorType
- Object
- MonitorType
- MonitorType_Threshold
- Defined in:
- lib/MonitorType/Threshold.rb
Overview
A base class for checking a number against a min and/or max value
Direct Known Subclasses
MonitorType_Beanstalk, MonitorType_Dir, MonitorType_Drive, MonitorType_FluidDb, MonitorType_Process
Instance Method Summary collapse
-
#check(value) ⇒ Object
Provides the means to check a value against thresholds.
-
#getValue ⇒ Object
Get the context dependent value which is to be checked.
-
#initialize(params) ⇒ MonitorType_Threshold
constructor
See super method for generic description.
- #process ⇒ Object
Methods inherited from MonitorType
#alert, #extractParams, #run, #setup, #teardown
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) ⇒ Object
Provides the means to check a value against thresholds
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/MonitorType/Threshold.rb', line 30 def check( value ) context_sentence = "" if !@context_sentence.nil? then context_sentence = "#{@context_sentence}\n" end value = value.to_i if !@min.nil? && value < @min then self.alert( "#{context_sentence}Minimum threshold exceeded. Minimum: #{@min}, Actual: #{value}" ) end if !@max.nil? && value > @max then self.alert( "#{context_sentence}Maximum threshold exceeded. Maximum: #{@max}, Actual: #{value}" ) end end |
#getValue ⇒ Object
Get the context dependent value which is to be checked
13 14 15 |
# File 'lib/MonitorType/Threshold.rb', line 13 def getValue raise "Method needs to be overridden" end |
#process ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/MonitorType/Threshold.rb', line 17 def process if @block.nil? then value = self.getValue else value = @block.call( @params ) string = "value: #{value}\n" puts string end self.check( value ) end |