Class: God::Conditions::Ping
- Inherits:
-
PollCondition
- Object
- Behavior
- God::Condition
- PollCondition
- God::Conditions::Ping
- Includes:
- ConditionHelper
- Defined in:
- lib/god/conditions/ping.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#times ⇒ Object
Returns the value of attribute times.
-
#trigger_on ⇒ Object
Returns the value of attribute trigger_on.
Attributes inherited from PollCondition
Attributes inherited from God::Condition
#info, #notify, #phase, #transition
Attributes inherited from Behavior
Instance Method Summary collapse
-
#initialize ⇒ Ping
constructor
A new instance of Ping.
- #prepare ⇒ Object
- #test ⇒ Object
- #valid? ⇒ Boolean
Methods included from ConditionHelper
Methods inherited from PollCondition
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, #reset
Constructor Details
#initialize ⇒ Ping
Returns a new instance of Ping.
8 9 10 11 12 13 14 |
# File 'lib/god/conditions/ping.rb', line 8 def initialize super self.timeout = 2 # s self.host = nil self.trigger_on=true self.times = [1, 1] end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/god/conditions/ping.rb', line 6 def host @host end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/god/conditions/ping.rb', line 6 def timeout @timeout end |
#times ⇒ Object
Returns the value of attribute times.
6 7 8 |
# File 'lib/god/conditions/ping.rb', line 6 def times @times end |
#trigger_on ⇒ Object
Returns the value of attribute trigger_on.
6 7 8 |
# File 'lib/god/conditions/ping.rb', line 6 def trigger_on @trigger_on end |
Instance Method Details
#prepare ⇒ Object
16 17 18 19 20 21 |
# File 'lib/god/conditions/ping.rb', line 16 def prepare if self.times.kind_of?(Integer) self.times = [self.times, self.times] end @timeline = Timeline.new(self.times[1]) end |
#test ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/god/conditions/ping.rb', line 30 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 timeline_test(self.trigger_on) end self.info = "Server unreachable via ping!!!" return timeline_test(!self.trigger_on) end |
#valid? ⇒ Boolean
23 24 25 26 27 28 |
# File 'lib/god/conditions/ping.rb', line 23 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 |