Module: TCPSimple

Included in:
Inari::Commands
Defined in:
lib/inari/commands/tcp_simple.rb

Overview

The simplest commands in the toolset: These check a por is available

Instance Method Summary collapse

Instance Method Details

#down?Boolean

Returns:

  • (Boolean)


23
# File 'lib/inari/commands/tcp_simple.rb', line 23

def down? ; !up? ; end

#up?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/inari/commands/tcp_simple.rb', line 3

def up?
  state = false
  name = @host + ' TCP check'
  
  begin
    Timeout::timeout(@timeout) do
      t = TCPSocket.new(@host, @port)
      state = true
      add_response(name, Response.new('Up'))
    end
  rescue
    Inari::logger.error "TCP error: #{$!} for host: #{@host}, port: #{@port}"
    add_response(name, Response.new($!), true)
  ensure
    t.close if defined? t
  end
  
  return state
end