Module: ICMP4EM::HostCommon

Included in:
ICMPv4
Defined in:
lib/icmp4em/common.rb

Instance Method Summary collapse

Instance Method Details

#failures_required=(failures) ⇒ Object

Set the number of consecutive ‘failure’ pings required to switch host state to ‘down’ and trigger failure callback, assuming the host is up.



63
64
65
# File 'lib/icmp4em/common.rb', line 63

def failures_required=(failures)
  @failures_required = failures
end

#on_expire(proc = nil, &block) ⇒ Object

Set ‘expiry’ callback. This will be called and yielded the host, sequence number, and Exception every time a ping fails. This is not just for timeouts! This can be triggered by failure of the ping for any reason.



57
58
59
60
# File 'lib/icmp4em/common.rb', line 57

def on_expire(proc = nil, &block)
  @expiry = proc || block unless proc.nil? and block.nil?
  @expiry
end

#on_failure(proc = nil, &block) ⇒ Object

Set failure callback. The provided Proc or block will be called and yielded the host and sequence number, whenever the failure count exceeds the defined threshold.



38
39
40
41
# File 'lib/icmp4em/common.rb', line 38

def on_failure(proc = nil, &block)
  @failure = proc || block unless proc.nil? and block.nil?
  @failure
end

#on_recovery(proc = nil, &block) ⇒ Object

Set recovery callback. The provided Proc or block will be called and yielded the host and sequence number, whenever the recovery count exceeds the defined threshold.



44
45
46
47
# File 'lib/icmp4em/common.rb', line 44

def on_recovery(proc = nil, &block)
  @recovery = proc || block unless proc.nil? and block.nil?
  @recovery
end

#on_success(proc = nil, &block) ⇒ Object

Set success callback. This will be called and yielded the host, sequence number, and latency every time a ping returns successfully.



50
51
52
53
# File 'lib/icmp4em/common.rb', line 50

def on_success(proc = nil, &block)
  @success = proc || block unless proc.nil? and block.nil?
  @success
end

#recoveries_required=(recoveries) ⇒ Object

Set the number of consecutive ‘recovery’ pings required to switch host state to ‘up’ and trigger recovery callback, assuming the host is down.



68
69
70
# File 'lib/icmp4em/common.rb', line 68

def recoveries_required=(recoveries)
  @recoveries_required = recoveries
end