Class: Nagios::Check::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/nagios-check/range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range) ⇒ Range

Returns a new instance of Range.



7
8
9
10
11
12
13
14
# File 'lib/nagios-check/range.rb', line 7

def initialize(range)
  @start_value = 0
  @end_value = 0
  @start_infinity = false
  @end_infinity = false
  @alert_on = :inside
  parse_range_string(range.to_s)
end

Instance Attribute Details

#alert_onObject (readonly)

Returns the value of attribute alert_on.



5
6
7
# File 'lib/nagios-check/range.rb', line 5

def alert_on
  @alert_on
end

#end_infinityObject (readonly)

Returns the value of attribute end_infinity.



5
6
7
# File 'lib/nagios-check/range.rb', line 5

def end_infinity
  @end_infinity
end

#end_valueObject (readonly)

Returns the value of attribute end_value.



5
6
7
# File 'lib/nagios-check/range.rb', line 5

def end_value
  @end_value
end

#start_infinityObject (readonly)

Returns the value of attribute start_infinity.



5
6
7
# File 'lib/nagios-check/range.rb', line 5

def start_infinity
  @start_infinity
end

#start_valueObject (readonly)

Returns the value of attribute start_value.



5
6
7
# File 'lib/nagios-check/range.rb', line 5

def start_value
  @start_value
end

Instance Method Details

#check_range(value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/nagios-check/range.rb', line 16

def check_range(value)
  value = value.to_f
  result =
    if !start_infinity && end_infinity
      start_value <= value
    elsif start_infinity && !end_infinity
      value <= end_value
    else
      start_value <= value && value <= end_value
    end
  alert_on == :outside ? result : !result
end