Sha256: ab03b8335f4929ab5b833e515080227110f96af6ab0bc449f7b9b220294801dc

Contents?: true

Size: 745 Bytes

Versions: 27

Compression:

Stored size: 745 Bytes

Contents

require 'open3'
require 'timeout'

module Ring
class SQA

  class MTR
    BIN  = 'mtr'
    def self.run host
      MTR.new.run host
    end

    def run host, args=nil
      Timeout::timeout(@timeout) do
        args ||= CFG.mtr.args.split(' ')
        mtr host, args
      end
    rescue Timeout::Error
      "MTR runtime exceeded #{@timeout}s"
    end

    private

    def initialize timeout=CFG.mtr.timeout
      @timeout = timeout
    end

    def mtr host, *args
      out = ''
      args = [*args, host].flatten
      Open3.popen3(BIN, *args) do |stdin, stdout, stderr, wait_thr|
        out << stdout.read until stdout.eof?
      end
      'mtr ' + args.join(' ') + "\n" + out.each_line.to_a[1..-1].join rescue ''
    end
  end

end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
ring-sqa-0.1.0 lib/ring/sqa/mtr.rb
ring-sqa-0.0.23 lib/ring/sqa/mtr.rb
ring-sqa-0.0.22 lib/ring/sqa/mtr.rb
ring-sqa-0.0.21 lib/ring/sqa/mtr.rb
ring-sqa-0.0.20 lib/ring/sqa/mtr.rb
ring-sqa-0.0.19 lib/ring/sqa/mtr.rb
ring-sqa-0.0.18 lib/ring/sqa/mtr.rb