class Poller::HTTP::HttpProbe
Public Class Methods
new(url_s, matcher, proxy_hostname = nil, proxy_port = nil, proxy_user = nil, proxy_pwd = nil)
click to toggle source
# File lib/poller/http/http_probe.rb, line 29 def initialize(url_s, matcher, proxy_hostname = nil, proxy_port = nil, proxy_user = nil, proxy_pwd = nil) @uri = URI.parse(url_s) @matcher = matcher @proxy = Net::HTTP::Proxy(proxy_hostname, proxy_port, proxy_user, proxy_pwd).new(@uri.host, @uri.port) end
Public Instance Methods
sample()
click to toggle source
# File lib/poller/http/http_probe.rb, line 35 def sample begin # support SSL, not veryfing the SSL certificates (out of scope from my perspective) if @uri.scheme == 'https' @proxy.use_ssl = true @proxy.verify_mode = OpenSSL::SSL::VERIFY_NONE end request = Net::HTTP::Get.new(@uri.request_uri) # support basic auth if userinfo appears in url if @uri.userinfo request.basic_auth(@uri.user, @uri.password) end @http_response = @proxy.request(request) return @http_response if @http_response.class == Net::HTTPOK rescue Exception => e raise RuntimeError, "#sample caught an Exception of class #{e.class} with message: #{e.message}" end raise RuntimeError, "HTTP request failed, the error class is: #{@http_response.class}" end
satisfied?()
click to toggle source
# File lib/poller/http/http_probe.rb, line 55 def satisfied? return false if @http_response.nil? @matcher.matches?(@http_response.body) end