Sha256: cfbec584e8bf09fb258f3ceb6c68de880c4e58d8639cbccccacf629f88b82c54

Contents?: true

Size: 666 Bytes

Versions: 2

Compression:

Stored size: 666 Bytes

Contents

#encoding: utf-8

require 'uri'
require 'net/http'

module Riemann
  module Babbler
    module Plugins
      module Helpers

        # http rest
        def rest_get(url)
          begin
            Timeout::timeout(plugin.timeout) do
              begin
                res = ::Net::HTTP.get_response(URI(url))
                raise ::Net::HTTPError unless res.kind_of?(::Net::HTTPSuccess)
                res.body
              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

2 entries across 2 versions & 1 rubygems

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