Class: What::Modules::Http
- Inherits:
-
Base
- Object
- Base
- What::Modules::Http
show all
- Defined in:
- lib/what/modules/http.rb
Instance Attribute Summary
Attributes inherited from Base
#interval
Instance Method Summary
collapse
Methods inherited from Base
#identifier, #initialize, #name, #shared_status, #start_monitoring, #status
Instance Method Details
#check ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/what/modules/http.rb', line 13
def check
resp = Net::HTTP.get_response(@url)
@status = resp.code.to_i
@body = resp.body.strip
@got_response = true
rescue Net::ReadTimeout => e
@got_response = false
end
|
#details ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/what/modules/http.rb', line 34
def details
{
'status' => @status,
'last_response' => @body[0..200],
'got_response' => @got_response
}
end
|
#health ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/what/modules/http.rb', line 22
def health
if !@got_response
'alert'
elsif @status != 200
'alert'
elsif @expect && @expect != @body
'alert'
else
'ok'
end
end
|
#initialize_module ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/what/modules/http.rb', line 5
def initialize_module
@url = URI.parse @config['url']
@expect = @config['expect'].strip if @config['expect']
@status = -1
@body = ''
end
|