Class: IsItWorking::UrlCheck
- Inherits:
-
Object
- Object
- IsItWorking::UrlCheck
- Defined in:
- lib/is_it_working/checks/url_check.rb
Overview
Check if getting a URL returns a successful response. Only responses in the range 2xx or 304 are considered successful. Redirects will not be followed.
Available options are:
-
:get
- The URL to get. -
:headers
- Hash of headers to send with the request -
:proxy
- Hash of proxy server information. The hash must contain a:host
key and may contain:port
,:username
, and:password
-
:username
- Username to use for Basic Authentication -
:password
- Password to use for Basic Authentication -
:open_timeout
- Time in seconds to wait for opening the connection (defaults to 5 seconds) -
:read_timeout
- Time in seconds to wait for data from the connection (defaults to 10 seconds) -
:alias
- Alias used for reporting in case making the URL known to the world could provide a security risk.
Example
IsItWorking::Handler.new do |h|
h.check :url, :get => "http://services.example.com/api", :headers => {"Accept" => "text/xml"}
end
Instance Method Summary collapse
- #call(status) ⇒ Object
-
#initialize(options = {}) ⇒ UrlCheck
constructor
A new instance of UrlCheck.
Constructor Details
#initialize(options = {}) ⇒ UrlCheck
Returns a new instance of UrlCheck.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/is_it_working/checks/url_check.rb', line 25 def initialize(={}) raise ArgumentError.new(":get must provide the URL to check") unless [:get] @uri = URI.parse([:get]) @headers = [:headers] || {} @proxy = [:proxy] @username = [:username] @password = [:password] @open_timeout = [:open_timeout] || 5 @read_timeout = [:read_timeout] || 10 @alias = [:alias] || [:get] end |
Instance Method Details
#call(status) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/is_it_working/checks/url_check.rb', line 37 def call(status) t = Time.now response = perform_http_request if response.is_a?(Net::HTTPSuccess) status.ok("GET #{@alias} responded with response '#{response.code} #{response.}'") else status.fail("GET #{@alias} failed with response '#{response.code} #{response.}'") end rescue Timeout::Error status.fail("GET #{@alias} timed out after #{Time.now - t} seconds") end |