Method: IsItWorking::PingCheck#initialize

Defined in:
lib/is_it_working/checks/ping_check.rb

#initialize(options = {}) ⇒ PingCheck

Check if a host is reachable and accepting connections on a specified port.

The host and port to ping are specified with the :host and :port options. The port can be either a port number or port name for a well known port (i.e. “smtp” and 25 are equivalent). The default timeout to wait for a response is 2 seconds. This can be changed with the :timeout option.

By default, the host name will be included in the output. If this could pose a security risk by making the existence of the host known to the world, you can supply the :alias option which will be used for output purposes. In general, you should supply this option unless the host is on a private network behind a firewall.

Example

IsItWorking::Handler.new do |h|
  h.check :ping, :host => "example.com", :port => "ftp", :timeout => 4
end

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
# File 'lib/is_it_working/checks/ping_check.rb', line 23

def initialize(options={})
  @host = options[:host]
  raise ArgumentError.new(":host not specified") unless @host
  @port = options[:port]
  raise ArgumentError.new(":port not specified") unless @port
  @timeout = options[:timeout] || 2
  @alias = options[:alias] || @host
end