Sha256: 7fa19a92806de3b00b5386538e34a1351d7d100b30ab97a5aa6017a3cf592803

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

require 'net/ping/external'
require 'outpost/expectations'

module Outpost
  module Scouts
    # Uses system's "ping" command line tool to check if the server is
    # responding in a timely manner.
    #
    # * Responds to response_time expectation
    #   ({Outpost::Expectations::ResponseTime})
    class Ping < Outpost::Scout
      extend Outpost::Expectations::ResponseTime
      attr_reader :response_time
      report_data :response_time

      # Configure the scout with given options.
      # @param [Hash] Options to setup the scout
      # @option options [String] :host The host that will be "pinged".
      # @option options [Object] :pinger An object that can ping hosts.
      #   Defaults to Net::Ping::External.new
      def setup(options)
        @host   = options[:host]
        @pinger = options[:pinger] || Net::Ping::External.new
      end

      # Runs the scout, pinging the host and getting the duration.
      def execute
        if @pinger.ping(@host)
          # Miliseconds
          @response_time = @pinger.duration * 1000
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
outpost-0.2.5 lib/outpost/scouts/ping.rb
outpost-0.2.4 lib/outpost/scouts/ping.rb