class Apolo::Notifiers::Nagios

Public Class Methods

new(options = {}) click to toggle source
# File lib/apolo/notifiers/nagios.rb, line 10
def initialize(options = {})
  @file     = options[:file]
  @host     = options[:host]
  @service  = options[:service]
  @warning  = options[:warning]
  @critical = options[:critical]

  unless @file && @host && @service
    raise ArgumentError, 'You need to set :file, :host and :service to use nagios notify.'
  end
end

Public Instance Methods

critical?(value) click to toggle source
# File lib/apolo/notifiers/nagios.rb, line 22
def critical?(value)
  unless @critical
    return false
  end
  if value >= @critical
    return true
  else
    return false
  end
end
notify(monitor, message, value) click to toggle source
# File lib/apolo/notifiers/nagios.rb, line 52
def notify(monitor, message, value)
  status = NAGIOS_UNKNOW
  status = NAGIOS_OK if ok?(value)
  status = NAGIOS_WARNING if warning?(value)
  status = NAGIOS_CRITICAL if critical?(value)

  output = "#{DateTime.now.strftime('%s')}  PROCESS_HOST_CHECK_RESULT;"
  output += "#{@host};#{@service};#{status};#{message}"
  open(@file, 'a') { |f| f.puts output }
end
ok?(value) click to toggle source
# File lib/apolo/notifiers/nagios.rb, line 44
def ok?(value)
  if @critical && @warning
    return true
  else
    return false
  end
end
warning?(value) click to toggle source
# File lib/apolo/notifiers/nagios.rb, line 33
def warning?(value)
  unless @warning
    return false
  end
  if value >= @warning
    return true
  else
    return false
  end
end