tribune-is_it_working 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/is_it_working/checks/url_check.rb +23 -7
- 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: b22be9cda692ebefffa0f9af6877afa972d1dbbc83d12d202163767c9d360dd4
|
4
|
+
data.tar.gz: e61c1188e1061ccd69ea3c83eb036d83fa9184b61058bd293a49ac07022f4ebf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: affa26c31930fe117b92e37e07c8265eadadcbb8685f3c74bfb1fe00d53197c82cf035cc9665fce0d9959069dcd0293142830f72df2537ad5c5cabd97dc83d5e
|
7
|
+
data.tar.gz: 6b3ed70ced13c6b0f92b8a5c40f60d6cb031d68f50bdc6b3f429659e26e336364933dcb01e26e66819f03f972055d8493202de179c9d595c7ce10edab5436120
|
@@ -20,30 +20,41 @@ module IsItWorking
|
|
20
20
|
#
|
21
21
|
# IsItWorking::Handler.new do |h|
|
22
22
|
# h.check :url, :get => "http://services.example.com/api", :headers => {"Accept" => "text/xml"}
|
23
|
+
# h.check :url, :post => "http://services.example.com/api",:headers => {"Content-Type" => "application/json"}
|
23
24
|
# end
|
24
25
|
class UrlCheck
|
26
|
+
attr_accessor :request_method
|
25
27
|
def initialize(options={})
|
26
|
-
|
27
|
-
|
28
|
+
# TODO: Add support for PUT, DELETE & PATCH request methods
|
29
|
+
raise ArgumentError.new(":get|:post must provide the URL to check") unless options[:get] || options[:post]
|
30
|
+
# request method (get|post|put|delete)
|
31
|
+
@request_method = if options.key?(:get)
|
32
|
+
:get
|
33
|
+
elsif options.key?(:post)
|
34
|
+
:post
|
35
|
+
else
|
36
|
+
:get # fallback
|
37
|
+
end
|
38
|
+
@uri = URI.parse(options[request_method])
|
28
39
|
@headers = options[:headers] || {}
|
29
40
|
@proxy = options[:proxy]
|
30
41
|
@username = options[:username]
|
31
42
|
@password = options[:password]
|
32
43
|
@open_timeout = options[:open_timeout] || 5
|
33
44
|
@read_timeout = options[:read_timeout] || 10
|
34
|
-
@alias = options[:alias] || options[
|
45
|
+
@alias = options[:alias] || options[request_method]
|
35
46
|
end
|
36
47
|
|
37
48
|
def call(status)
|
38
49
|
t = Time.now
|
39
50
|
response = perform_http_request
|
40
51
|
if response.is_a?(Net::HTTPSuccess)
|
41
|
-
status.ok("
|
52
|
+
status.ok("#{request_method.upcase} #{@alias} responded with response '#{response.code} #{response.message}'")
|
42
53
|
else
|
43
|
-
status.fail("
|
54
|
+
status.fail("#{request_method.upcase} #{@alias} failed with response '#{response.code} #{response.message}'")
|
44
55
|
end
|
45
56
|
rescue Timeout::Error
|
46
|
-
status.fail("
|
57
|
+
status.fail("#{request_method.upcase} #{@alias} timed out after #{Time.now - t} seconds")
|
47
58
|
end
|
48
59
|
|
49
60
|
private
|
@@ -70,7 +81,12 @@ module IsItWorking
|
|
70
81
|
|
71
82
|
# Perform an HTTP request and return the response
|
72
83
|
def perform_http_request #:nodoc:
|
73
|
-
|
84
|
+
case request_method
|
85
|
+
when :post
|
86
|
+
request = Net::HTTP::Post.new(@uri.request_uri, @headers)
|
87
|
+
else
|
88
|
+
request = Net::HTTP::Get.new(@uri.request_uri, @headers)
|
89
|
+
end
|
74
90
|
request.basic_auth(@username, @password) if @username || @password
|
75
91
|
http = instantiate_http
|
76
92
|
http.start do
|