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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b22be9cda692ebefffa0f9af6877afa972d1dbbc83d12d202163767c9d360dd4
4
- data.tar.gz: e61c1188e1061ccd69ea3c83eb036d83fa9184b61058bd293a49ac07022f4ebf
3
+ metadata.gz: 19f29788c1d9cfd03068ba09dd7c35495a583978bb2f7dd87d4914ca14d63261
4
+ data.tar.gz: 93e288834b180ca0826b12643192d3177e71d08742e15fc9a651c2ad7bc53ba7
5
5
  SHA512:
6
- metadata.gz: affa26c31930fe117b92e37e07c8265eadadcbb8685f3c74bfb1fe00d53197c82cf035cc9665fce0d9959069dcd0293142830f72df2537ad5c5cabd97dc83d5e
7
- data.tar.gz: 6b3ed70ced13c6b0f92b8a5c40f60d6cb031d68f50bdc6b3f429659e26e336364933dcb01e26e66819f03f972055d8493202de179c9d595c7ce10edab5436120
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
- attr_accessor :request_method
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("#{request_method.upcase} #{@alias} responded with response '#{response.code} #{response.message}'")
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 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tribune-is_it_working
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand