class Nagios::Check::Threshold

Public Class Methods

new(thresholds = {}) click to toggle source
# File lib/nagios-check/threshold.rb, line 5
def initialize(thresholds = {})
  set(:warn, thresholds[:warn])
  set(:crit, thresholds[:crit])
end

Public Instance Methods

crit(value = nil) click to toggle source
# File lib/nagios-check/threshold.rb, line 15
def crit(value = nil)
  set(:crit, value) if value
  @crit
end
get_status(value) click to toggle source
# File lib/nagios-check/threshold.rb, line 20
def get_status(value)
  return Nagios::CRITICAL if self.crit && self.crit.check_range(value)
  return Nagios::WARNING  if self.warn && self.warn.check_range(value)
  return Nagios::OK
end
warn(value = nil) click to toggle source
# File lib/nagios-check/threshold.rb, line 10
def warn(value = nil)
  set(:warn, value) if value
  @warn
end

Private Instance Methods

set(attr, value) click to toggle source
# File lib/nagios-check/threshold.rb, line 27
def set(attr, value)
  return unless [:warn, :crit].include?(attr)
  return unless value
  begin
    range = Range.new(value)
    instance_variable_set("@#{attr}".to_sym, range)
  rescue => e
    Nagios.logger.warn("Can't setup a threshold value to: #{value.inspect}. #{e}")
  end
end