Class: Philae::HttpProbe
- Inherits:
-
Object
- Object
- Philae::HttpProbe
- Defined in:
- lib/philae/http_probe.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(name, uri, username = nil, password = nil) ⇒ HttpProbe
constructor
A new instance of HttpProbe.
Constructor Details
#initialize(name, uri, username = nil, password = nil) ⇒ HttpProbe
Returns a new instance of HttpProbe.
7 8 9 10 11 12 |
# File 'lib/philae/http_probe.rb', line 7 def initialize(name, uri, username = nil, password = nil) @name = name @uri = uri @username = username @password = password end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/philae/http_probe.rb', line 5 def name @name end |
Instance Method Details
#check ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/philae/http_probe.rb', line 14 def check begin uri = URI(@uri) req = Net::HTTP::Get.new(uri) req.basic_auth @username, @password if !@username.nil? || !@password.nil? resp = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end return { healthy: false, comment: 'Invalid response code' } if resp.code.to_s[0] != '2' && resp.code.to_s[0] != '3' rescue return { healthy: false, comment: 'Unable to contact server' } end { healthy: true, comment: '' } end |