Class: Apolo::Notifiers::Nagios

Inherits:
Object
  • Object
show all
Defined in:
lib/apolo/notifiers/nagios.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Nagios

Returns a new instance of Nagios.



10
11
12
13
14
15
16
17
18
19
20
# 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

Instance Method Details

#critical?(value) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
# 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) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# 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) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
# File 'lib/apolo/notifiers/nagios.rb', line 44

def ok?(value)
  if @critical && @warning
    return true
  else
    return false
  end
end

#warning?(value) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
# 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