Class: Heartcheck::Services::Firewall

Inherits:
Object
  • Object
show all
Defined in:
lib/heartcheck/services/firewall.rb

Overview

A service to check with a simple telnet if the route to a host is working.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ void

Sets up the options to firewall.

Examples:

Firewall.new(host: 'domain.com', port: 80)
Firewall.new(host: 'domain.com', port: 80, timeout: 5)
Firewall.new(uri: 'https://domain.com')
Firewall.new(uri: 'https://domain.com', proxy: 'http://proxy.domain.com')

Parameters:

  • params (Hash)

    a hash with the configurations.

Options Hash (params):

  • :host (String)

    The domain/Ip

  • :port (Integer)

    Number of port to check

  • :proxy (String)

    The uri of your proxy if is required

  • :timeout (integer) — default: defaults to: 2

    Number in seconds

  • :uri (string)

    You can pass a URI instead a host and port


26
27
28
29
30
31
32
# File 'lib/heartcheck/services/firewall.rb', line 26

def initialize(params)
  @host    = params[:host]
  @port    = params[:port]
  @proxy   = params[:proxy]
  @timeout = params[:timeout] || 2
  @uri     = URI(params[:url].to_s)
end

Instance Attribute Details

#proxyObject (readonly)

Returns the value of attribute proxy


8
9
10
# File 'lib/heartcheck/services/firewall.rb', line 8

def proxy
  @proxy
end

#uriObject (readonly)

Returns the value of attribute uri


8
9
10
# File 'lib/heartcheck/services/firewall.rb', line 8

def uri
  @uri
end

Instance Method Details

#hostString

to get the host or stract from @uri

Returns:

  • (String)

    the host that is configured


50
51
52
# File 'lib/heartcheck/services/firewall.rb', line 50

def host
  @host || uri.host
end

#paramsHash

format params to use in Telnet

Returns:

  • (Hash)

    with the config

    • Host

    • Port

    • Timeout

    • Proxy - if is seted return a Net::Telnet object


41
42
43
44
45
# File 'lib/heartcheck/services/firewall.rb', line 41

def params
  params = { 'Host' => host, 'Port' => port, 'Timeout' => @timeout }
  params['Proxy'] = proxy_uri if proxy
  params
end

#portIntegre

to get the port or stract from @uri

Returns:

  • (Integre)

    the port that is configured


57
58
59
# File 'lib/heartcheck/services/firewall.rb', line 57

def port
  @port || uri.port
end