Class: Philae::PhilaeProbe
- Inherits:
-
Object
- Object
- Philae::PhilaeProbe
- Defined in:
- lib/philae/philae_probe.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(name, uri, username = nil, password = nil) ⇒ PhilaeProbe
constructor
A new instance of PhilaeProbe.
Constructor Details
#initialize(name, uri, username = nil, password = nil) ⇒ PhilaeProbe
Returns a new instance of PhilaeProbe.
8 9 10 11 12 13 |
# File 'lib/philae/philae_probe.rb', line 8 def initialize(name, uri, username = nil, password = nil) @name = name @uri = uri @username = username @password = password end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/philae/philae_probe.rb', line 6 def name @name end |
Instance Method Details
#check ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/philae/philae_probe.rb', line 15 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 if resp.code.to_s[0] != '2' && resp.code.to_s[0] != '3' return { healthy: false, comment: 'Invalid return code' } end status = JSON.parse(resp.body) if status['healthy'] return { healthy: true, comment: '' } else return { healthy: false, comment: 'node not healthy' } end rescue return { healthy: false, comment: 'Unable to contact server' } end end |