Class: Bluepill::Gearman::SendGearman

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of SendGearman.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bluepill-gearman.rb', line 27

def initialize(process, options={})
  @default_args = {
    :gearman_job_server => ["#{options.delete(:gearman_server)}:#{options.delete(:gearman_port) || 4730}"],
    :host => options.delete(:host) || `hostname -f`.chomp,
    :service => options.delete(:service) || process.name,
    :queue => options.delete(:queue) || 'check_results',
    :key => options.delete(:key) || '',
    :encryption => options.delete(:encryption) || false
  }
  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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bluepill-gearman.rb', line 43

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_gearman(_args)
  end
end