Sha256: a3b0366c6ed93cd634cb47efc83a582f68c0fea16f2db914e2215a0e6d2174df

Contents?: true

Size: 798 Bytes

Versions: 1

Compression:

Stored size: 798 Bytes

Contents

#encoding: utf-8

require 'open-uri'

module Riemann
  module Babbler
    module Plugins
      module Helpers

        # http rest
        def rest_get(url)
          begin
            Timeout::timeout(plugin.timeout) do
              begin
                uri = URI(url)
                if uri.userinfo
                  open("#{uri.scheme}://#{uri.hostname}:#{uri.port}#{uri.request_uri}", 
                    :http_basic_authentication => [uri.user, uri.password]).read
                else
                  open(url).read
                end
              rescue
                raise "Get from url: #{url} failed"
              end
            end
          rescue Timeout::Error
            raise "Get from url: #{url}, timeout error"
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
riemann-babbler-2.8.5 lib/riemann/babbler/plugins/helpers/rest.rb