Class: GranPulse::Url
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Attributes inherited from Check
Instance Method Summary collapse
-
#initialize ⇒ Url
constructor
A new instance of Url.
- #perform(params) ⇒ Object
Constructor Details
#initialize ⇒ Url
Returns a new instance of Url.
5 6 7 |
# File 'app/models/gran_pulse/url.rb', line 5 def initialize self.type = 'url' end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'app/models/gran_pulse/url.rb', line 3 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'app/models/gran_pulse/url.rb', line 3 def port @port end |
Instance Method Details
#perform(params) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/gran_pulse/url.rb', line 9 def perform params self.host = URI.parse(params[:host]).host self.port = params[:port] || 80 begin Timeout::timeout(1) do begin s = TCPSocket.new(host, port) s.close self.healthy = true self. = 'ok' rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e self.healthy = false self. = e end end rescue Timeout::Error self.healthy = false self. = 'timeout' end self end |