sensu-plugins-http-boutetnico 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c22c8bb8150663fdf2082b42d8d7b8d5b61ede28
4
+ data.tar.gz: 1b2f55ad0743f8d0465f88733960d9a42f9e14d3
5
+ SHA512:
6
+ metadata.gz: 3bf4f6d7289710cec3a60bd7af3871677371f6a80f478e2c5ddebeb191d7ee2ffa4d49063048531a5f732a52506b33ad729dd69bbe39f0f82ab03e86cc41f950
7
+ data.tar.gz: 4ce3378f60ef16b33191ec6ec0f76a056cd4538712259a626e923483034252c2df1903f8cb86cd4b52e6eff9926d2ef9fce5dd5f79145ef35838f63ccf2182b4
@@ -0,0 +1 @@
1
+ Can be found at [https://github.com/boutetnico/sensu-plugins-http/releases](https://github.com/boutetnico/sensu-plugins-http/releases).
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Sensu-Plugins
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,211 @@
1
+ ## Sensu-Plugins-http
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-http-boutetnico.svg)](https://badge.fury.io/rb/sensu-plugins-http-boutetnico.svg)
4
+ [![Sensu Bonsai Asset](https://img.shields.io/badge/Bonsai-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/boutetnico/sensu-plugins-http)
5
+
6
+ ## This is an unofficial fork
7
+
8
+ This fork is automatically tested, built and published to [RubyGems](https://rubygems.org/gems/sensu-plugins-http-boutetnico/) and [Bonsai](https://bonsai.sensu.io/assets/boutetnico/sensu-plugins-http).
9
+
10
+ ## Sensu HTTP Plugin
11
+
12
+ - [Overview](#overview)
13
+ - [Usage examples](#usage-examples)
14
+ - [Configuration](#configuration)
15
+ - [Sensu Go](#sensu-go)
16
+ - [Asset definition](#asset-definition)
17
+ - [Check definition](#check-definition)
18
+ - [Sensu Core](#sensu-core)
19
+ - [Check definition](#check-definition)
20
+ - [Functionality](#functionality)
21
+ - [Additional information](#additional-information)
22
+ - [Installation](#installation)
23
+
24
+ ### Overview
25
+
26
+ 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`.
27
+
28
+ 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)
29
+
30
+ #### Files
31
+ * bin/check-head-redirect.rb
32
+ * bin/check-http-cors.rb
33
+ * bin/check-http-json.rb
34
+ * bin/check-http.rb
35
+ * bin/check-https-cert.rb
36
+ * bin/check-last-modified.rb
37
+ * bin/metrics-curl.rb
38
+ * bin/metrics-http-json-deep.rb
39
+ * bin/metrics-http-json.rb
40
+ * bin/metrics-libcurl.rb
41
+
42
+ ## Usage examples
43
+
44
+ **check-http.rb**
45
+ ```
46
+ Usage: check-http.rb (options)
47
+ --aws-v4 Sign http request with AWS v4 signature
48
+ --aws-v4-region REGION Region to use for AWS v4 signing. Defaults to AWS_REGION or AWS_DEFAULT_REGION
49
+ --aws-v4-service SERVICE Service name to use when building the v4 signature
50
+ -d, --body BODY Send a data body string with the request
51
+ -C, --cacert FILE A CA Cert to use
52
+ -c, --cert FILE Cert to use
53
+ --dns-timeout SECS Number of seconds to allow for DNS resolution. Accepts decimal number.
54
+ -e, --expiry EXPIRY Warn EXPIRE days before cert expires
55
+ -H, --header HEADER Send one or more comma-separated headers with the request
56
+ -h, --hostname HOSTNAME A HOSTNAME to connect to
57
+ -k Enabling insecure connections
58
+ -m, --method GET|HEAD|POST|PUT Specify a GET, HEAD, POST, or PUT operation; defaults to GET (included in ['GET', 'HEAD', 'POST', 'PUT'])
59
+ -g, --min-bytes BYTES Check the response contains at least BYTES bytes
60
+ -n, --negquery PAT Query for a specific pattern that must be absent
61
+ --noproxy Do not use proxy server even from environment http_proxy setting
62
+ --open-timeout SECS Number of seconds to wait for the connection to open
63
+ -a, --password PASS A password to use for the username
64
+ -q, --query PAT Query for a specific pattern that must exist
65
+ -P, --port PORT Select another port
66
+ --proxy-url PROXY_URL Use a proxy server to connect
67
+ --read-timeout SECS Number of seconds to wait for one block to be read
68
+ -r Check if a redirect is ok
69
+ -R, --redirect-to URL Redirect to another page
70
+ -p, --request-uri PATH Specify a uri path
71
+ -B, --require-bytes BYTES Check the response contains exactly BYTES bytes
72
+ -b, --response-bytes BYTES Print BYTES of the output
73
+ --response-code REGEX Critical if HTTP response code does not match REGEX
74
+ -S, --checksum CHECKSUM SHA-256 checksum
75
+ -s Enabling SSL connections
76
+ -t, --timeout SECS Set the total execution timeout in seconds
77
+ -x, --user-agent USER-AGENT Specify a USER-AGENT
78
+ -u, --url URL A URL to connect to
79
+ -U, --username USER A username to connect as
80
+ -w, --whole-response Print whole output when check fails
81
+
82
+ ```
83
+
84
+ **metrics-curl.rb**
85
+ ```
86
+ Usage: metrics-curl.rb (options)
87
+ -a, --curl_args "CURL ARGS" Additional arguments to pass to curl
88
+ -s, --scheme SCHEME Metric naming scheme, text to prepend to metric (required)
89
+ -u, --url URL valid cUrl url to connect
90
+
91
+ ```
92
+
93
+ ### Configuration
94
+ #### Sensu Go
95
+ ##### Asset registration
96
+
97
+ 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:
98
+
99
+ `sensuctl asset add sensu-plugins/sensu-plugins-http`
100
+
101
+ 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).
102
+
103
+ ##### Asset definition
104
+
105
+ ```yaml
106
+ ---
107
+ type: Asset
108
+ api_version: core/v2
109
+ metadata:
110
+ name: sensu-plugins-http
111
+ spec:
112
+ url: https://assets.bonsai.sensu.io/30d8361243af8c7806e2d6db4a6dc576dab02966/sensu-plugins-http_5.1.1_centos_linux_amd64.tar.gz
113
+ sha512: 642643d00c6af177d2e159b9152c0a513c1b193622c1e6dc2735b7518ce57a1522186dcbf62d6cfbdf1c79c45215f1142d362276815c31aa6071d49735bf1d35
114
+ ```
115
+
116
+ ##### Check definition
117
+
118
+ ```yaml
119
+ ---
120
+ type: CheckConfig
121
+ spec:
122
+ command: "metrics-curl.rb -u https://google.com"
123
+ handlers: []
124
+ high_flap_threshold: 0
125
+ interval: 10
126
+ low_flap_threshold: 0
127
+ publish: true
128
+ runtime_assets:
129
+ - sensu-plugins-http
130
+ - sensu-ruby-runtime
131
+ subscriptions:
132
+ - linux
133
+ output_metric_format: graphite_plaintext
134
+ output_metric_handlers:
135
+ - influx-db
136
+ ```
137
+ #### Sensu Core
138
+ ##### Check definition
139
+ ```json
140
+ {
141
+ "checks": {
142
+ "check-http": {
143
+ "command": "check-http.rb -u https://google.com",
144
+ "subscribers": [
145
+ "webservers"
146
+ ],
147
+ "interval": 60
148
+ }
149
+ }
150
+ }
151
+ ```
152
+
153
+ ### Additional information
154
+
155
+ `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.
156
+
157
+ This is helpful if you do not want to configure connection information as an argument to the sensu checks. If a bucket and key are specified that the environment the sensu check executes in has access to, or you provide an AWS key and token, the checks will pull the specified JSON file from S3 and merge the JSON config in to the current check configuration.
158
+
159
+ `check-https-cert.rb` can be used to test for valid and successfully expired certs, amongst other things.
160
+
161
+ ## Installation
162
+
163
+ ### Sensu Go
164
+
165
+ See the instructions above for [asset registration](#asset-registration)
166
+
167
+ ### Sensu Core
168
+ Install and setup plugins on [Sensu Core](https://docs.sensu.io/sensu-core/latest/installation/installing-plugins/)
169
+
170
+ ## Notes
171
+ ### check-curl.rb and check-libcurl.rb
172
+ These metrics checks output equivalent metrics in graphite plaintext format.
173
+ check-curl.rb operates by calling the curl executable with arbitrary arguments
174
+ ```
175
+ metrics-curl.rb --help
176
+ Usage: metrics-curl.rb (options)
177
+ -a, --curl_args "CURL ARGS" Additional arguments to pass to curl
178
+ -s, --scheme SCHEME Metric naming scheme, text to prepend to metric (required)
179
+ -u, --url URL valid cUrl url to connect
180
+
181
+ ```
182
+
183
+ check-curllub.rb operators by calling into the libcurl library with arbitrary arguments.
184
+ ```
185
+ metrics-libcurl.rb --help
186
+ Usage: metrics-libcurl.rb (options)
187
+ -d, --debug Include debug output, should not use in production.
188
+ -H, --headers JSON HTTP Request Headers as key/value JSON string
189
+ -P, --params JSON HTTP Request Parameters as key/value JSON string
190
+ -w, --warn_redirect return warning status (1) if http response redirect status encountered (3xx)
191
+ -c, --critical_http_error return critical status (2) if http response error status encountered (>= 400)
192
+ -o, --options JSON Libcurl Options as a key/value JSON string
193
+ -s, --scheme SCHEME Metric naming scheme, text to prepend to metric
194
+ -u, --url URL valid cUrl url to connect (default: http://127.0.0.1:80/)
195
+ -h, --help Show this message
196
+ Detailed Info:
197
+ This wrapper makes use of libcurl directly instead of the curl executable by way of the Typhoeus RubyGem.
198
+ You can provide additional libcurl options via the commandline using the --options argument.
199
+
200
+ Options Examples:
201
+ Follow Redirects: --options '{"followlocation": true}'
202
+ Use Proxy: --options '{proxy: "http://proxyurl.com", proxyuserpwd: "user:password"}'
203
+ Disable TLS Verification: '{"ssl_verifypeer": false}'
204
+
205
+ References:
206
+ Typhoeus Docs: https://www.rubydoc.info/gems/typhoeus/1.3.1
207
+ Libcurl Options: https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
208
+ ```
209
+
210
+ ### check-http.rb and check-https-cert.rb
211
+ 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
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
4
+ #
5
+ # check-head-redirect
6
+ #
7
+ # DESCRIPTION:
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Leon Gibat <brendan.gibat@gmail.com>
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
25
+ # for details.
26
+ #
27
+ require 'sensu-plugin/check/cli'
28
+ require 'net/https'
29
+ require 'time'
30
+ require 'aws-sdk'
31
+ require 'json'
32
+ require 'sensu-plugins-http'
33
+
34
+ #
35
+ # Checks that redirection links can be followed in a set number of requests.
36
+ #
37
+ class CheckHeadRedirect < Sensu::Plugin::Check::CLI
38
+ include Common
39
+ option :aws_access_key_id,
40
+ short: '-a AWS_ACCESS_KEY_ID',
41
+ long: '--aws-access-key-id AWS_ACCESS_KEY_ID',
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']
44
+
45
+ option :aws_secret_access_key,
46
+ short: '-k AWS_SECRET_ACCESS_KEY',
47
+ long: '--aws-secret-access-key AWS_SECRET_ACCESS_KEY',
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']
50
+
51
+ option :aws_region,
52
+ short: '-r AWS_REGION',
53
+ long: '--aws-region REGION',
54
+ description: 'AWS Region (defaults to us-east-1)',
55
+ default: 'us-east-1'
56
+
57
+ option :s3_config_bucket,
58
+ short: '-s S3_CONFIG_BUCKET',
59
+ long: '--s3-config-bucket S3_CONFIG_BUCKET',
60
+ description: 'S3 config bucket'
61
+
62
+ option :s3_config_key,
63
+ short: '-k S3_CONFIG_KEY',
64
+ long: '--s3-config-key S3_CONFIG_KEY',
65
+ description: 'S3 config key'
66
+
67
+ option :url,
68
+ short: '-u URL',
69
+ long: '--url URL',
70
+ description: 'The URL of the file to be checked'
71
+
72
+ option :user,
73
+ short: '-U USER',
74
+ long: '--username USER',
75
+ description: 'A username to connect as'
76
+
77
+ option :password,
78
+ short: '-a PASS',
79
+ long: '--password PASS',
80
+ description: 'A password to use for the username'
81
+
82
+ option :follow_redirects,
83
+ short: '-R FOLLOW_REDIRECTS',
84
+ long: '--redirect FOLLOW_REDIRECTS',
85
+ proc: proc(&:to_i),
86
+ default: 0,
87
+ description: 'Follow first <N> redirects'
88
+
89
+ option :follow_redirects_with_get,
90
+ short: '-g GET_REDIRECTS',
91
+ long: '--get-redirects GET_REDIRECTS',
92
+ proc: proc(&:to_i),
93
+ default: 0,
94
+ description: 'Follow first <N> redirects with GET requests'
95
+
96
+ option :auth_first_only,
97
+ short: '-A',
98
+ long: '--auth-first-only',
99
+ default: true,
100
+ description: 'Use basic auth on first request only'
101
+
102
+ def follow_uri(uri, total_redirects, get_redirects, auth_count)
103
+ location = URI(uri)
104
+ http = Net::HTTP.new(location.host, location.port)
105
+
106
+ if location.port == 443
107
+ http.use_ssl = true
108
+ end
109
+
110
+ request = if get_redirects > 0
111
+ Net::HTTP::Get.new(location.request_uri)
112
+ else
113
+ Net::HTTP::Head.new(location.request_uri)
114
+ end
115
+
116
+ if auth_count > 0 && config[:user] && config[:password] && total_redirects == config[:follow_redirects]
117
+ http.use_ssl = true
118
+ request.basic_auth(config[:user], config[:password])
119
+ auth_count -= 1
120
+ end
121
+
122
+ response = http.request(request)
123
+ if total_redirects > 0
124
+ case response
125
+ when Net::HTTPSuccess then ok
126
+ when Net::HTTPRedirection then follow_uri(response['location'], total_redirects - 1, get_redirects - 1, auth_count)
127
+ else
128
+ critical 'Http Error'
129
+ end
130
+ else
131
+ case response
132
+ when Net::HTTPSuccess then ok
133
+ else
134
+ critical 'Http Error'
135
+ end
136
+ end
137
+ end
138
+
139
+ def run
140
+ merge_s3_config
141
+
142
+ url = config[:url]
143
+
144
+ # Validate arguments
145
+ unless url
146
+ unknown 'No URL specified'
147
+ end
148
+
149
+ follow_uri(url, config[:follow_redirects], config[:follow_redirects_with_get], config[:auth_first_only] ? 1 : config[:follow_redirects])
150
+ end
151
+ end
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: false
3
+
4
+ #
5
+ # check-http-cors
6
+ #
7
+ # DESCRIPTION:
8
+ # Takes either a URL or a combination of host/path/query/port/ssl, and checks
9
+ # for valid JSON output in the response. Can also optionally validate simple
10
+ # string key/value pairs.
11
+ #
12
+ # OUTPUT:
13
+ # plain text
14
+ #
15
+ # PLATFORMS:
16
+ # Linux
17
+ #
18
+ # DEPENDENCIES:
19
+ # gem: sensu-plugin
20
+ # gem: json
21
+ # gem: net/http
22
+ #
23
+ # USAGE:
24
+ # #YELLOW
25
+ #
26
+ # EXAMPLE:
27
+ # # simple key access
28
+ # $ ruby plugins/http/check-http-json.rb -u https://example.com/cors_resource -O "Origin:http://dummy"
29
+ #
30
+ # NOTES:
31
+ # Based on Check HTTP by Sonian Inc.
32
+ #
33
+ # LICENSE:
34
+ # Copyright 2015 Alexander Paz <alexjpaz@gmail.com>
35
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
36
+ # for details.
37
+ #
38
+
39
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
40
+ require 'sensu-plugin/check/cli'
41
+ require 'json'
42
+ require 'net/http'
43
+ require 'net/https'
44
+
45
+ class CheckCORS < Sensu::Plugin::Check::CLI
46
+ option :url, short: '-u URL'
47
+ option :host, short: '-h HOST'
48
+ option :path, short: '-p PATH'
49
+ option :query, short: '-q QUERY'
50
+ option :port, short: '-P PORT', proc: proc(&:to_i)
51
+ option :header, short: '-H HEADER', long: '--header HEADER'
52
+ option :ssl, short: '-s', boolean: true, default: false
53
+ option :insecure, short: '-k', boolean: true, default: false
54
+ option :user, short: '-U', long: '--username USER'
55
+ option :password, short: '-a', long: '--password PASS'
56
+ option :cert, short: '-c FILE'
57
+ option :cacert, short: '-C FILE'
58
+ option :timeout, short: '-t SECS', proc: proc(&:to_i), default: 15
59
+ option :key, short: '-K KEY', long: '--key KEY'
60
+ option :value, short: '-v VALUE', long: '--value VALUE'
61
+
62
+ def run
63
+ if config[:url]
64
+ uri = URI.parse(config[:url])
65
+ config[:host] = uri.host
66
+ config[:path] = uri.path
67
+ config[:query] = uri.query
68
+ config[:port] = uri.port
69
+ config[:ssl] = uri.scheme == 'https'
70
+ else
71
+ # #YELLOW
72
+ unless config[:host] && config[:path]
73
+ unknown 'No URL specified'
74
+ end
75
+ config[:port] ||= config[:ssl] ? 443 : 80
76
+ end
77
+
78
+ begin
79
+ timeout(config[:timeout]) do
80
+ acquire_resource
81
+ end
82
+ rescue Timeout::Error
83
+ critical 'Connection timed out'
84
+ rescue StandardError => e
85
+ critical "Connection error: #{e.message}"
86
+ end
87
+ end
88
+
89
+ def cors?(res)
90
+ headers = {}
91
+
92
+ if config[:header]
93
+ config[:header].split(',').each do |header|
94
+ h, v = header.split(':', 2)
95
+ headers[h] = v.strip
96
+ end
97
+ end
98
+
99
+ res['Access-Control-Allow-Origin'] == headers['Origin']
100
+ end
101
+
102
+ def acquire_resource
103
+ res = request_http
104
+
105
+ case res.code
106
+ when /^2/
107
+ if cors?(res)
108
+ ok 'Request has matching CORS headers'
109
+ else
110
+ critical 'Response does not have valid CORS headers'
111
+ end
112
+ else
113
+ critical res.code
114
+ end
115
+ end
116
+
117
+ def request_http
118
+ http = Net::HTTP.new(config[:host], config[:port])
119
+
120
+ if config[:ssl]
121
+ http.use_ssl = true
122
+ if config[:cert]
123
+ cert_data = File.read(config[:cert])
124
+ http.cert = OpenSSL::X509::Certificate.new(cert_data)
125
+ http.key = OpenSSL::PKey::RSA.new(cert_data, nil)
126
+ end
127
+ http.ca_file = config[:cacert] if config[:cacert]
128
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if config[:insecure]
129
+ end
130
+
131
+ req = Net::HTTP::Get.new([config[:path], config[:query]].compact.join('?'))
132
+ unless config[:user].nil? && config[:password].nil?
133
+ req.basic_auth config[:user], config[:password]
134
+ end
135
+
136
+ if config[:header]
137
+ config[:header].split(',').each do |header|
138
+ h, v = header.split(':', 2)
139
+ req[h] = v.strip
140
+ end
141
+ end
142
+
143
+ http.request(req)
144
+ end
145
+ end