Class: God::Conditions::Ping

Inherits:
PollCondition show all
Defined in:
lib/god/conditions/ping.rb

Instance Attribute Summary collapse

Attributes inherited from PollCondition

#interval

Attributes inherited from God::Condition

#info, #notify, #phase, #transition

Attributes inherited from Behavior

#watch

Instance Method Summary collapse

Methods inherited from PollCondition

#after, #before

Methods inherited from God::Condition

#friendly_name, generate, valid?

Methods inherited from Behavior

#after_restart, #after_start, #after_stop, #before_restart, #before_start, #before_stop, #friendly_name, generate

Methods included from God::Configurable

#base_name, complain, #complain, #friendly_name, #prepare, #reset

Constructor Details

#initializePing

Returns a new instance of Ping.



7
8
9
10
11
12
# File 'lib/god/conditions/ping.rb', line 7

def initialize
  super
  self.timeout = 2 # s
  self.host = nil
  self.trigger_on=true
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/god/conditions/ping.rb', line 5

def host
  @host
end

#timeoutObject

Returns the value of attribute timeout.



5
6
7
# File 'lib/god/conditions/ping.rb', line 5

def timeout
  @timeout
end

#trigger_onObject

Returns the value of attribute trigger_on.



5
6
7
# File 'lib/god/conditions/ping.rb', line 5

def trigger_on
  @trigger_on
end

Instance Method Details

#testObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/god/conditions/ping.rb', line 21

def test
  cmd = "ping -W #{self.timeout} -c 5 #{self.host}"
  ping_result = `#{cmd}`
  if ping_result=~/time=/
    self.info = "Server reachable via ping!"
    return self.trigger_on
  end
  self.info = "Server unreachable via ping!!!"
  return !self.trigger_on
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/god/conditions/ping.rb', line 14

def valid?
  valid = true
  valid &= complain("Attribute 'host' must be specified", self) if self.host.nil?
  valid &= complain("Attribute 'timeout' must be specified", self) if self.timeout.nil?
  valid
end