sensu-plugins-http 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YmE4MDg5NjNjNGJlYzEyZDgxNDJhNTc1NjM0YjAxYWViMzEyYTEzZQ==
5
- data.tar.gz: !binary |-
6
- ODFhOTk2M2JmYTdlZmIzNWViNDY4ZmViNDM3ZTQxNzE4ZDM4OGM2MA==
2
+ SHA1:
3
+ metadata.gz: 95a39066cb3a991ed3c72a76eee75116bd29eb6b
4
+ data.tar.gz: 6a13f65bb32146e991fe33685d6505177721da97
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NDEzYjgzNDJhNTYxMDhjMDMzZThmNjllZGY2ZWZiNTUxNGE4YzZjYmZiMWUy
10
- MjE5OWMwMGI1M2IwZGQxYTM5MzIyYWFhNzQ4OTdjMzc3YWRhMjY0NDlmOTQ3
11
- YmY3MGY3YzkyZGNjZDk0ZmU5ZTNiNTE3Yjc1MjEwOGQ3NWIyZGQ=
12
- data.tar.gz: !binary |-
13
- ZTNkZjgwNjcwOTVhNzk2Y2U4YzcwNzU2ZjNhOGEyYmE0M2FjZWI1YjYzNWU0
14
- ODc3NDVlYzdjYTIzZTFhNWQ3MDI0MWFjNzdkNGQyMzMyZTljOTk4ZGJmYmU2
15
- ZmY1YThjNGI5YWU2NDc4NGM3ODg1NWVlMjY3YjJmMjA1YjA5YjY=
6
+ metadata.gz: 3382ead5492e3c4dfffdec1dabbd31b2ed53520542d8aafde38923088561e2d39127f4179f96d4845225fe5db1a5c65435d40afbb7a07c5a48da7f9df618be36
7
+ data.tar.gz: 42b6f719e1ef650e8286e4ea6db0368ef5116170e3d7fc69e3c37e4a2bd1afabf8246067ac7bf4ce6e03394be4f2b678b31ba28d0f8f4272fad5b2b8476bff56
data/CHANGELOG.md CHANGED
@@ -5,7 +5,28 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
- ## [1.0.0] - 2016-01-27
8
+ ## [2.0.0] - 2017-02-20
9
+ ### Breaking Changes
10
+ - Support for Ruby < 2.1 removed. Ruby 2.0 and older are EOL.
11
+ - The `-b` option in `check-http` to send a data body with the request has been changed to `-d` to
12
+ avoid conflicting with the `-b` option to print the bytes of the response.
13
+
14
+ ### Changed
15
+ - Revert rest-client to 1.8 as 2.0 requires ruby >= 2.0 (@sstarcher)
16
+ - `check-http`: change conflicting body short argument letter to `-d` for data (@rmkbow)
17
+
18
+ ### Fixed
19
+ - `metrics-http-json`: fix behavior when a root object key is not specified (@mrooney)
20
+ - Fix CI tests (@RoboticCheese)
21
+
22
+ ### Added
23
+ - `check-http-json`: add an option to return response body (@obazoud)
24
+ - `check-http-json`: support nested hash/array paths in key (@parisholley)
25
+
26
+ ### Removed
27
+ - Support for Ruby < 2.1 (@eheydrick)
28
+
29
+ ## [1.0.0] - 2016-07-27
9
30
  ### Fixed
10
31
  - Don't send basic auth when no password is supplied
11
32
  - Add default thresholds to check-https-cert.rb
@@ -88,7 +109,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
88
109
  ### Added
89
110
  - Initial release
90
111
 
91
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-http/compare/1.0.0...HEAD
112
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-http/compare/2.0.0...HEAD
113
+ [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/1.0.0...2.0.0
92
114
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/0.4.0...1.0.0
93
115
  [0.4.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/0.3.0...0.4.0
94
116
  [0.3.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/0.2.1...0.3.0
@@ -56,6 +56,7 @@ class CheckJson < Sensu::Plugin::Check::CLI
56
56
  option :timeout, short: '-t SECS', proc: proc(&:to_i), default: 15
57
57
  option :key, short: '-K KEY', long: '--key KEY'
58
58
  option :value, short: '-v VALUE', long: '--value VALUE'
59
+ option :whole_response, short: '-w', long: '--whole-response', boolean: true, default: false
59
60
 
60
61
  def run
61
62
  if config[:url]
@@ -84,6 +85,40 @@ class CheckJson < Sensu::Plugin::Check::CLI
84
85
  end
85
86
  end
86
87
 
88
+ def deep_value(data, desired_key, parent = '')
89
+ case data
90
+ when Array
91
+ data.each_with_index do |value, index|
92
+ arr_key = parent + '[' + index.to_s + ']'
93
+
94
+ if arr_key == desired_key
95
+ return value
96
+ end
97
+
98
+ if desired_key.include? arr_key
99
+ search = deep_value(value, desired_key, arr_key)
100
+
101
+ return search unless search.nil?
102
+ end
103
+ end
104
+ when Hash
105
+ data.each do |key, value|
106
+ key_prefix = parent.empty? ? '' : '.'
107
+ hash_key = parent + key_prefix + key
108
+
109
+ if hash_key == desired_key
110
+ return value
111
+ end
112
+
113
+ if desired_key.include?(hash_key + '.') || desired_key.include?(hash_key + '[')
114
+ search = deep_value(value, desired_key, hash_key)
115
+
116
+ return search unless search.nil?
117
+ end
118
+ end
119
+ end
120
+ end
121
+
87
122
  def json_valid?(str)
88
123
  JSON.parse(str)
89
124
  return true
@@ -128,20 +163,19 @@ class CheckJson < Sensu::Plugin::Check::CLI
128
163
  end
129
164
  res = http.request(req)
130
165
 
131
- critical res.code unless res.code =~ /^2/
166
+ unless res.code =~ /^2/
167
+ critacal "http code: #{res.code}: body: #{res.body}" if config[:whole_response]
168
+ critical res.code
169
+ end
132
170
  critical 'invalid JSON from request' unless json_valid?(res.body)
133
171
  ok 'valid JSON returned' if config[:key].nil? && config[:value].nil?
134
172
 
135
173
  json = JSON.parse(res.body)
136
174
 
137
175
  begin
138
- keys = config[:key].scan(/(?:\\\.|[^.])+/).map { |key| key.gsub(/\\./, '.') }
139
-
140
- leaf = keys.reduce(json) do |tree, key|
141
- raise "could not find key: #{config[:key]}" unless tree.key?(key)
142
- tree[key]
143
- end
176
+ leaf = deep_value(json, config[:key])
144
177
 
178
+ raise "could not find key: #{config[:key]}" if leaf.nil?
145
179
  raise "unexpected value for key: '#{config[:value]}' != '#{leaf}'" unless leaf.to_s == config[:value].to_s
146
180
 
147
181
  ok "key has expected value: '#{config[:key]}' = '#{config[:value]}'"
data/bin/check-http.rb CHANGED
@@ -87,9 +87,9 @@ class CheckHttp < Sensu::Plugin::Check::CLI
87
87
  description: 'Send one or more comma-separated headers with the request'
88
88
 
89
89
  option :body,
90
- short: '-b BODY',
90
+ short: '-d BODY',
91
91
  long: '--body BODY',
92
- description: 'Send a body string with the request'
92
+ description: 'Send a data body string with the request'
93
93
 
94
94
  option :ssl,
95
95
  short: '-s',
@@ -82,10 +82,10 @@ class HttpJsonGraphite < Sensu::Plugin::Metric::CLI::Graphite
82
82
  output([scheme, metric].join('.'), v)
83
83
  end
84
84
  end
85
- JSON.parse(r).each do |k, v|
86
- if k == attribute
87
- output([scheme, metric].join('.'), v)
88
- end
85
+ end
86
+ JSON.parse(r).each do |k, v|
87
+ if k == attribute
88
+ output([scheme, metric].join('.'), v)
89
89
  end
90
90
  end
91
91
  end
@@ -1,6 +1,6 @@
1
1
  module SensuPluginsHttp
2
2
  module Version
3
- MAJOR = 1
3
+ MAJOR = 2
4
4
  MINOR = 0
5
5
  PATCH = 0
6
6
 
metadata CHANGED
@@ -1,268 +1,255 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-27 00:00:00.000000000 Z
11
+ date: 2017-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: aws-sdk
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rest-client
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: 1.8.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: 1.8.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.7'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.7'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: codeclimate-test-reporter
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.4'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: github-markup
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '1.3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.3'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0.10'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.10'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '10.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '10.0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: redcarpet
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ~>
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
131
  version: '3.2'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ~>
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '3.2'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ~>
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
145
  version: '3.1'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ~>
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '3.1'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rubocop
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ~>
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
159
  version: 0.40.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ~>
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
166
  version: 0.40.0
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: yard
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
- - - ~>
171
+ - - "~>"
172
172
  - !ruby/object:Gem::Version
173
173
  version: '0.8'
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
- - - ~>
178
+ - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0.8'
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: test-kitchen
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
- - - ~>
185
+ - - "~>"
186
186
  - !ruby/object:Gem::Version
187
187
  version: '1.6'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
- - - ~>
192
+ - - "~>"
193
193
  - !ruby/object:Gem::Version
194
194
  version: '1.6'
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: kitchen-vagrant
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
- - - ~>
199
+ - - "~>"
200
200
  - !ruby/object:Gem::Version
201
201
  version: '0.19'
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
- - - ~>
206
+ - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0.19'
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: kitchen-localhost
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - ~>
213
+ - - "~>"
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0.3'
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - ~>
220
+ - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: '0.3'
223
- - !ruby/object:Gem::Dependency
224
- name: net-ssh
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - ~>
228
- - !ruby/object:Gem::Version
229
- version: '2.9'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - ~>
235
- - !ruby/object:Gem::Version
236
- version: '2.9'
237
223
  - !ruby/object:Gem::Dependency
238
224
  name: json
239
225
  requirement: !ruby/object:Gem::Requirement
240
226
  requirements:
241
- - - <
227
+ - - "<"
242
228
  - !ruby/object:Gem::Version
243
229
  version: 2.0.0
244
230
  type: :development
245
231
  prerelease: false
246
232
  version_requirements: !ruby/object:Gem::Requirement
247
233
  requirements:
248
- - - <
234
+ - - "<"
249
235
  - !ruby/object:Gem::Version
250
236
  version: 2.0.0
251
- description: ! "This plugin provides native HTTP instrumentation\n for
252
- monitoring and metrics collection, including:\n response
253
- code, JSON response, HTTP last modified,\n SSL expiry,
254
- and metrics via `curl`."
255
- email: <sensu-users@googlegroups.com>
237
+ description: |-
238
+ This plugin provides native HTTP instrumentation
239
+ for monitoring and metrics collection, including:
240
+ response code, JSON response, HTTP last modified,
241
+ SSL expiry, and metrics via `curl`.
242
+ email: "<sensu-users@googlegroups.com>"
256
243
  executables:
257
- - metrics-http-json-deep.rb
258
244
  - check-http-json.rb
259
- - metrics-curl.rb
245
+ - check-http.rb
246
+ - metrics-http-json-deep.rb
247
+ - metrics-http-json.rb
260
248
  - check-last-modified.rb
261
- - check-https-cert.rb
262
249
  - check-http-cors.rb
250
+ - check-https-cert.rb
263
251
  - check-head-redirect.rb
264
- - metrics-http-json.rb
265
- - check-http.rb
252
+ - metrics-curl.rb
266
253
  extensions: []
267
254
  extra_rdoc_files: []
268
255
  files:
@@ -297,17 +284,17 @@ require_paths:
297
284
  - lib
298
285
  required_ruby_version: !ruby/object:Gem::Requirement
299
286
  requirements:
300
- - - ! '>='
287
+ - - ">="
301
288
  - !ruby/object:Gem::Version
302
- version: 2.0.0
289
+ version: 2.1.0
303
290
  required_rubygems_version: !ruby/object:Gem::Requirement
304
291
  requirements:
305
- - - ! '>='
292
+ - - ">="
306
293
  - !ruby/object:Gem::Version
307
294
  version: '0'
308
295
  requirements: []
309
296
  rubyforge_project:
310
- rubygems_version: 2.4.3
297
+ rubygems_version: 2.4.8
311
298
  signing_key:
312
299
  specification_version: 4
313
300
  summary: Sensu plugins for various http monitors and metrics