tribune-is_it_working 1.1.0 → 1.1.1
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 +17 -3
- data/lib/is_it_working/handler.rb +1 -3
- 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: 19f29788c1d9cfd03068ba09dd7c35495a583978bb2f7dd87d4914ca14d63261
|
4
|
+
data.tar.gz: 93e288834b180ca0826b12643192d3177e71d08742e15fc9a651c2ad7bc53ba7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bded01d7f39448874cce85f243647387cf227825d4d6cfa1f086e835e649debfa07c3b73f3d445da1ee01215ca4bd4aabc7b7fe514b6dd07f89e6453a371eec
|
7
|
+
data.tar.gz: bb8a754c454eb6c3b7123f585c90886de536eb7b8e0fb6a12b024b6118f54614711fccd331b79a86541c6b599af10e7082a1cc9b7cd8b3a51444535c197e1abf
|
@@ -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,7 +17,7 @@ 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|
|
@@ -23,7 +25,11 @@ module IsItWorking
|
|
23
25
|
# h.check :url, :post => "http://services.example.com/api",:headers => {"Content-Type" => "application/json"}
|
24
26
|
# end
|
25
27
|
class UrlCheck
|
26
|
-
|
28
|
+
|
29
|
+
attr_reader :request_method, :request_payload
|
30
|
+
# Follow 302 redirect or not, default is true
|
31
|
+
attr_reader :follow_redirect
|
32
|
+
|
27
33
|
def initialize(options={})
|
28
34
|
# TODO: Add support for PUT, DELETE & PATCH request methods
|
29
35
|
raise ArgumentError.new(":get|:post must provide the URL to check") unless options[:get] || options[:post]
|
@@ -35,6 +41,8 @@ module IsItWorking
|
|
35
41
|
else
|
36
42
|
:get # fallback
|
37
43
|
end
|
44
|
+
@request_payload = options[:payload]
|
45
|
+
@follow_redirect = options[:follow_redirect].nil? ? true : options[:follow_redirect]
|
38
46
|
@uri = URI.parse(options[request_method])
|
39
47
|
@headers = options[:headers] || {}
|
40
48
|
@proxy = options[:proxy]
|
@@ -48,8 +56,12 @@ module IsItWorking
|
|
48
56
|
def call(status)
|
49
57
|
t = Time.now
|
50
58
|
response = perform_http_request
|
59
|
+
ok_msg = "#{request_method.upcase} #{@alias} responded with response '#{response.code} #{response.message}'"
|
51
60
|
if response.is_a?(Net::HTTPSuccess)
|
52
|
-
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)
|
53
65
|
else
|
54
66
|
status.fail("#{request_method.upcase} #{@alias} failed with response '#{response.code} #{response.message}'")
|
55
67
|
end
|
@@ -84,6 +96,8 @@ module IsItWorking
|
|
84
96
|
case request_method
|
85
97
|
when :post
|
86
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?
|
87
101
|
else
|
88
102
|
request = Net::HTTP::Get.new(@uri.request_uri, @headers)
|
89
103
|
end
|
@@ -163,15 +163,13 @@ module IsItWorking
|
|
163
163
|
# Seperate method for rendeing/returning JSON
|
164
164
|
def render_json(statuses, elapsed_time) #:nodoc:
|
165
165
|
fail = statuses.all?{|s| s.success?}
|
166
|
-
messages = []
|
167
166
|
components = []
|
168
167
|
total_fail_count = 0
|
169
168
|
statuses.each do |status|
|
170
169
|
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
170
|
message = { name: status.name,
|
173
171
|
component_name: status.component_name,
|
174
|
-
info: "#{m.message} (#{status.time ? sprintf('%0.000f', status.time * 1000) : '?'}ms",
|
172
|
+
info: "#{m.message} (#{status.time ? sprintf('%0.000f', status.time * 1000) : '?'}ms)",
|
175
173
|
time: status.time,
|
176
174
|
success: m.ok? ? true : false,
|
177
175
|
description: status.description }
|