Sha256: 23eb6a18afc9c2e9533b98d51c1723aa29fd099dfdaf9e4f6d42610cb1742d43

Contents?: true

Size: 873 Bytes

Versions: 9

Compression:

Stored size: 873 Bytes

Contents

require 'panoptimon-collector-socket/tcp'
require 'panoptimon-collector-socket/unix'

module Panoptimon
  module Collector
    class Socket
      attr_accessor :path, :timeout, :match

      def initialize(options={})
        @path    = options[:path]    || defaults[:path]
        @match   = options[:match]   || defaults[:match]
        @timeout = options[:timeout] || defaults[:timeout]
        return options
      end

      # dispatching constructor
      def self.construct(options={})
        (options[:path] =~ %r{^/} ? Unix : TCP).new(options)
      end

      def defaults
        {match:   '.*'}
      end

      def run
        out = begin
          a = Timeout::timeout(timeout.to_i) { get_banner }
          {status: a.match(match) ? true : false}
        rescue Timeout::Error
          {timeout: true}
        end

        out
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
panoptimon-0.4.5 collectors/socket/lib/panoptimon-collector-socket/socket.rb
panoptimon-0.4.4 collectors/socket/lib/panoptimon-collector-socket/socket.rb
panoptimon-0.4.2 collectors/socket/lib/panoptimon-collector-socket/socket.rb
panoptimon-0.4.1 collectors/socket/lib/panoptimon-collector-socket/socket.rb
panoptimon-0.4.0 collectors/socket/lib/panoptimon-collector-socket/socket.rb
panoptimon-0.3.0 collectors/socket/lib/panoptimon-collector-socket/socket.rb
panoptimon-0.2.0 collectors/socket/lib/panoptimon-collector-socket/socket.rb
panoptimon-0.1.0 collectors/socket/lib/panoptimon-collector-socket/socket.rb
panoptimon-0.0.2 collectors/socket/lib/panoptimon-collector-socket/socket.rb