sensu-plugins-http 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: baae84cdad42522163688ef776fa9e0b42ea97a5
4
+ data.tar.gz: 0b470c1472f31a9881cdc4ad7beb174499fc3381
5
+ SHA512:
6
+ metadata.gz: 62bc0001873cf5f561af714860847a7dcba2542e5793e41811c76e26953f5322eee091c6c3ff7d6537672ae413112a564a852a0a7ab7a42de8ccacde190e2e23
7
+ data.tar.gz: 7e6f92b631a3068210757e06c17b58a25f1627fa9ef5a94763512548ee4f27bf1319a2871032904c39d24f024029f73d7ece51257092b784f9b8573fe3519b10
checksums.yaml.gz.sig ADDED
@@ -0,0 +1 @@
1
+ Z��D�54����K?�Tm$��+�bO�:���F�U|��W�\�an;1 �ΐnt���>�̎��㛒O��]Ď�~Qh��d�ʣn6M��0M��L'�Ǔ�����'ߕ����Bt����.z{H�
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ z}`��J��V[��α�J4���~���#ejj�ɦ_%ge��zY$%��ϡ�CFl��Vz�����ǣ�ؙDr*N�@�55�����y0��������*��c÷ډ����T�u� �����VO�ұ�e�s�P��}~4��ݷ��}5@i)膋�]����<U"�F�=Kl�z�o^|� ���L+6nrnj|�F7�$|^�n����O:�ts�6��F�C��P�`s�x���z������$�m� �=�
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ #Change Log
2
+ This project adheres to [Semantic Versioning](http://semver.org/).
3
+
4
+ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
+
6
+ ## Unreleased][unreleased]
7
+
8
+ ## 0.0.1 - 2015-05-21
9
+
10
+ ### Added
11
+ - initial release
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.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ ## Sensu-Plugins-http
2
+
3
+ [![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-http.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-http)
4
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-http.svg)](http://badge.fury.io/rb/sensu-plugins-http)
5
+ [![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-http/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-http)
6
+ [![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-http/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-http)
7
+ [![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-http.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-http)
8
+ [![Codeship Status for sensu-plugins/sensu-plugins-http](https://codeship.com/projects/38675d80-ccdc-0132-c33d-1edd85dc7674/status?branch=master)](https://codeship.com/projects/76165)
9
+
10
+ ## Functionality
11
+
12
+ ## Files
13
+ * bin/check-http-json.rb
14
+ * bin/check-http.rb
15
+ * bin/check-https-cert.rb
16
+ * bin/metrics-curl.rb
17
+
18
+ ## Usage
19
+
20
+ ## Installation
21
+
22
+ [Installation and Setup](https://github.com/sensu-plugins/documentation/blob/master/user_docs/installation_instructions.md)
23
+
24
+ ## Notes
@@ -0,0 +1,138 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-http-json
4
+ #
5
+ # DESCRIPTION:
6
+ # Takes either a URL or a combination of host/path/query/port/ssl, and checks
7
+ # for valid JSON output in the response. Can also optionally validate simple
8
+ # string key/value pairs.
9
+ #
10
+ # OUTPUT:
11
+ # plain text
12
+ #
13
+ # PLATFORMS:
14
+ # Linux
15
+ #
16
+ # DEPENDENCIES:
17
+ # gem: sensu-plugin
18
+ # gem: json
19
+ #
20
+ # USAGE:
21
+ # #YELLOW
22
+ #
23
+ # NOTES:
24
+ # Based on Check HTTP by Sonian Inc.
25
+ #
26
+ # LICENSE:
27
+ # Copyright 2013 Matt Revell <nightowlmatt@gmail.com>
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'sensu-plugin/check/cli'
33
+ require 'json'
34
+ require 'net/http'
35
+ require 'net/https'
36
+
37
+ #
38
+ # Check JSON
39
+ #
40
+ class CheckJson < Sensu::Plugin::Check::CLI
41
+ option :url, short: '-u URL'
42
+ option :host, short: '-h HOST'
43
+ option :path, short: '-p PATH'
44
+ option :query, short: '-q QUERY'
45
+ option :port, short: '-P PORT', proc: proc(&:to_i)
46
+ option :header, short: '-H HEADER', long: '--header HEADER'
47
+ option :ssl, short: '-s', boolean: true, default: false
48
+ option :insecure, short: '-k', boolean: true, default: false
49
+ option :user, short: '-U', long: '--username USER'
50
+ option :password, short: '-a', long: '--password PASS'
51
+ option :cert, short: '-c FILE'
52
+ option :cacert, short: '-C FILE'
53
+ option :timeout, short: '-t SECS', proc: proc(&:to_i), default: 15
54
+ option :key, short: '-K KEY', long: '--key KEY'
55
+ option :value, short: '-v VALUE', long: '--value VALUE'
56
+
57
+ def run
58
+ if config[:url]
59
+ uri = URI.parse(config[:url])
60
+ config[:host] = uri.host
61
+ config[:path] = uri.path
62
+ config[:query] = uri.query
63
+ config[:port] = uri.port
64
+ config[:ssl] = uri.scheme == 'https'
65
+ else
66
+ # #YELLOW
67
+ unless config[:host] && config[:path] # rubocop:disable IfUnlessModifier
68
+ unknown 'No URL specified'
69
+ end
70
+ config[:port] ||= config[:ssl] ? 443 : 80
71
+ end
72
+
73
+ begin
74
+ timeout(config[:timeout]) do
75
+ acquire_resource
76
+ end
77
+ rescue Timeout::Error
78
+ critical 'Connection timed out'
79
+ rescue => e
80
+ critical "Connection error: #{e.message}"
81
+ end
82
+ end
83
+
84
+ def json_valid?(str)
85
+ JSON.parse(str)
86
+ return true
87
+ rescue JSON::ParserError
88
+ return false
89
+ end
90
+
91
+ def acquire_resource # rubocop:disable all
92
+ http = Net::HTTP.new(config[:host], config[:port])
93
+
94
+ if config[:ssl]
95
+ http.use_ssl = true
96
+ if config[:cert]
97
+ cert_data = File.read(config[:cert])
98
+ http.cert = OpenSSL::X509::Certificate.new(cert_data)
99
+ http.key = OpenSSL::PKey::RSA.new(cert_data, nil)
100
+ end
101
+ http.ca_file = config[:cacert] if config[:cacert]
102
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if config[:insecure]
103
+ end
104
+
105
+ req = Net::HTTP::Get.new([config[:path], config[:query]].compact.join('?'))
106
+ if !config[:user].nil? && !config[:password].nil?
107
+ req.basic_auth config[:user], config[:password]
108
+ end
109
+ if config[:header]
110
+ config[:header].split(',').each do |header|
111
+ h, v = header.split(':', 2)
112
+ req[h] = v.strip
113
+ end
114
+ end
115
+ res = http.request(req)
116
+
117
+ critical res.code unless res.code =~ /^2/
118
+ critical 'invalid JSON from request' unless json_valid?(res.body)
119
+ ok 'valid JSON returned' if config[:key].nil? && config[:value].nil?
120
+
121
+ json = JSON.parse(res.body)
122
+
123
+ begin
124
+ keys = config[:key].scan(/(?:\\\.|[^.])+/).map { |key| key.gsub(/\\./, '.') }
125
+
126
+ leaf = keys.reduce(json) do |tree, key|
127
+ fail "could not find key: #{config[:key]}" unless tree.key?(key)
128
+ tree[key]
129
+ end
130
+
131
+ fail "unexpected value for key: '#{config[:value]}' != '#{leaf}'" unless leaf == config[:value]
132
+
133
+ ok "key has expected value: '#{config[:key]}' = '#{config[:value]}'"
134
+ rescue => e
135
+ critical "key check failed: #{e}"
136
+ end
137
+ end
138
+ end
data/bin/check-http.rb ADDED
@@ -0,0 +1,293 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-http
4
+ #
5
+ # DESCRIPTION:
6
+ # Takes either a URL or a combination of host/path/port/ssl, and checks for
7
+ # a 200 response (that matches a pattern, if given). Can use client certs.
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # #YELLOW
20
+ #
21
+ # NOTES:
22
+ #
23
+ # LICENSE:
24
+ # Copyright 2011 Sonian, Inc <chefs@sonian.net>
25
+ # Updated by Lewis Preson 2012 to accept basic auth credentials
26
+ # Updated by SweetSpot 2012 to require specified redirect
27
+ # Updated by Chris Armstrong 2013 to accept multiple headers
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'sensu-plugin/check/cli'
33
+ require 'net/http'
34
+ require 'net/https'
35
+
36
+ #
37
+ # Check HTTP
38
+ #
39
+ class CheckHttp < Sensu::Plugin::Check::CLI
40
+ option :ua,
41
+ short: '-x USER-AGENT',
42
+ long: '--user-agent USER-AGENT',
43
+ description: 'Specify a USER-AGENT',
44
+ default: 'Sensu-HTTP-Check'
45
+
46
+ option :url,
47
+ short: '-u URL',
48
+ long: '--url URL',
49
+ description: 'A URL to connect to'
50
+
51
+ option :host,
52
+ short: '-h HOST',
53
+ long: '--hostname HOSTNAME',
54
+ description: 'A HOSTNAME to connect to'
55
+
56
+ option :port,
57
+ short: '-P PORT',
58
+ long: '--port PORT',
59
+ proc: proc(&:to_i),
60
+ description: 'Select another port',
61
+ default: 80
62
+
63
+ option :request_uri,
64
+ short: '-p PATH',
65
+ long: '--request-uri PATH',
66
+ description: 'Specify a uri path'
67
+
68
+ option :header,
69
+ short: '-H HEADER',
70
+ long: '--header HEADER',
71
+ description: 'Check for a HEADER'
72
+
73
+ option :ssl,
74
+ short: '-s',
75
+ boolean: true,
76
+ description: 'Enabling SSL connections',
77
+ default: false
78
+
79
+ option :insecure,
80
+ short: '-k',
81
+ boolean: true,
82
+ description: 'Enabling insecure connections',
83
+ default: false
84
+
85
+ option :user,
86
+ short: '-U',
87
+ long: '--username USER',
88
+ description: 'A username to connect as'
89
+
90
+ option :password,
91
+ short: '-a',
92
+ long: '--password PASS',
93
+ description: 'A password to use for the username'
94
+
95
+ option :cert,
96
+ short: '-c FILE',
97
+ long: '--cert FILE',
98
+ description: 'Cert to use'
99
+
100
+ option :cacert,
101
+ short: '-C FILE',
102
+ long: '--cacert FILE',
103
+ description: 'A CA Cert to use'
104
+
105
+ option :expiry,
106
+ short: '-e EXPIRY',
107
+ long: '--expiry EXPIRY',
108
+ proc: proc(&:to_i),
109
+ description: 'Warn EXPIRE days before cert expires'
110
+
111
+ option :pattern,
112
+ short: '-q PAT',
113
+ long: '--query PAT',
114
+ description: 'Query for a specific pattern'
115
+
116
+ option :timeout,
117
+ short: '-t SECS',
118
+ long: '--timeout SECS',
119
+ proc: proc(&:to_i),
120
+ description: 'Set the timeout',
121
+ default: 15
122
+
123
+ option :redirectok,
124
+ short: '-r',
125
+ boolean: true,
126
+ description: 'Check if a redirect is ok',
127
+ default: false
128
+
129
+ option :redirectto,
130
+ short: '-R URL',
131
+ long: '--redirect-to URL',
132
+ description: 'Redirect to another page'
133
+
134
+ option :response_bytes,
135
+ short: '-b BYTES',
136
+ long: '--response-bytes BYTES',
137
+ description: 'Print BYTES of the output',
138
+ proc: proc(&:to_i)
139
+
140
+ option :require_bytes,
141
+ short: '-B BYTES',
142
+ long: '--require-bytes BYTES',
143
+ description: 'Check the response contains exactly BYTES bytes',
144
+ proc: proc(&:to_i)
145
+
146
+ option :response_code,
147
+ long: '--response-code CODE',
148
+ description: 'Check for a specific response code'
149
+
150
+ option :proxy_url,
151
+ long: '--proxy-url PROXY_URL',
152
+ description: 'Use a proxy server to connect'
153
+
154
+ option :no_proxy,
155
+ long: '--noproxy',
156
+ boolean: true,
157
+ description: 'Do not use proxy server even from environment http_proxy setting',
158
+ default: false
159
+
160
+ def run
161
+ if config[:url]
162
+ uri = URI.parse(config[:url])
163
+ config[:host] = uri.host
164
+ config[:port] = uri.port
165
+ config[:request_uri] = uri.request_uri
166
+ config[:ssl] = uri.scheme == 'https'
167
+ else
168
+ # #YELLOW
169
+ unless config[:host] && config[:request_uri] # rubocop:disable IfUnlessModifier
170
+ unknown 'No URL specified'
171
+ end
172
+ config[:port] ||= config[:ssl] ? 443 : 80
173
+ end
174
+
175
+ begin
176
+ timeout(config[:timeout]) do
177
+ acquire_resource
178
+ end
179
+ rescue Timeout::Error
180
+ critical 'Request timed out'
181
+ rescue => e
182
+ critical "Request error: #{e.message}"
183
+ end
184
+ end
185
+
186
+ def acquire_resource # rubocop:disable all
187
+ http = nil
188
+
189
+ if config[:no_proxy]
190
+ http = Net::HTTP.new(config[:host], config[:port], nil, nil)
191
+ elsif config[:proxy_url]
192
+ proxy_uri = URI.parse(config[:proxy_url])
193
+ http = Net::HTTP.new(config[:host], config[:port], proxy_uri.host, proxy_uri.port)
194
+ else
195
+ http = Net::HTTP.new(config[:host], config[:port])
196
+ end
197
+
198
+ warn_cert_expire = nil
199
+ if config[:ssl]
200
+ http.use_ssl = true
201
+ if config[:cert]
202
+ cert_data = File.read(config[:cert])
203
+ http.cert = OpenSSL::X509::Certificate.new(cert_data)
204
+ http.key = OpenSSL::PKey::RSA.new(cert_data, nil)
205
+ end
206
+ http.ca_file = config[:cacert] if config[:cacert]
207
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if config[:insecure]
208
+
209
+ unless config[:expiry].nil?
210
+ expire_warn_date = Time.now + (config[:expiry] * 60 * 60 * 24)
211
+ # We can't raise inside the callback, have to check when we finish.
212
+ http.verify_callback = proc do |_preverify_ok, ssl_context|
213
+ if ssl_context.current_cert.not_after <= expire_warn_date
214
+ warn_cert_expire = ssl_context.current_cert.not_after
215
+ end
216
+ end
217
+ end
218
+ end
219
+
220
+ req = Net::HTTP::Get.new(config[:request_uri], 'User-Agent' => config[:ua])
221
+
222
+ if !config[:user].nil? && !config[:password].nil?
223
+ req.basic_auth config[:user], config[:password]
224
+ end
225
+ if config[:header]
226
+ config[:header].split(',').each do |header|
227
+ h, v = header.split(':', 2)
228
+ req[h] = v.strip
229
+ end
230
+ end
231
+ res = http.request(req)
232
+
233
+ if config[:response_bytes]
234
+ body = "\n" + res.body[0..config[:response_bytes]]
235
+ else
236
+ body = ''
237
+ end
238
+
239
+ if config[:require_bytes] && res.body.length != config[:require_bytes]
240
+ critical "Response was #{res.body.length} bytes instead of #{config[:require_bytes]}" + body
241
+ end
242
+
243
+ unless warn_cert_expire.nil?
244
+ warning "Certificate will expire #{warn_cert_expire}"
245
+ end
246
+
247
+ size = res.body.nil? ? '0' : res.body.size
248
+
249
+ case res.code
250
+ when /^2/
251
+ if config[:redirectto]
252
+ critical "Expected redirect to #{config[:redirectto]} but got #{res.code}" + body
253
+ elsif config[:pattern]
254
+ if res.body =~ /#{config[:pattern]}/
255
+ ok "#{res.code}, found /#{config[:pattern]}/ in #{size} bytes" + body
256
+ else
257
+ critical "#{res.code}, did not find /#{config[:pattern]}/ in #{size} bytes: #{res.body[0...200]}..."
258
+ end
259
+ else
260
+ ok("#{res.code}, #{size} bytes" + body) unless config[:response_code]
261
+ end
262
+ when /^3/
263
+ if config[:redirectok] || config[:redirectto]
264
+ if config[:redirectok]
265
+ # #YELLOW
266
+ ok("#{res.code}, #{size} bytes" + body) unless config[:response_code] # rubocop:disable BlockNesting
267
+ elsif config[:redirectto]
268
+ # #YELLOW
269
+ if config[:redirectto] == res['Location'] # rubocop:disable BlockNesting
270
+ ok "#{res.code} found redirect to #{res['Location']}" + body
271
+ else
272
+ critical "Expected redirect to #{config[:redirectto]} instead redirected to #{res['Location']}" + body
273
+ end
274
+ end
275
+ else
276
+ warning res.code + body
277
+ end
278
+ when /^4/, /^5/
279
+ critical(res.code + body) unless config[:response_code]
280
+ else
281
+ warning(res.code + body) unless config[:response_code]
282
+ end
283
+
284
+ # #YELLOW
285
+ if config[:response_code] # rubocop:disable GuardClause
286
+ if config[:response_code] == res.code
287
+ ok "#{res.code}, #{size} bytes" + body
288
+ else
289
+ critical res.code + body
290
+ end
291
+ end
292
+ end
293
+ end
@@ -0,0 +1,80 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-https-cert
4
+ #
5
+ # DESCRIPTION:
6
+ # Checks the expiration date of a URL SSL Certificate
7
+ # and notifies if it is before the expiry parameter.
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ # gem: nrt-https
18
+ #
19
+ # USAGE:
20
+ # #YELLOW
21
+ #
22
+ # NOTES:
23
+ #
24
+ # LICENSE:
25
+ # Copyright 2014 Rhommel Lamas <roml@rhommell.com>
26
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
27
+ # for details.
28
+ #
29
+
30
+ require 'sensu-plugin/check/cli'
31
+ require 'net/https'
32
+
33
+ #
34
+ # Check HTTP
35
+ #
36
+ class CheckHttpCert < Sensu::Plugin::Check::CLI
37
+ option :url,
38
+ short: '-u URL',
39
+ long: '--url URL',
40
+ proc: proc(&:to_s),
41
+ description: 'A URL to connect to'
42
+
43
+ option :warning,
44
+ short: '-w',
45
+ long: '--warning DAYS',
46
+ proc: proc(&:to_i),
47
+ description: 'Warn EXPIRE days before cert expires'
48
+
49
+ option :critical,
50
+ short: '-c',
51
+ long: '--critical DAYS',
52
+ proc: proc(&:to_i),
53
+ description: 'Critical EXPIRE days before cert expires'
54
+
55
+ def run
56
+ uri = URI.parse(config[:url])
57
+ http = Net::HTTP.new(uri.host, uri.port)
58
+ http.use_ssl = true
59
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
60
+
61
+ http.start do |h|
62
+ @cert = h.peer_cert
63
+ end
64
+ days_until = ((@cert.not_after - Time.now) / (60 * 60 * 24)).to_i
65
+
66
+ if days_until <= 0
67
+ critical "Expired #{days_until.abs} days ago."
68
+ elsif days_until < config[:critical].to_i
69
+ critical "SSL expires on #{@cert.not_after} - #{days_until} days left."
70
+ elsif days_until < config[:warning].to_i
71
+ warning "SSL expires on #{@cert.not_after} - #{days_until} days left."
72
+ else
73
+ ok "SSL expires on #{@cert.not_after} - #{days_until} days left."
74
+ end
75
+
76
+ rescue
77
+ message "Could not connect to #{config[:url]}"
78
+ exit 1
79
+ end
80
+ end
@@ -0,0 +1,74 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # metrics-curl
4
+ #
5
+ # DESCRIPTION:
6
+ # Simple wrapper around curl for getting timing stats from the various phases
7
+ # of connecting to an HTTP/HTTPS server.
8
+ #
9
+ # OUTPUT:
10
+ # metric data
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # #YELLOW
20
+ #
21
+ # NOTES:
22
+ # Based on: http://dev.nuclearrooster.com/2009/12/07/quick-download-benchmarks-with-curl/
23
+ # by Nick Stielau.
24
+ #
25
+ # LICENSE:
26
+ # Copyright 2012 Joe Miller
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+ #
30
+
31
+ require 'socket'
32
+ require 'sensu-plugin/metric/cli'
33
+
34
+ #
35
+ # Curl Metrics
36
+ #
37
+ class CurlMetrics < Sensu::Plugin::Metric::CLI::Graphite
38
+ option :url,
39
+ short: '-u URL',
40
+ long: '--url URL',
41
+ description: 'valid cUrl url to connect',
42
+ default: 'http://127.0.0.1:80/'
43
+
44
+ option :curl_args,
45
+ short: '-a "CURL ARGS"',
46
+ long: '--curl_args "CURL ARGS"',
47
+ description: 'Additional arguments to pass to curl',
48
+ default: ''
49
+
50
+ option :scheme,
51
+ description: 'Metric naming scheme, text to prepend to metric',
52
+ short: '-s SCHEME',
53
+ long: '--scheme SCHEME',
54
+ required: true,
55
+ default: "#{Socket.gethostname}.curl_timings"
56
+
57
+ def run
58
+ cmd = "curl --silent --output /dev/null #{config[:curl_args]} "
59
+ cmd += '-w "%{time_total},%{time_namelookup},%{time_connect},%{time_pretransfer},%{time_redirect},%{time_starttransfer}" '
60
+ cmd += config[:url]
61
+
62
+ output = `#{cmd}`
63
+
64
+ (time_total, time_namelookup, time_connect, time_pretransfer, time_redirect, time_starttransfer) = output.split(',')
65
+ output "#{config[:scheme]}.time_total", time_total
66
+ output "#{config[:scheme]}.time_namelookup", time_namelookup
67
+ output "#{config[:scheme]}.time_connect", time_connect
68
+ output "#{config[:scheme]}.time_pretransfer", time_pretransfer
69
+ output "#{config[:scheme]}.time_redirect", time_redirect
70
+ output "#{config[:scheme]}.time_starttransfer", time_starttransfer
71
+
72
+ ok
73
+ end
74
+ end
@@ -0,0 +1,14 @@
1
+ require 'sensu-plugins-http/version'
2
+
3
+ # Load the defaults
4
+
5
+ #
6
+ # Default class
7
+ #
8
+ module SensuPluginsHttp
9
+ class << self
10
+ end
11
+
12
+ class << self
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ # encoding: utf-8
4
+ module SensuPluginsHttp
5
+ # This defines the version of the gem
6
+ module Version
7
+ MAJOR = 0
8
+ MINOR = 0
9
+ PATCH = 1
10
+
11
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
12
+
13
+ NAME = 'sensu-plugins-http'
14
+ BANNER = "#{NAME} v%s"
15
+
16
+ module_function
17
+
18
+ def version
19
+ format(BANNER, VER_STRING)
20
+ end
21
+
22
+ def json_version
23
+ {
24
+ 'version' => VER_STRING
25
+ }.to_json
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sensu-Plugins and contributors
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRIwEAYDVQQDDAltYXR0
14
+ am9uZXMxGDAWBgoJkiaJk/IsZAEZFgh5aWVsZGJvdDETMBEGCgmSJomT8ixkARkW
15
+ A2NvbTAeFw0xNTAxMjgyMTAyNTFaFw0xNjAxMjgyMTAyNTFaMEMxEjAQBgNVBAMM
16
+ CW1hdHRqb25lczEYMBYGCgmSJomT8ixkARkWCHlpZWxkYm90MRMwEQYKCZImiZPy
17
+ LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyTSzVYnO
18
+ CLgyrIyT1mBQakArQyW8xhi6MlDqyzXHJGeERT790U6EgoBVeS4XoK0ptFZNR8Tf
19
+ zko0w+Nv47TarSCgkPOaxY+mxWnAVR10dOmfeLr7huiMyps+YD56/EF2FqQ3jf/+
20
+ qohENfKD91qy1ieEy+Fn7Pf74ltbNKUdkb9a9eFXQ0DQ4ip5vik7DzjQkUTj4lca
21
+ k6ArwnmHX4YDhZoYtrQJ8jVktN0/+NtA40M5qkCYHNe5tUW25b/tKVYuioxG6b2Z
22
+ oIzaZxRLxf6HVAWpCVRT/F5+/yjigkX4u++eYacfLGleXQzoK7BL65vHGMJygWEE
23
+ 0TKGqFOrl/L0AQIDAQABo38wfTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
24
+ HQ4EFgQUEf6a8Td7MrSZc8ImbLFZAENPbz0wIQYDVR0RBBowGIEWbWF0dGpvbmVz
25
+ QHlpZWxkYm90LmNvbTAhBgNVHRIEGjAYgRZtYXR0am9uZXNAeWllbGRib3QuY29t
26
+ MA0GCSqGSIb3DQEBBQUAA4IBAQBbzXAYA3BVGw8DZ0YYoY1VHPNEcH5qPIApmHO8
27
+ rvSmuUT0yMEi7u00H/5uHRFf4LleGT/+sTdyXKsNPGT9kdRuQEgwi+vf7Zfvd8aX
28
+ UF/+4VkEYf/8rV8Ere6u2QaWPgApdMV6JjKr1fAwCTd8AuGXNaWItiPPMseSQzLJ
29
+ JKP4hVvbc1d+oS925B1lcBiqn2aYvElbyNAVmQPywNNqkWmvtlqj9ZVJfV5HQLdu
30
+ 8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
+ HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
+ -----END CERTIFICATE-----
33
+ date: 2015-05-22 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: sensu-plugin
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.1.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 1.1.0
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 1.8.2
56
+ type: :runtime
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '='
61
+ - !ruby/object:Gem::Version
62
+ version: 1.8.2
63
+ - !ruby/object:Gem::Dependency
64
+ name: codeclimate-test-reporter
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.4'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.4'
77
+ - !ruby/object:Gem::Dependency
78
+ name: rubocop
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.30'
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0.30'
91
+ - !ruby/object:Gem::Dependency
92
+ name: rspec
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '3.1'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '3.1'
105
+ - !ruby/object:Gem::Dependency
106
+ name: bundler
107
+ requirement: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.7'
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.7'
119
+ - !ruby/object:Gem::Dependency
120
+ name: rake
121
+ requirement: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '10.0'
126
+ type: :development
127
+ prerelease: false
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '10.0'
133
+ - !ruby/object:Gem::Dependency
134
+ name: github-markup
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '1.3'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - "~>"
145
+ - !ruby/object:Gem::Version
146
+ version: '1.3'
147
+ - !ruby/object:Gem::Dependency
148
+ name: redcarpet
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '3.2'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '3.2'
161
+ - !ruby/object:Gem::Dependency
162
+ name: yard
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - "~>"
166
+ - !ruby/object:Gem::Version
167
+ version: '0.8'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - "~>"
173
+ - !ruby/object:Gem::Version
174
+ version: '0.8'
175
+ - !ruby/object:Gem::Dependency
176
+ name: pry
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '0.10'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '0.10'
189
+ description: Sensu plugins for various http monitors and metrics
190
+ email: "<sensu-users@googlegroups.com>"
191
+ executables:
192
+ - check-http-json.rb
193
+ - check-http.rb
194
+ - check-https-cert.rb
195
+ - metrics-curl.rb
196
+ extensions: []
197
+ extra_rdoc_files: []
198
+ files:
199
+ - CHANGELOG.md
200
+ - LICENSE
201
+ - README.md
202
+ - bin/check-http-json.rb
203
+ - bin/check-http.rb
204
+ - bin/check-https-cert.rb
205
+ - bin/metrics-curl.rb
206
+ - lib/sensu-plugins-http.rb
207
+ - lib/sensu-plugins-http/version.rb
208
+ homepage: https://github.com/sensu-plugins/sensu-plugins-http
209
+ licenses:
210
+ - MIT
211
+ metadata:
212
+ maintainer: ''
213
+ development_status: unmaintained
214
+ production_status: unstable - testing recommended
215
+ releae_draft: 'false'
216
+ release_prerelease: 'false'
217
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
218
+ in /etc/default/sensu
219
+ rdoc_options: []
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: 1.9.3
227
+ required_rubygems_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ requirements: []
233
+ rubyforge_project:
234
+ rubygems_version: 2.4.6
235
+ signing_key:
236
+ specification_version: 4
237
+ summary: Sensu plugins for various http monitors and metrics
238
+ test_files: []
metadata.gz.sig ADDED
Binary file