tribune-is_it_working 1.0.9 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/is_it_working/checks/url_check.rb +38 -8
- data/lib/is_it_working/filter.rb +4 -3
- data/lib/is_it_working/handler.rb +5 -4
- data/lib/is_it_working/status.rb +3 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c06c40921e40bbcd62cb5442f165837704997ed0676bfa6ffedcbdec26886b10
|
4
|
+
data.tar.gz: 046d065c1c02741933ecc2df05867014cbf6ad262f66f596ae31d234b3fcce34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3dcd717dea11e62123bae07dc0f8cc031e9ff6aca8bb8389b9ce605964065b045f763b8aa63c1fa50707cb8e10b01a68cb9d7dd8cf55e38eb105cfd5a4817f1
|
7
|
+
data.tar.gz: e18cdba1a5ff9767468717dae3d2fabe1a8ec4f68273d2f7c09b26779f62939219169b63e63a72b796ed7154d09c7652693abd67b3e5ebe704cfdf2560e8053a
|
@@ -8,6 +8,8 @@ module IsItWorking
|
|
8
8
|
# Available options are:
|
9
9
|
#
|
10
10
|
# * <tt>:get</tt> - The URL to get.
|
11
|
+
# * <tt>:post</tt> - The URL to post.
|
12
|
+
# * <tt>:payload</tt> - Request body parameters.
|
11
13
|
# * <tt>:headers</tt> - Hash of headers to send with the request
|
12
14
|
# * <tt>:proxy</tt> - Hash of proxy server information. The hash must contain a <tt>:host</tt> key and may contain <tt>:port</tt>, <tt>:username</tt>, and <tt>:password</tt>
|
13
15
|
# * <tt>:username</tt> - Username to use for Basic Authentication
|
@@ -15,35 +17,56 @@ module IsItWorking
|
|
15
17
|
# * <tt>:open_timeout</tt> - Time in seconds to wait for opening the connection (defaults to 5 seconds)
|
16
18
|
# * <tt>:read_timeout</tt> - Time in seconds to wait for data from the connection (defaults to 10 seconds)
|
17
19
|
# * <tt>:alias</tt> - Alias used for reporting in case making the URL known to the world could provide a security risk.
|
18
|
-
#
|
20
|
+
# * <tt>:follow_redirect</tt> - Follow 302 redirect or not (defaults to true)
|
19
21
|
# === Example
|
20
22
|
#
|
21
23
|
# IsItWorking::Handler.new do |h|
|
22
24
|
# h.check :url, :get => "http://services.example.com/api", :headers => {"Accept" => "text/xml"}
|
25
|
+
# h.check :url, :post => "http://services.example.com/api",:headers => {"Content-Type" => "application/json"}
|
23
26
|
# end
|
24
27
|
class UrlCheck
|
28
|
+
|
29
|
+
attr_reader :request_method, :request_payload
|
30
|
+
# Follow 302 redirect or not, default is true
|
31
|
+
attr_reader :follow_redirect
|
32
|
+
|
25
33
|
def initialize(options={})
|
26
|
-
|
27
|
-
|
34
|
+
# TODO: Add support for PUT, DELETE & PATCH request methods
|
35
|
+
raise ArgumentError.new(":get|:post must provide the URL to check") unless options[:get] || options[:post]
|
36
|
+
# request method (get|post|put|delete)
|
37
|
+
@request_method = if options.key?(:get)
|
38
|
+
:get
|
39
|
+
elsif options.key?(:post)
|
40
|
+
:post
|
41
|
+
else
|
42
|
+
:get # fallback
|
43
|
+
end
|
44
|
+
@request_payload = options[:payload]
|
45
|
+
@follow_redirect = options[:follow_redirect].nil? ? true : options[:follow_redirect]
|
46
|
+
@uri = URI.parse(options[request_method])
|
28
47
|
@headers = options[:headers] || {}
|
29
48
|
@proxy = options[:proxy]
|
30
49
|
@username = options[:username]
|
31
50
|
@password = options[:password]
|
32
51
|
@open_timeout = options[:open_timeout] || 5
|
33
52
|
@read_timeout = options[:read_timeout] || 10
|
34
|
-
@alias = options[:alias] || options[
|
53
|
+
@alias = options[:alias] || options[request_method]
|
35
54
|
end
|
36
55
|
|
37
56
|
def call(status)
|
38
57
|
t = Time.now
|
39
58
|
response = perform_http_request
|
59
|
+
ok_msg = "#{request_method.upcase} #{@alias} responded with response '#{response.code} #{response.message}'"
|
40
60
|
if response.is_a?(Net::HTTPSuccess)
|
41
|
-
status.ok(
|
61
|
+
status.ok(ok_msg)
|
62
|
+
# 200 ok for 302 unless follow_redirect
|
63
|
+
elsif response.is_a?(Net::HTTPRedirection) && !follow_redirect
|
64
|
+
status.ok(ok_msg)
|
42
65
|
else
|
43
|
-
status.fail("
|
66
|
+
status.fail("#{request_method.upcase} #{@alias} failed with response '#{response.code} #{response.message}'")
|
44
67
|
end
|
45
68
|
rescue Timeout::Error
|
46
|
-
status.fail("
|
69
|
+
status.fail("#{request_method.upcase} #{@alias} timed out after #{Time.now - t} seconds")
|
47
70
|
end
|
48
71
|
|
49
72
|
private
|
@@ -70,7 +93,14 @@ module IsItWorking
|
|
70
93
|
|
71
94
|
# Perform an HTTP request and return the response
|
72
95
|
def perform_http_request #:nodoc:
|
73
|
-
|
96
|
+
case request_method
|
97
|
+
when :post
|
98
|
+
request = Net::HTTP::Post.new(@uri.request_uri, @headers)
|
99
|
+
# Assign request_payload to body if it present
|
100
|
+
request.body = request_payload.to_json unless request_payload.blank?
|
101
|
+
else
|
102
|
+
request = Net::HTTP::Get.new(@uri.request_uri, @headers)
|
103
|
+
end
|
74
104
|
request.basic_auth(@username, @password) if @username || @password
|
75
105
|
http = instantiate_http
|
76
106
|
http.start do
|
data/lib/is_it_working/filter.rb
CHANGED
@@ -19,12 +19,13 @@ module IsItWorking
|
|
19
19
|
attr_reader :name, :async
|
20
20
|
|
21
21
|
# name and description of Component
|
22
|
-
attr_reader :component_name, :description
|
22
|
+
attr_reader :component_name, :component_type, :description
|
23
23
|
|
24
24
|
# Create a new filter to run a status check. The name is used for display purposes.
|
25
|
-
def initialize(name, component_name, description, check, async = true)
|
25
|
+
def initialize(name, component_name, component_type, description, check, async = true)
|
26
26
|
@name = name
|
27
27
|
@component_name = component_name
|
28
|
+
@component_type = component_type
|
28
29
|
@description = description
|
29
30
|
@check = check
|
30
31
|
@async = async
|
@@ -33,7 +34,7 @@ module IsItWorking
|
|
33
34
|
# Run a status the status check. This method keeps track of the time it took to run
|
34
35
|
# the check and will trap any unexpected exceptions and report them as failures.
|
35
36
|
def run
|
36
|
-
status = IsItWorking::Status.new(name, component_name, description)
|
37
|
+
status = IsItWorking::Status.new(name, component_name, component_type, description)
|
37
38
|
runner = (async ? AsyncRunner : SyncRunner).new do
|
38
39
|
t = Time.now
|
39
40
|
begin
|
@@ -104,9 +104,11 @@ module IsItWorking
|
|
104
104
|
# New Params:
|
105
105
|
# @param: component_name [String] optional
|
106
106
|
# => for which component checking health-check (ex: dss-url, zephr-url, active_record etc)
|
107
|
+
# @param: component_type [String] optional
|
108
|
+
# => for which component_type checking health-check (ex: Database, MemCache etc)
|
107
109
|
# @param: description [String] optional
|
108
110
|
# => Description for health-check for component
|
109
|
-
@filters << IsItWorking::Filter.new(name, options[:component_name],
|
111
|
+
@filters << IsItWorking::Filter.new(name, options[:component_name], options[:component_type],
|
110
112
|
options[:description], check, options[:async])
|
111
113
|
end
|
112
114
|
|
@@ -163,15 +165,14 @@ module IsItWorking
|
|
163
165
|
# Seperate method for rendeing/returning JSON
|
164
166
|
def render_json(statuses, elapsed_time) #:nodoc:
|
165
167
|
fail = statuses.all?{|s| s.success?}
|
166
|
-
messages = []
|
167
168
|
components = []
|
168
169
|
total_fail_count = 0
|
169
170
|
statuses.each do |status|
|
170
171
|
status.messages.each do |m|
|
171
|
-
messages << "#{m.ok? ? 'OK: ' : 'FAIL:'} #{status.name} - #{m.message} (#{status.time ? sprintf('%0.000f', status.time * 1000) : '?'}ms)"
|
172
172
|
message = { name: status.name,
|
173
173
|
component_name: status.component_name,
|
174
|
-
|
174
|
+
component_type: status.component_type,
|
175
|
+
info: "#{m.message} (#{status.time ? sprintf('%0.000f', status.time * 1000) : '?'}ms)",
|
175
176
|
time: status.time,
|
176
177
|
success: m.ok? ? true : false,
|
177
178
|
description: status.description }
|
data/lib/is_it_working/status.rb
CHANGED
@@ -22,7 +22,7 @@ module IsItWorking
|
|
22
22
|
attr_reader :name
|
23
23
|
|
24
24
|
# name and description of Component
|
25
|
-
attr_reader :component_name, :description
|
25
|
+
attr_reader :component_name, :component_type, :description
|
26
26
|
|
27
27
|
# The messages set on the status check.
|
28
28
|
attr_reader :messages
|
@@ -30,9 +30,10 @@ module IsItWorking
|
|
30
30
|
# The amount of time it takes to complete the status check.
|
31
31
|
attr_accessor :time
|
32
32
|
|
33
|
-
def initialize(name, component_name, description)
|
33
|
+
def initialize(name, component_name, component_type, description)
|
34
34
|
@name = name
|
35
35
|
@component_name = component_name
|
36
|
+
@component_type = component_type
|
36
37
|
@description = description
|
37
38
|
@messages = []
|
38
39
|
end
|