Class: Outpost::Scouts::Tcp

Inherits:
Ping show all
Extended by:
Expectations::ResponseTime
Defined in:
lib/outpost/scouts/tcp.rb

Overview

Uses net/ping tcp pinger to check if port is open

Constant Summary

Constants included from Expectations::ResponseTime

Expectations::ResponseTime::RESPONSE_TIME_MAPPING

Instance Attribute Summary collapse

Attributes inherited from Outpost::Scout

#report_data

Instance Method Summary collapse

Methods included from Expectations::ResponseTime

evaluate_response_time, extended

Methods inherited from Outpost::Scout

expect, expectations, #gather_reporting_data, #initialize, report_data, #run

Constructor Details

This class inherits a constructor from Outpost::Scout

Instance Attribute Details

#response_timeObject (readonly)

Returns the value of attribute response_time


12
13
14
# File 'lib/outpost/scouts/tcp.rb', line 12

def response_time
  @response_time
end

Instance Method Details

#executeObject

Runs the scout, pinging the host and getting the duration.


30
31
32
33
34
35
# File 'lib/outpost/scouts/tcp.rb', line 30

def execute
  if @pinger.ping?
    # Miliseconds
    @response_time = @pinger.duration * 1000
  end
end

#setup(options) ⇒ Object

Configure the scout with given options.

Options Hash (options):

  • :host (String)

    The host that will be “pinged”.

  • :pinger (Object)

    An object that can ping hosts. Defaults to Net::Ping::Tcp.new


20
21
22
23
24
25
26
27
# File 'lib/outpost/scouts/tcp.rb', line 20

def setup(options)
  host   = options[:host]
  port   = options[:port]
  timeout= options[:timeout] || 3
  pinger = options[:pinger] || Net::Ping::TCP

  @pinger = pinger.new(host, port, timeout)
end