Class: Wary::Check::HttpStatus

Inherits:
Object
  • Object
show all
Includes:
Wary::Check
Defined in:
lib/wary/check/http_status.rb

Instance Attribute Summary

Attributes included from Wary::Check

#name

Instance Method Summary collapse

Methods included from Wary::Check

#configure

Constructor Details

#initialize(options) ⇒ HttpStatus

Returns a new instance of HttpStatus.



9
10
11
12
13
# File 'lib/wary/check/http_status.rb', line 9

def initialize(options)
  @url = options.fetch(:url)
  @http_client = options.fetch(:http_client) { HTTPClient.new }
  configure(options)
end

Instance Method Details

#statusObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wary/check/http_status.rb', line 15

def status
  begin
    response = @http_client.get_response(@url)
  rescue => e
    return failure("#{@url} down (#{e.message})")
  end

  if response.code == "200"
    ok(message(response))
  else
    alert("#{@url} (#{response.code} #{response.message})")
  end
end