sensu-plugins-http 2.4.0 → 2.5.0

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
  SHA1:
3
- metadata.gz: ca57c0e31d8ed570c39220d5e53e58f0f0ab1653
4
- data.tar.gz: 4bb90f34c4cbe01c73620dc70d0cee45049f0a9d
3
+ metadata.gz: 2a45f782620f82677c15eebd6b7b47a78ec9f088
4
+ data.tar.gz: 7ebd595a2c7e394ff91c0f80f0309529ee9a736d
5
5
  SHA512:
6
- metadata.gz: 05165b0c233127001b007ca723bd3dec67e911b3f8eb3fa98c65d45421a64c6b69b18c411c5944914a1da0492f2252143297f88df118d0cafc8794b6c381d81b
7
- data.tar.gz: b216a8da06a548df33a1a64a8faf70db40524e95928663d40a05624ba7034bf6ebad2529e5b4fe1ad2e0fb5ffd585c6ff5fe56015573db07d5ec4acffa54d726
6
+ metadata.gz: 1ba70ef7c3d652b2ad84988feab12f494c225c609d1d53b58ce2bd9aefc68389cfceb21d43ba36290d53c4b7dac3a021f3f0e2fbe9fd8854a0bbe8d0e206d5a3
7
+ data.tar.gz: ec9597333137cee04918cb0de68f7c865ca84df3d40ed33730afcb92d7c3cb15612713569fbc797379651f3c8203de7dbc1d750af6187534f740f2c0bdeda2c7
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [2.5.0] - 2017-07-06
9
+ ### Added
10
+ - `check-http`: Added ability to sign requests with AWS V4 authentication (@ajmath)
11
+
8
12
  ## [2.4.0] - 2017-06-19
9
13
  ### Added
10
14
  - Initial set of tests for `check-https-cert.rb` (@pgporada)
@@ -139,7 +143,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
139
143
  ### Added
140
144
  - Initial release
141
145
 
142
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-http/compare/2.4.0...HEAD
146
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-http/compare/2.5.0...HEAD
147
+ [2.5.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/2.4.0...2.5.0
143
148
  [2.4.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/2.3.0...2.4.0
144
149
  [2.3.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/2.2.0...2.3.0
145
150
  [2.2.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/2.1.0...2.2.0
data/bin/check-http.rb CHANGED
@@ -44,6 +44,7 @@
44
44
  # for details.
45
45
  #
46
46
 
47
+ require 'sensu-plugins-http'
47
48
  require 'sensu-plugin/check/cli'
48
49
  require 'net/http'
49
50
  require 'net/https'
@@ -201,6 +202,23 @@ class CheckHttp < Sensu::Plugin::Check::CLI
201
202
  description: 'Do not use proxy server even from environment http_proxy setting',
202
203
  default: false
203
204
 
205
+ option :aws_v4,
206
+ long: '--aws-v4',
207
+ boolean: true,
208
+ description: 'Sign http request with AWS v4 signature',
209
+ default: false
210
+
211
+ option :aws_v4_region,
212
+ long: '--aws-v4-region REGION',
213
+ description: 'Region to use for AWS v4 signing. Defaults to AWS_REGION or AWS_DEFAULT_REGION'
214
+
215
+ option :aws_v4_service,
216
+ long: '--aws-v4-service SERVICE',
217
+ description: 'Service name to use when building the v4 signature',
218
+ default: 'execute-api'
219
+
220
+ include SensuPluginsHttp::AwsV4
221
+
204
222
  def run
205
223
  if config[:url]
206
224
  uri = URI.parse(config[:url])
@@ -291,6 +309,8 @@ class CheckHttp < Sensu::Plugin::Check::CLI
291
309
  end
292
310
  req.body = config[:body] if config[:body]
293
311
 
312
+ req = apply_v4_signature(http, req, config) if config[:aws_v4]
313
+
294
314
  res = http.request(req)
295
315
 
296
316
  body = if config[:whole_response]
@@ -0,0 +1,38 @@
1
+ module SensuPluginsHttp
2
+ module AwsV4
3
+ # Returns a modified request object with AWS v4 signature headers
4
+ # and authentication options (if any)
5
+ #
6
+ # @param [Net::HTTP] http
7
+ # The http object used to execute the request. Used to build uri
8
+ # @param [Net::HTTPGenericRequest] req
9
+ # The http request. Used to populate headers, path, method, and body
10
+ # @param [Hash] options Details about how to configure the request
11
+ # @option options [String] :aws_v4_service
12
+ # AWS service to use in signature. Defaults to 'execute-api'
13
+ # @option options [String] :aws_v4_region
14
+ # AWS region to use in signature. Defaults to
15
+ # ENV['AWS_REGION'] or ENV['AWS_DEFAULT_REGION']
16
+ def apply_v4_signature(http, req, options = {})
17
+ require 'aws-sdk'
18
+
19
+ fake_seahorse = Struct.new(:endpoint, :body, :headers, :http_method)
20
+ headers = {}
21
+ req.each_name { |name| headers[name] = req[name] }
22
+ protocol = http.use_ssl? ? 'https' : 'http'
23
+ uri = URI.parse("#{protocol}://#{http.address}:#{http.port}#{req.path}")
24
+ fake_req = fake_seahorse.new(uri, req.body || '',
25
+ headers, req.method)
26
+
27
+ credentials = Aws::CredentialProviderChain.new.resolve
28
+ service = options[:aws_v4_service] || 'execute-api'
29
+ region = options[:aws_v4_region] || ENV['AWS_REGION'] || ENV['AWS_DEFAULT_REGION']
30
+ signer = Aws::Signers::V4.new(credentials, service, region)
31
+
32
+ signed_req = signer.sign(fake_req)
33
+ signed_req.headers.each { |key, value| req[key] = value }
34
+
35
+ req
36
+ end
37
+ end
38
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsHttp
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 4
4
+ MINOR = 5
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -1,2 +1,3 @@
1
1
  require 'sensu-plugins-http/version'
2
2
  require 'sensu-plugins-http/common'
3
+ require 'sensu-plugins-http/aws-v4'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.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: 2017-06-20 00:00:00.000000000 Z
11
+ date: 2017-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -241,15 +241,15 @@ description: |-
241
241
  SSL expiry, and metrics via `curl`.
242
242
  email: "<sensu-users@googlegroups.com>"
243
243
  executables:
244
- - check-http-json.rb
245
- - check-http.rb
246
244
  - metrics-http-json-deep.rb
247
- - metrics-http-json.rb
248
- - check-last-modified.rb
245
+ - metrics-curl.rb
249
246
  - check-http-cors.rb
250
247
  - check-https-cert.rb
248
+ - check-last-modified.rb
249
+ - check-http.rb
250
+ - check-http-json.rb
251
+ - metrics-http-json.rb
251
252
  - check-head-redirect.rb
252
- - metrics-curl.rb
253
253
  extensions: []
254
254
  extra_rdoc_files: []
255
255
  files:
@@ -266,6 +266,7 @@ files:
266
266
  - bin/metrics-http-json-deep.rb
267
267
  - bin/metrics-http-json.rb
268
268
  - lib/sensu-plugins-http.rb
269
+ - lib/sensu-plugins-http/aws-v4.rb
269
270
  - lib/sensu-plugins-http/common.rb
270
271
  - lib/sensu-plugins-http/version.rb
271
272
  homepage: https://github.com/sensu-plugins/sensu-plugins-http
@@ -294,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
294
295
  version: '0'
295
296
  requirements: []
296
297
  rubyforge_project:
297
- rubygems_version: 2.4.8
298
+ rubygems_version: 2.6.12
298
299
  signing_key:
299
300
  specification_version: 4
300
301
  summary: Sensu plugins for various http monitors and metrics