Class: Bluepill::Nagios::Nsca

Inherits:
Trigger
  • Object
show all
Defined in:
lib/bluepill-nagios.rb

Instance Method Summary collapse

Constructor Details

#initialize(process, options = {}) ⇒ Nsca

Called by bluepill when a “checks :nsca” is declared in pill file

Parameters:

  • process (Bluepill::Process)
  • options (Hash) (defaults to: {})

    available options:

    • nscahost: the host hosting the nsca daemon. mandatory

    • hostname: the host defined in nagios to be hosting the service (default: hostname -f)

    • service: the service declared in nagios (default: the bluepill process name)

    See checks github.com/arya/bluepill for the syntax to pass those options



15
16
17
18
19
20
21
22
23
# File 'lib/bluepill-nagios.rb', line 15

def initialize(process, options={})
  @default_args = {
    :nscahost => options.delete(:nscahost),
    :port => options.delete(:port) || 5667,
    :hostname => options.delete(:host) || `hostname -f`.chomp,
    :service => options.delete(:service) || process.name
  }
  super
end

Instance Method Details

#notify(transition) ⇒ Object

Called by bluepill when process states changes. Notifies the nagios when:

  • the process goes to :unmonitored notifies warning

  • the process goes to :down notifies critical

  • the process goes to :up notifies ok



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bluepill-nagios.rb', line 29

def notify(transition)
  _return_code, _status = case transition.to_name
  when :down
    [2, "Bluepill reported process down at #{Time.now}"]
  when :unmonitored
    [1 , "Bluepill stopped monitoring at #{Time.now}"]
  when :up
    [0 , "Running"]
  else
    [nil, nil]
  end
  if _status and _return_code
    _args = @default_args.merge({:status => _status, :return_code => _return_code})
    send_nsca(_args)
  end
end