sensu-plugins-http 5.1.1 → 6.0.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
  SHA256:
3
- metadata.gz: 1b0495f80bf93d4fd28a5974b5af0d2f11861e50778fb1b1972281a64a63d623
4
- data.tar.gz: 6c09b75331eac1000e9b8d7f4d13febac4309d50d6a7b7e1b5b8721b05386156
3
+ metadata.gz: d193fb1024e7a3e545f9cf4cc88ebece09511d688a85dc78cee839936c998349
4
+ data.tar.gz: de667092233f6676751c01610c8fb154a8321f8500e02acfce114432576ba056
5
5
  SHA512:
6
- metadata.gz: 649da5a29714d569bc287e19a4a76185dce76f1d791db61f6167b51721a3e0b57aea7b89fa0e61349bb212e1bc6621b59eff97cb1fb7c67f38c169724345e1fc
7
- data.tar.gz: fed3fc5d2cfd2c1f07a7a890749f4370377114522fbc5851b41c93be0a4704edbaaade8f24b216f153434a7939d699f9c8766ed44a95a1075b4ddc188eaae288
6
+ metadata.gz: 89bbfd559da67522f7fbe49f92b6723323d136b5adaff9c376faa75a1ec94188740307f09f535c53acf18a7e97ecb0690206573d8b33138d15f2467c9c53b50f
7
+ data.tar.gz: 21c7cee2151d64d4339748adfbf4019d2c325a0481d69d2c49b079ade88bd0f26d57e30d4a0c45e932d7f17f2725f34715db144dc84a4e7fb5f0f9b47bc6eac0
data/CHANGELOG.md CHANGED
@@ -5,6 +5,31 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [6.0.0] - 2020-01-17
9
+ ### Added
10
+ - New metrics-libcurl.rb metrics check that works directly with libcurl and does not need curl executable on system. Very useful as an asset in containerized Sensu Agent installs.
11
+ - `check-http.rb`: Add `HEAD` to method options
12
+ - `check-http.rb` Added option to include file with multiple headers, useful for long list of headers.
13
+
14
+ ### Fixed
15
+ - Updated asset build automation for Alpine target to ensure curl and libcurl based metrics work.
16
+ - `check-http.rb`: An empty response body when using `-w` no longer creates a potentially confusing `no implicit conversion of nil into String` error
17
+
18
+ ### Changed
19
+ - Updated bundler development dependancy to '~> 2.1'
20
+ - Make rake Kitchen tasks conditional on ability to load kitchen module in development env. kitchen module will not load on hosts without docker runtime.
21
+ - Update asset build definitions to match targets supported by ruby-runtime
22
+ - Updated test-kitchen development dependancy from '~> 1.23.5' to '~> 1.25.0'
23
+ - Updated rubocop requirement 'from ~> 0.51.0' to '~> 0.79.0'
24
+ - Updated rake requirement from '~> 12.3' to '~> 13.0'
25
+ - Updated rest-client runtime requirement from '~> 2.0.2' to '~> 2.1'
26
+ - Make rdoc a development requirement for ruby installations that package rdoc as a gem instead of as part of base ruby
27
+ - Updated metrics-curl.rb to check for existance of curl executable in PATH. If not found, reports critical error with message.
28
+
29
+ ### Breaking Change
30
+ - Updated json requirement from '< 2.0.0' to '~> 2.3'
31
+ - Updated oj requirement from '~> 2.18' to '~> 3.10'
32
+
8
33
  ## [5.1.1] - 2019-06-21
9
34
  ### Fixed
10
35
  - Fix issue with JSON.parse referencing sensu-plugin subclass instead of top level ::JSON module as intended
@@ -244,7 +269,8 @@ metrics-http-json.rb: Added debug option to see the processing of json data
244
269
  ### Added
245
270
  - Initial release
246
271
 
247
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-http/compare/5.1.1...HEAD
272
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-http/compare/6.0.0...HEAD
273
+ [6.0.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/5.1.1...6.0.0
248
274
  [5.1.1]: https://github.com/sensu-plugins/sensu-plugins-http/compare/5.1.0...5.1.1
249
275
  [5.1.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/5.0.0...5.1.0
250
276
  [5.0.0]: https://github.com/sensu-plugins/sensu-plugins-http/compare/4.1.0...5.0.0
data/README.md CHANGED
@@ -1,28 +1,152 @@
1
- ## Sensu-Plugins-http
2
-
1
+ [![Sensu Bonsai Asset](https://img.shields.io/badge/Bonsai-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/sensu-plugins/sensu-plugins-http)
3
2
  [![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-http.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-http)
4
3
  [![Gem Version](https://badge.fury.io/rb/sensu-plugins-http.svg)](http://badge.fury.io/rb/sensu-plugins-http)
5
4
  [![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-http.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-http)
6
- [![Sensu Bonsai Asset](https://img.shields.io/badge/Bonsai-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/sensu-plugins/sensu-plugins-http)
7
5
 
8
- ## Sensu Asset
9
- The Sensu assets packaged from this repository are built against the Sensu ruby runtime environment. When using these assets as part of a Sensu Go resource (check, mutator or handler), make sure you include the corresponding Sensu ruby runtime asset in the list of assets needed by the resource. The current ruby-runtime assets can be found [here](https://bonsai.sensu.io/assets/sensu/sensu-ruby-runtime) in the [Bonsai Asset Index](bonsai.sensu.io).
6
+ ## Sensu HTTP Plugin
10
7
 
8
+ - [Overview](#overview)
9
+ - [Usage examples](#usage-examples)
10
+ - [Configuration](#configuration)
11
+ - [Sensu Go](#sensu-go)
12
+ - [Asset definition](#asset-definition)
13
+ - [Check definition](#check-definition)
14
+ - [Sensu Core](#sensu-core)
15
+ - [Check definition](#check-definition)
16
+ - [Functionality](#functionality)
17
+ - [Additional information](#additional-information)
18
+ - [Installation](#installation)
11
19
 
12
- ## Functionality
20
+ ### Overview
13
21
 
14
- ## Files
22
+ This plugin provides native HTTP instrumentation for monitoring and metrics collection, including: response code, JSON response, HTTP last modified, SSL expiry, and metrics via `curl`.
23
+
24
+ The Sensu assets packaged from this repository are built against the Sensu ruby runtime environment. When using these assets as part of a Sensu Go resource (check, mutator or handler), make sure you include the corresponding Sensu ruby runtime asset in the list of assets needed by the resource. The current ruby-runtime assets can be found [here](https://bonsai.sensu.io/assets/sensu/sensu-ruby-runtime) in the [Bonsai Asset Index](bonsai.sensu.io)
25
+
26
+ #### Files
15
27
  * bin/check-http-json.rb
16
28
  * bin/check-http.rb
17
29
  * bin/check-https-cert.rb
18
30
  * bin/check-last-modified.rb
19
31
  * bin/metrics-curl.rb
32
+ * bin/metrics-libcurl.rb
20
33
  * bin/metrics-http-json.rb
21
34
  * bin/metrics-http-json-deep.rb
22
35
  * bin/check-head-redirect.rb
23
36
  * bin/check-http-cors.rb
24
37
 
25
- ## Usage
38
+ ## Usage examples
39
+
40
+ **check-http.rb**
41
+ ```
42
+ Usage: check-http.rb (options)
43
+ --aws-v4 Sign http request with AWS v4 signature
44
+ --aws-v4-region REGION Region to use for AWS v4 signing. Defaults to AWS_REGION or AWS_DEFAULT_REGION
45
+ --aws-v4-service SERVICE Service name to use when building the v4 signature
46
+ -d, --body BODY Send a data body string with the request
47
+ -C, --cacert FILE A CA Cert to use
48
+ -c, --cert FILE Cert to use
49
+ --dns-timeout SECS Number of seconds to allow for DNS resolution. Accepts decimal number.
50
+ -e, --expiry EXPIRY Warn EXPIRE days before cert expires
51
+ -H, --header HEADER Send one or more comma-separated headers with the request
52
+ -h, --hostname HOSTNAME A HOSTNAME to connect to
53
+ -k Enabling insecure connections
54
+ -m, --method GET|HEAD|POST|PUT Specify a GET, HEAD, POST, or PUT operation; defaults to GET (included in ['GET', 'HEAD', 'POST', 'PUT'])
55
+ -g, --min-bytes BYTES Check the response contains at least BYTES bytes
56
+ -n, --negquery PAT Query for a specific pattern that must be absent
57
+ --noproxy Do not use proxy server even from environment http_proxy setting
58
+ --open-timeout SECS Number of seconds to wait for the connection to open
59
+ -a, --password PASS A password to use for the username
60
+ -q, --query PAT Query for a specific pattern that must exist
61
+ -P, --port PORT Select another port
62
+ --proxy-url PROXY_URL Use a proxy server to connect
63
+ --read-timeout SECS Number of seconds to wait for one block to be read
64
+ -r Check if a redirect is ok
65
+ -R, --redirect-to URL Redirect to another page
66
+ -p, --request-uri PATH Specify a uri path
67
+ -B, --require-bytes BYTES Check the response contains exactly BYTES bytes
68
+ -b, --response-bytes BYTES Print BYTES of the output
69
+ --response-code REGEX Critical if HTTP response code does not match REGEX
70
+ -S, --checksum CHECKSUM SHA-256 checksum
71
+ -s Enabling SSL connections
72
+ -t, --timeout SECS Set the total execution timeout in seconds
73
+ -x, --user-agent USER-AGENT Specify a USER-AGENT
74
+ -u, --url URL A URL to connect to
75
+ -U, --username USER A username to connect as
76
+ -w, --whole-response Print whole output when check fails
77
+
78
+ ```
79
+
80
+ **metrics-curl.rb**
81
+ ```
82
+ Usage: metrics-curl.rb (options)
83
+ -a, --curl_args "CURL ARGS" Additional arguments to pass to curl
84
+ -s, --scheme SCHEME Metric naming scheme, text to prepend to metric (required)
85
+ -u, --url URL valid cUrl url to connect
86
+
87
+ ```
88
+
89
+ ### Configuration
90
+ #### Sensu Go
91
+ ##### Asset registration
92
+
93
+ Assets are the best way to make use of this plugin. If you're not using an asset, please consider doing so! If you're using sensuctl 5.13 or later, you can use the following command to add the asset:
94
+
95
+ `sensuctl asset add sensu-plugins/sensu-plugins-http`
96
+
97
+ If you're using an earlier version of sensuctl, you can download the asset definition from [this project's Bonsai Asset Index page](https://bonsai.sensu.io/assets/sensu-plugins/sensu-plugins-http).
98
+
99
+ ##### Asset definition
100
+
101
+ ```yaml
102
+ ---
103
+ type: Asset
104
+ api_version: core/v2
105
+ metadata:
106
+ name: sensu-plugins-http
107
+ spec:
108
+ url: https://assets.bonsai.sensu.io/30d8361243af8c7806e2d6db4a6dc576dab02966/sensu-plugins-http_5.1.1_centos_linux_amd64.tar.gz
109
+ sha512: 642643d00c6af177d2e159b9152c0a513c1b193622c1e6dc2735b7518ce57a1522186dcbf62d6cfbdf1c79c45215f1142d362276815c31aa6071d49735bf1d35
110
+ ```
111
+
112
+ ##### Check definition
113
+
114
+ ```yaml
115
+ ---
116
+ type: CheckConfig
117
+ spec:
118
+ command: "metrics-curl.rb -u https://google.com"
119
+ handlers: []
120
+ high_flap_threshold: 0
121
+ interval: 10
122
+ low_flap_threshold: 0
123
+ publish: true
124
+ runtime_assets:
125
+ - sensu-plugins-http
126
+ - sensu-ruby-runtime
127
+ subscriptions:
128
+ - linux
129
+ output_metric_format: graphite_plaintext
130
+ output_metric_handlers:
131
+ - influx-db
132
+ ```
133
+ #### Sensu Core
134
+ ##### Check definition
135
+ ```json
136
+ {
137
+ "checks": {
138
+ "check-http": {
139
+ "command": "check-http.rb -u https://google.com",
140
+ "subscribers": [
141
+ "webservers"
142
+ ],
143
+ "interval": 60
144
+ }
145
+ }
146
+ }
147
+ ```
148
+
149
+ ### Additional information
26
150
 
27
151
  `check-head-redirect.rb` and `check-last-modified.rb` can be used in conjunction with AWS to pull configuration from a specific bucket and file.
28
152
 
@@ -32,9 +156,52 @@ This is helpful if you do not want to configure connection information as an arg
32
156
 
33
157
  ## Installation
34
158
 
35
- [Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
159
+ ### Sensu Go
160
+
161
+ See the instructions above for [asset registration](#asset-registration)
162
+
163
+ ### Sensu Core
164
+ Install and setup plugins on [Sensu Core](https://docs.sensu.io/sensu-core/latest/installation/installing-plugins/)
36
165
 
37
166
  ## Notes
167
+ ### check-curl.rb and check-libcurl.rb
168
+ These metrics checks output equivalent metrics in graphite plaintext format.
169
+ check-curl.rb operates by calling the curl executable with arbitrary arguments
170
+ ```
171
+ metrics-curl.rb --help
172
+ Usage: metrics-curl.rb (options)
173
+ -a, --curl_args "CURL ARGS" Additional arguments to pass to curl
174
+ -s, --scheme SCHEME Metric naming scheme, text to prepend to metric (required)
175
+ -u, --url URL valid cUrl url to connect
176
+
177
+ ```
178
+
179
+ check-curllub.rb operators by calling into the libcurl library with arbitrary arguments.
180
+ ```
181
+ metrics-libcurl.rb --help
182
+ Usage: metrics-libcurl.rb (options)
183
+ -d, --debug Include debug output, should not use in production.
184
+ -H, --headers JSON HTTP Request Headers as key/value JSON string
185
+ -P, --params JSON HTTP Request Parameters as key/value JSON string
186
+ -w, --warn_redirect return warning status (1) if http response redirect status encountered (3xx)
187
+ -c, --critical_http_error return critical status (2) if http response error status encountered (>= 400)
188
+ -o, --options JSON Libcurl Options as a key/value JSON string
189
+ -s, --scheme SCHEME Metric naming scheme, text to prepend to metric
190
+ -u, --url URL valid cUrl url to connect (default: http://127.0.0.1:80/)
191
+ -h, --help Show this message
192
+ Detailed Info:
193
+ This wrapper makes use of libcurl directly instead of the curl executable by way of the Typhoeus RubyGem.
194
+ You can provide additional libcurl options via the commandline using the --options argument.
195
+
196
+ Options Examples:
197
+ Follow Redirects: --options '{"followlocation": true}'
198
+ Use Proxy: --options '{proxy: "http://proxyurl.com", proxyuserpwd: "user:password"}'
199
+ Disable TLS Verification: '{"ssl_verifypeer": false}'
200
+
201
+ References:
202
+ Typhoeus Docs: https://www.rubydoc.info/gems/typhoeus/1.3.1
203
+ Libcurl Options: https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
204
+ ```
38
205
 
39
206
  ### check-http.rb and check-https-cert.rb
40
207
  This check is not really geared to check all of the complexities of ssl which is why there is a separate repo and set of checks for that: https://github.com/sensu-plugins/sensu-plugins-ssl. If you are trying to verify cert expiration you will notice that in some cases it does not do what you always expect it to do. For example it might appear that when using using `-k` option you see different expiration times. This is due to the fact that when using `-k` it does not check expiration of all of the certs in the chain. Rather than duplicate this behavior in this check use the other repo where we handle those more complicated ssl checks better. For more information see: https://github.com/sensu-plugins/sensu-plugins-http/issues/67
@@ -37,31 +37,31 @@ require 'sensu-plugins-http'
37
37
  class CheckHeadRedirect < Sensu::Plugin::Check::CLI
38
38
  include Common
39
39
  option :aws_access_key_id,
40
- short: '-a AWS_ACCESS_KEY_ID',
41
- long: '--aws-access-key-id AWS_ACCESS_KEY_ID',
40
+ short: '-a AWS_ACCESS_KEY_ID',
41
+ long: '--aws-access-key-id AWS_ACCESS_KEY_ID',
42
42
  description: 'AWS Access Key. Either set ENV["AWS_ACCESS_KEY_ID"] or provide it as an option',
43
- default: ENV['AWS_ACCESS_KEY_ID']
43
+ default: ENV['AWS_ACCESS_KEY_ID']
44
44
 
45
45
  option :aws_secret_access_key,
46
- short: '-k AWS_SECRET_ACCESS_KEY',
47
- long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
46
+ short: '-k AWS_SECRET_ACCESS_KEY',
47
+ long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
48
48
  description: 'AWS Secret Access Key. Either set ENV["AWS_SECRET_ACCESS_KEY"] or provide it as an option',
49
- default: ENV['AWS_SECRET_ACCESS_KEY']
49
+ default: ENV['AWS_SECRET_ACCESS_KEY']
50
50
 
51
51
  option :aws_region,
52
- short: '-r AWS_REGION',
53
- long: '--aws-region REGION',
52
+ short: '-r AWS_REGION',
53
+ long: '--aws-region REGION',
54
54
  description: 'AWS Region (defaults to us-east-1)',
55
- default: 'us-east-1'
55
+ default: 'us-east-1'
56
56
 
57
57
  option :s3_config_bucket,
58
- short: '-s S3_CONFIG_BUCKET',
59
- long: '--s3-config-bucket S3_CONFIG_BUCKET',
58
+ short: '-s S3_CONFIG_BUCKET',
59
+ long: '--s3-config-bucket S3_CONFIG_BUCKET',
60
60
  description: 'S3 config bucket'
61
61
 
62
62
  option :s3_config_key,
63
- short: '-k S3_CONFIG_KEY',
64
- long: '--s3-config-key S3_CONFIG_KEY',
63
+ short: '-k S3_CONFIG_KEY',
64
+ long: '--s3-config-key S3_CONFIG_KEY',
65
65
  description: 'S3 config key'
66
66
 
67
67
  option :url,
@@ -142,9 +142,9 @@ class CheckJson < Sensu::Plugin::Check::CLI
142
142
 
143
143
  def json_valid?(str)
144
144
  ::JSON.parse(str)
145
- return true
145
+ true
146
146
  rescue ::JSON::ParserError
147
- return false
147
+ false
148
148
  end
149
149
 
150
150
  def acquire_resource
@@ -204,14 +204,17 @@ class CheckJson < Sensu::Plugin::Check::CLI
204
204
  message = "key has expected value: '#{config[:key]}' "
205
205
  if config[:value]
206
206
  raise "unexpected value for key: '#{leaf}' != '#{config[:value]}'" unless leaf.to_s == config[:value].to_s
207
+
207
208
  message += "equals '#{config[:value]}'"
208
209
  end
209
210
  if config[:valueGt]
210
211
  raise "unexpected value for key: '#{leaf}' not > '#{config[:valueGt]}'" unless leaf.to_f > config[:valueGt].to_f
212
+
211
213
  message += "greater than '#{config[:valueGt]}'"
212
214
  end
213
215
  if config[:valueLt]
214
216
  raise "unexpected value for key: '#{leaf}' not < '#{config[:valueLt]}'" unless leaf.to_f < config[:valueLt].to_f
217
+
215
218
  message += "less than '#{config[:valueLt]}'"
216
219
  end
217
220
 
data/bin/check-http.rb CHANGED
@@ -93,10 +93,10 @@ class CheckHttp < Sensu::Plugin::Check::CLI
93
93
  description: 'Specify a uri path'
94
94
 
95
95
  option :method,
96
- short: '-m GET|POST',
97
- long: '--method GET|POST|PUT',
98
- description: 'Specify a GET, POST, or PUT operation; defaults to GET',
99
- in: %w[GET POST PUT],
96
+ short: '-m GET|HEAD|POST|PUT',
97
+ long: '--method GET|HEAD|POST|PUT',
98
+ description: 'Specify a GET, HEAD, POST, or PUT operation; defaults to GET',
99
+ in: %w[GET HEAD POST PUT],
100
100
  default: 'GET'
101
101
 
102
102
  option :header,
@@ -104,6 +104,10 @@ class CheckHttp < Sensu::Plugin::Check::CLI
104
104
  long: '--header HEADER',
105
105
  description: 'Send one or more comma-separated headers with the request'
106
106
 
107
+ option :headerfile,
108
+ long: '--headerfile FILE',
109
+ description: 'Send headers with the request, read from FILE, separated by newline'
110
+
107
111
  option :body,
108
112
  short: '-d BODY',
109
113
  long: '--body BODY',
@@ -341,6 +345,8 @@ class CheckHttp < Sensu::Plugin::Check::CLI
341
345
  req = case config[:method]
342
346
  when 'GET'
343
347
  Net::HTTP::Get.new(config[:request_uri], 'User-Agent' => config[:ua])
348
+ when 'HEAD'
349
+ Net::HTTP::Head.new(config[:request_uri], 'User-Agent' => config[:ua])
344
350
  when 'POST'
345
351
  Net::HTTP::Post.new(config[:request_uri], 'User-Agent' => config[:ua])
346
352
  when 'PUT'
@@ -356,6 +362,14 @@ class CheckHttp < Sensu::Plugin::Check::CLI
356
362
  req[h.strip] = v.strip
357
363
  end
358
364
  end
365
+
366
+ if config[:headerfile]
367
+ File.readlines(config[:headerfile]).each do |line|
368
+ h, v = line.split(':', 2)
369
+ req[h.strip] = v.strip
370
+ end
371
+ end
372
+
359
373
  req.body = config[:body] if config[:body]
360
374
 
361
375
  req = apply_v4_signature(http, req, config) if config[:aws_v4]
@@ -363,7 +377,7 @@ class CheckHttp < Sensu::Plugin::Check::CLI
363
377
  res = http.request(req)
364
378
 
365
379
  body = if config[:whole_response]
366
- "\n" + res.body
380
+ "\n" + res.body.to_s
367
381
  else
368
382
  body = if config[:response_bytes] # rubocop:disable Lint/UselessAssignment
369
383
  "\n" + res.body[0..config[:response_bytes]]
@@ -419,10 +433,10 @@ class CheckHttp < Sensu::Plugin::Check::CLI
419
433
  if config[:redirectok] || config[:redirectto]
420
434
  if config[:redirectok]
421
435
  # #YELLOW
422
- ok("#{res.code}, #{size} bytes" + body) unless config[:response_code] # rubocop:disable BlockNesting
436
+ ok("#{res.code}, #{size} bytes" + body) unless config[:response_code] # rubocop:disable Metrics/BlockNesting
423
437
  elsif config[:redirectto]
424
438
  # #YELLOW
425
- if config[:redirectto] == res['Location'] # rubocop:disable BlockNesting
439
+ if config[:redirectto] == res['Location'] # rubocop:disable Metrics/BlockNesting
426
440
  ok "#{res.code} found redirect to #{res['Location']}" + body
427
441
  else
428
442
  critical "Expected redirect to #{config[:redirectto]} instead redirected to #{res['Location']}" + body
@@ -38,31 +38,31 @@ require 'sensu-plugins-http'
38
38
  class CheckLastModified < Sensu::Plugin::Check::CLI
39
39
  include Common
40
40
  option :aws_access_key_id,
41
- short: '-a AWS_ACCESS_KEY_ID',
42
- long: '--aws-access-key-id AWS_ACCESS_KEY_ID',
41
+ short: '-a AWS_ACCESS_KEY_ID',
42
+ long: '--aws-access-key-id AWS_ACCESS_KEY_ID',
43
43
  description: 'AWS Access Key. Either set ENV["AWS_ACCESS_KEY_ID"] or provide it as an option',
44
- default: ENV['AWS_ACCESS_KEY_ID']
44
+ default: ENV['AWS_ACCESS_KEY_ID']
45
45
 
46
46
  option :aws_secret_access_key,
47
- short: '-k AWS_SECRET_KEY',
48
- long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
47
+ short: '-k AWS_SECRET_KEY',
48
+ long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
49
49
  description: 'AWS Secret Access Key. Either set ENV["AWS_SECRET_ACCESS_KEY"] or provide it as an option',
50
- default: ENV['AWS_SECRET_ACCESS_KEY']
50
+ default: ENV['AWS_SECRET_ACCESS_KEY']
51
51
 
52
52
  option :aws_region,
53
- short: '-r AWS_REGION',
54
- long: '--aws-region REGION',
53
+ short: '-r AWS_REGION',
54
+ long: '--aws-region REGION',
55
55
  description: 'AWS Region (defaults to us-east-1).',
56
- default: 'us-east-1'
56
+ default: 'us-east-1'
57
57
 
58
58
  option :s3_config_bucket,
59
- short: '-s S3_CONFIG_BUCKET',
60
- long: '--s3-config-bucket S3_CONFIG_BUCKET',
59
+ short: '-s S3_CONFIG_BUCKET',
60
+ long: '--s3-config-bucket S3_CONFIG_BUCKET',
61
61
  description: 'S3 config bucket'
62
62
 
63
63
  option :s3_config_key,
64
- short: '-k S3_CONFIG_KEY',
65
- long: '--s3-config-key S3_CONFIG_KEY',
64
+ short: '-k S3_CONFIG_KEY',
65
+ long: '--s3-config-key S3_CONFIG_KEY',
66
66
  description: 'S3 config key'
67
67
 
68
68
  option :url,
data/bin/metrics-curl.rb CHANGED
@@ -29,7 +29,6 @@
29
29
  # Released under the same terms as Sensu (the MIT license); see LICENSE
30
30
  # for details.
31
31
  #
32
-
33
32
  require 'socket'
34
33
  require 'English'
35
34
  require 'sensu-plugin/metric/cli'
@@ -58,10 +57,15 @@ class CurlMetrics < Sensu::Plugin::Metric::CLI::Graphite
58
57
  default: "#{Socket.gethostname}.curl_timings"
59
58
 
60
59
  def run
60
+ `type -t "curl" > /dev/null 2>&1`
61
+ unless $CHILD_STATUS == 0
62
+ critical 'CRITICAL: curl executable not found in PATH on this system.'\
63
+ ' If curl cannot be installed, consider using metrics_libcurl.rb instead.'
64
+ end
65
+
61
66
  cmd = "LC_NUMERIC=C curl --silent --output /dev/null #{config[:curl_args]} "
62
67
  cmd += '-w "%{time_total},%{time_namelookup},%{time_connect},%{time_pretransfer},%{time_redirect},%{time_starttransfer},%{http_code}" '
63
68
  cmd += config[:url]
64
-
65
69
  output = `#{cmd}`
66
70
 
67
71
  (time_total, time_namelookup, time_connect, time_pretransfer, time_redirect, time_starttransfer, http_code) = output.split(',')
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
4
+ #
5
+ # metrics-libcurl
6
+ #
7
+ # DESCRIPTION:
8
+ # Simple wrapper around libcurl for getting timing stats from the various phases
9
+ # of connecting to an HTTP/HTTPS server.
10
+ #
11
+ # OUTPUT:
12
+ # metric data
13
+ #
14
+ # PLATFORMS:
15
+ # Linux
16
+ #
17
+ # DEPENDENCIES:
18
+ # gem: sensu-plugin
19
+ # gem: typhoeus
20
+ #
21
+ # USAGE:
22
+ # #YELLOW
23
+ #
24
+ # NOTES:
25
+ # Based on: metrics-curl.rb
26
+ # by Joe Miller.
27
+ #
28
+ # LICENSE:
29
+ # Copyright 2019 Jef Spaleta
30
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
31
+ # for details.
32
+ #
33
+
34
+ require 'socket'
35
+ require 'English'
36
+ require 'sensu-plugin/metric/cli'
37
+ require 'typhoeus'
38
+ require 'json'
39
+
40
+ #
41
+ # Libcurl Metrics
42
+ #
43
+ class LibcurlMetrics < Sensu::Plugin::Metric::CLI::Graphite
44
+ option :url,
45
+ short: '-u URL',
46
+ long: '--url URL',
47
+ description: 'valid cUrl url to connect (default: http://127.0.0.1:80/)',
48
+ default: 'http://127.0.0.1:80/'
49
+
50
+ option :scheme,
51
+ description: 'Metric naming scheme, text to prepend to metric',
52
+ short: '-s SCHEME',
53
+ long: '--scheme SCHEME',
54
+ default: "#{Socket.gethostname}.curl_timings"
55
+ option :debug,
56
+ description: 'Include debug output, should not use in production.',
57
+ short: '-d',
58
+ long: '--debug',
59
+ default: false
60
+ option :libcurl_options,
61
+ description: 'Libcurl Options as a key/value JSON string',
62
+ short: '-o JSON',
63
+ long: '--options JSON',
64
+ default: '{}'
65
+ option :http_headers,
66
+ description: 'HTTP Request Headers as key/value JSON string',
67
+ short: '-H JSON',
68
+ long: '--headers JSON',
69
+ default: '{}'
70
+ option :http_params,
71
+ description: 'HTTP Request Parameters as key/value JSON string',
72
+ short: '-P JSON',
73
+ long: '--params JSON',
74
+ default: '{}'
75
+ option :http_response_error,
76
+ description: 'return critical status (2) if http response error status encountered (>= 400)',
77
+ short: '-c',
78
+ long: '--critical_http_error',
79
+ default: false
80
+ option :http_redirect_warning,
81
+ description: 'return warning status (1) if http response redirect status encountered (3xx)',
82
+ short: '-w',
83
+ long: '--warn_redirect',
84
+ default: false
85
+ option :help,
86
+ short: '-h',
87
+ long: '--help',
88
+ description: 'Show this message',
89
+ on: :tail,
90
+ boolean: true,
91
+ show_options: true
92
+
93
+ def usage_details
94
+ <<~USAGE
95
+ Detailed Info:
96
+ This wrapper makes use of libcurl directly instead of the curl executable by way of the Typhoeus RubyGem.
97
+ You can provide additional libcurl options via the commandline using the --options argument.
98
+
99
+ Options Examples:
100
+ Follow Redirects: --options '{\"followlocation\": true}'
101
+ Use Proxy: --options '{proxy: \"http://proxyurl.com\", proxyuserpwd: \"user:password\"}'
102
+ Disable TLS Verification: '{\"ssl_verifypeer\": false}'
103
+
104
+ References:
105
+ Typhoeus Docs: https://www.rubydoc.info/gems/typhoeus/1.3.1
106
+ Libcurl Options: https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
107
+ USAGE
108
+ end
109
+
110
+ def run
111
+ if config[:help]
112
+ puts usage_details
113
+ ok
114
+ end
115
+
116
+ puts "[DEBUG] args config: #{config}" if config[:debug]
117
+ begin
118
+ headers = ::JSON.parse(config[:http_headers])
119
+ rescue ::JSON::ParserError
120
+ critical "Error parsing http_headers JSON\n"
121
+ end
122
+ begin
123
+ params = ::JSON.parse(config[:http_params])
124
+ rescue ::JSON::ParserError
125
+ critical "Error parsing http_params JSON\n"
126
+ end
127
+ begin
128
+ hash = ::JSON.parse(config[:libcurl_options])
129
+ rescue ::JSON::ParserError
130
+ critical "Error parsing libcurl_options JSON\n"
131
+ end
132
+
133
+ begin
134
+ opts = Hash[hash.map { |k, v| [k.to_sym, v] }]
135
+ opts[:headers] = headers unless headers.empty?
136
+ opts[:params] = params unless params.empty?
137
+ request = Typhoeus::Request.new(config[:url], opts)
138
+ if config[:debug]
139
+ puts "[DEBUG] Request Options: #{request.options}"
140
+ puts "[DEBUG] Request Base Url: #{request.base_url}"
141
+ puts "[DEBUG] Request Full Url: #{request.url}"
142
+ end
143
+ response = request.run
144
+ Typhoeus.get(config[:url], followlocation: true)
145
+ if config[:debug]
146
+ puts "[DEBUG] Response HTTP Code: #{response.response_code}"
147
+ puts "[DEBUG] Response Return Code: #{response.return_code}"
148
+ end
149
+ rescue TyphoeusError
150
+ critical "Something went wrong\n Request Options: #{request.options}\n Request Base Url: #{request.base_url}\n Request Full Url: #{request.url}"
151
+ end
152
+ output "#{config[:scheme]}.time_total", response.total_time
153
+ output "#{config[:scheme]}.time_namelookup", response.namelookup_time
154
+ output "#{config[:scheme]}.time_connect", response.connect_time
155
+ output "#{config[:scheme]}.time_pretransfer", response.pretransfer_time
156
+ output "#{config[:scheme]}.time_redirect", response.redirect_time
157
+ output "#{config[:scheme]}.time_starttransfer", response.starttransfer_time
158
+ output "#{config[:scheme]}.http_code", response.response_code
159
+ if response.response_code == 0
160
+ critical
161
+ end
162
+
163
+ critical if config[:http_response_error] && response.response_code >= 400
164
+ warning if config[:http_redirect_warning] && response.response_code.between?(300, 399)
165
+ ok
166
+ end
167
+ end
@@ -2,9 +2,9 @@
2
2
 
3
3
  module SensuPluginsHttp
4
4
  module Version
5
- MAJOR = 5
6
- MINOR = 1
7
- PATCH = 1
5
+ MAJOR = 6
6
+ MINOR = 0
7
+ PATCH = 0
8
8
 
9
9
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
10
10
  end
metadata CHANGED
@@ -1,85 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.1
4
+ version: 6.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: 2019-06-21 00:00:00.000000000 Z
11
+ date: 2020-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sensu-plugin
14
+ name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '2.3'
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
- version: '4.0'
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: aws-sdk
28
+ name: oj
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.3'
33
+ version: '3.10'
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
- version: '2.3'
40
+ version: '3.10'
41
41
  - !ruby/object:Gem::Dependency
42
- name: oj
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.18'
47
+ version: '2.1'
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.18'
54
+ version: '2.1'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rest-client
56
+ name: sensu-plugin
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: typhoeus
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 2.0.2
75
+ version: 1.3.1
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 2.0.2
82
+ version: 1.3.1
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '1.7'
89
+ version: '2.1'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '1.7'
96
+ version: '2.1'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: github-markup
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -98,16 +112,16 @@ dependencies:
98
112
  name: json
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - "<"
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 2.0.0
117
+ version: '2.3'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - "<"
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: 2.0.0
124
+ version: '2.3'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: kitchen-docker
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +184,28 @@ dependencies:
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '12.3'
187
+ version: '13.0'
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '12.3'
194
+ version: '13.0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rdoc
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
181
209
  - !ruby/object:Gem::Dependency
182
210
  name: redcarpet
183
211
  requirement: !ruby/object:Gem::Requirement
@@ -212,28 +240,28 @@ dependencies:
212
240
  requirements:
213
241
  - - "~>"
214
242
  - !ruby/object:Gem::Version
215
- version: 0.51.0
243
+ version: 0.79.0
216
244
  type: :development
217
245
  prerelease: false
218
246
  version_requirements: !ruby/object:Gem::Requirement
219
247
  requirements:
220
248
  - - "~>"
221
249
  - !ruby/object:Gem::Version
222
- version: 0.51.0
250
+ version: 0.79.0
223
251
  - !ruby/object:Gem::Dependency
224
252
  name: test-kitchen
225
253
  requirement: !ruby/object:Gem::Requirement
226
254
  requirements:
227
255
  - - "~>"
228
256
  - !ruby/object:Gem::Version
229
- version: 1.23.5
257
+ version: 1.25.0
230
258
  type: :development
231
259
  prerelease: false
232
260
  version_requirements: !ruby/object:Gem::Requirement
233
261
  requirements:
234
262
  - - "~>"
235
263
  - !ruby/object:Gem::Version
236
- version: 1.23.5
264
+ version: 1.25.0
237
265
  - !ruby/object:Gem::Dependency
238
266
  name: yard
239
267
  requirement: !ruby/object:Gem::Requirement
@@ -255,15 +283,16 @@ description: |-
255
283
  SSL expiry, and metrics via `curl`.
256
284
  email: "<sensu-users@googlegroups.com>"
257
285
  executables:
286
+ - check-http-json.rb
287
+ - check-http-cors.rb
258
288
  - check-head-redirect.rb
259
- - metrics-http-json.rb
289
+ - check-https-cert.rb
260
290
  - check-last-modified.rb
261
291
  - check-http.rb
262
- - metrics-curl.rb
263
- - check-http-cors.rb
292
+ - metrics-http-json.rb
264
293
  - metrics-http-json-deep.rb
265
- - check-https-cert.rb
266
- - check-http-json.rb
294
+ - metrics-curl.rb
295
+ - metrics-libcurl.rb
267
296
  extensions: []
268
297
  extra_rdoc_files: []
269
298
  files:
@@ -279,6 +308,7 @@ files:
279
308
  - bin/metrics-curl.rb
280
309
  - bin/metrics-http-json-deep.rb
281
310
  - bin/metrics-http-json.rb
311
+ - bin/metrics-libcurl.rb
282
312
  - lib/sensu-plugins-http.rb
283
313
  - lib/sensu-plugins-http/aws-v4.rb
284
314
  - lib/sensu-plugins-http/common.rb
@@ -308,7 +338,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
338
  - !ruby/object:Gem::Version
309
339
  version: '0'
310
340
  requirements: []
311
- rubygems_version: 3.0.4
341
+ rubyforge_project:
342
+ rubygems_version: 2.7.7
312
343
  signing_key:
313
344
  specification_version: 4
314
345
  summary: Sensu plugins for various http monitors and metrics