sensu-checks-http-response-time 0.1.5

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: dce6daebbe4ab8123c228ce40a2a4d75cb502e4e
4
+ data.tar.gz: 8dfed77ea9f66738b4f151d7211fad6f2507c26d
5
+ SHA512:
6
+ metadata.gz: 9c46f5aaa76d7c8f8e74bbd9a07aeb5ade3b808041eedb3eed9c7539936220e4584a9fd0887a8e8bf5233fe3aab0ba546d8540e8cffb7c321d5b2d0b957597de
7
+ data.tar.gz: b448adc8f23ec5f9463d9e816123ad7bbe3c917510afc38d99a734d2428e55f60c6b94b1ce1309249c4df94caf4a26dbbef7e4c5fa208d31f0a17909d8373378
data/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ A modified MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dirk Gustke
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ Neither the Software, nor any derivative product, shall be used to operate weapons
10
+
11
+ Neither the Software, nor any derivative product, shall be used for any military use
12
+
13
+ Neither the Software, nor any derivative product, shall be used for any use by intelligence agencies
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+
File without changes
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'sensu-plugin/check/cli'
5
+ require 'net/http'
6
+ require 'net/https'
7
+
8
+
9
+ class CheckHttpResponseTime < Sensu::Plugin::Check::CLI
10
+
11
+
12
+ option :sudo,
13
+ short: '-s',
14
+ long: '--sudo',
15
+ description: 'run curl with sudo (and possibly avoid running sensu as root)',
16
+ boolean: true,
17
+ default: false
18
+
19
+ option :url,
20
+ short: '-u URL',
21
+ long: '--url URL',
22
+ description: 'relative URL on the given domain, defaults to /',
23
+ default: '/'
24
+
25
+ option :port,
26
+ short: '-p PORT',
27
+ long: '--port PORT',
28
+ description: 'port to check on the target host, defaults to 80',
29
+ default: 80
30
+
31
+ option :host,
32
+ short: '-h HOSTNAME',
33
+ long: '--host HOSTNAME',
34
+ description: 'alternating http-hostname for the given address, overrides the possible hostname of address, using this in combination with an IP-address will result in zero values for time_namelookup',
35
+ default: nil
36
+
37
+ option :address,
38
+ short: '-a ADDRESS',
39
+ long: '--address ADDRESS',
40
+ description: 'address to look up (ie. www.gruenderszene.de)',
41
+ required: true
42
+
43
+ option :protocol,
44
+ short: '-x PROTOCOL',
45
+ long: '--protocol PROTOCOL',
46
+ description: 'protocol to use in curl query, defaults to https',
47
+ default: 'https'
48
+
49
+ option :user,
50
+ short: '-U USER',
51
+ long: '--user USER',
52
+ description: 'user to use with basic auth',
53
+ default: nil
54
+
55
+ option :pass,
56
+ short: '-P PASSWORD',
57
+ long: '--password',
58
+ description: 'password to use with basic auth',
59
+ default: nil
60
+
61
+ option :method,
62
+ short: '-m METHOD',
63
+ long: '--method METHOD',
64
+ description: 'http method to use (GET, POST, DELETE, etc.), defaults to GET',
65
+ default: 'GET'
66
+
67
+ option :body_data,
68
+ short: '-d DATA',
69
+ long: '--body_data DATA',
70
+ description: 'body data to send along',
71
+ default: nil
72
+
73
+ option :headers,
74
+ short: '-H HEADER',
75
+ long: '--headers HEADER',
76
+ description: 'set header field, comma separated',
77
+ default: ''
78
+
79
+ option :user_agent,
80
+ short: '-A USER_AGENT',
81
+ long: '--user-agent',
82
+ description: 'set the user agent header',
83
+ default: nil
84
+
85
+ option :warn,
86
+ short: '-W WARN_LEVEL_IN_MS',
87
+ long: '--warn-level WARN_LEVEL_IN_MS',
88
+ description: 'values above this threshold will trigger a warning notification, defaults to 500',
89
+ default: 500
90
+
91
+ option :critical,
92
+ short: '-C CRTICIAL_LEVEL_IN_MS',
93
+ long: '--critical-level CRITICAL_LEVEL_IN_MS',
94
+ description: 'values above this threshold will trigger a critical notification, defaults to 1000',
95
+ default: 1000
96
+
97
+ def run
98
+
99
+ # init variable
100
+ command = ""
101
+
102
+ # enable sudo use if requested
103
+ command += "sudo " if config[:sudo]
104
+
105
+ # basic command
106
+ command += "curl -sq "
107
+
108
+ # prepare domain part
109
+ domain_string = config[:address]
110
+ if config[:port]
111
+ config[:host] = config[:address] if !config[:host]
112
+ domain_string += ":#{config[:port]}"
113
+ end
114
+
115
+ # add all headers
116
+ config[:headers].split(',').each do |header_string|
117
+ command += "-H \"#{header_string.gsub(/"/, '\\"')}\" "
118
+ end
119
+
120
+ # prepare optional hostname override
121
+ if config[:host]
122
+ command += "-H \"Host: #{config[:host]}\" "
123
+ end
124
+
125
+ # add body
126
+ command += "-d '#{config[:body_data].gsub(/'/, "\\'")}' " if config[:body_data]
127
+
128
+ # use specified method
129
+ command += "-X#{config[:method].upcase} " if config[:method]
130
+
131
+ # use given username and password
132
+ if config[:user]
133
+ command += "-u #{config[:user]}"
134
+ command += ":#{config[:pass]}"
135
+ command += " "
136
+ end
137
+
138
+ # add user agent
139
+ command += "-A '#{config[:user_agent].gsub(/'/, "\\'")}' " if config[:user_agent]
140
+
141
+ # squelch site output
142
+ command += '--output /dev/null '
143
+
144
+ command += '-w "%{time_total}" '
145
+
146
+ # add target uri
147
+ command += "\"#{config[:protocol]}://#{domain_string}#{config[:url]}\""
148
+
149
+ # fetch stats
150
+ time_total = `#{command}`
151
+ time_total_ms = (time_total.to_f * 1000.0).ceil.to_i
152
+
153
+ if time_total_ms > config[:critical].to_i
154
+ critical "request exceeded critical level: #{time_total_ms}ms"
155
+ elsif time_total_ms > config[:warn].to_i
156
+ warning "request exceeded warning level: #{time_total_ms}ms"
157
+ end
158
+
159
+ ok "#{time_total_ms} is acceptable"
160
+ end
161
+
162
+ end
163
+
@@ -0,0 +1,178 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require 'sensu-plugin/metric/cli'
5
+ require 'socket'
6
+
7
+
8
+ class MetricHttpResponseTime < Sensu::Plugin::Metric::CLI::Graphite
9
+
10
+ option :sudo,
11
+ short: '-s',
12
+ long: '--sudo',
13
+ description: 'run curl with sudo (and possibly avoid running sensu as root)',
14
+ boolean: true,
15
+ default: false
16
+
17
+ option :fields,
18
+ short: '-f fieldlist',
19
+ long: '--fields fieldlist',
20
+ description: 'The stats fields to get from curl, comma sepparated. See curl -w',
21
+ default: 'time_total,time_namelookup,time_connect,time_pretransfer,time_redirect,time_starttransfer'
22
+
23
+ option :scheme,
24
+ short: '-C SCHEME',
25
+ long: '--scheme SCHEME',
26
+ description: 'Metric naming scheme, text to prepend to metric and scheme_append',
27
+ default: "#{Socket.gethostname}"
28
+
29
+ option :url,
30
+ short: '-u URL',
31
+ long: '--url URL',
32
+ description: 'relative URL on the given domain, defaults to /',
33
+ default: '/'
34
+
35
+ option :port,
36
+ short: '-p PORT',
37
+ long: '--port PORT',
38
+ description: 'port to check on the target host, defaults to 80',
39
+ default: 80
40
+
41
+ option :host,
42
+ short: '-h HOSTNAME',
43
+ long: '--host HOSTNAME',
44
+ description: 'alternating http-hostname for the given address, overrides the possible hostname of address, using this in combination with an IP-address will result in zero values for time_namelookup',
45
+ default: nil
46
+
47
+ option :address,
48
+ short: '-a ADDRESS',
49
+ long: '--address ADDRESS',
50
+ description: 'address to look up (ie. www.gruenderszene.de)',
51
+ required: true
52
+
53
+ option :protocol,
54
+ short: '-x PROTOCOL',
55
+ long: '--protocol PROTOCOL',
56
+ description: 'protocol to use in curl query, defaults to https',
57
+ default: 'https'
58
+
59
+ option :scheme_append,
60
+ short: '-S APPEND_STRING',
61
+ long: '--scheme-append APPEND_STRING',
62
+ description: 'Set a string that will be placed right after the host identification and the script identification but before the measurements',
63
+ default: nil
64
+
65
+ option :user,
66
+ short: '-U USER',
67
+ long: '--user USER',
68
+ description: 'user to use with basic auth',
69
+ default: nil
70
+
71
+ option :pass,
72
+ short: '-P PASSWORD',
73
+ long: '--password',
74
+ description: 'password to use with basic auth',
75
+ default: nil
76
+
77
+ option :method,
78
+ short: '-m METHOD',
79
+ long: '--method METHOD',
80
+ description: 'http method to use (GET, POST, DELETE, etc.), defaults to GET',
81
+ default: 'GET'
82
+
83
+ option :body_data,
84
+ short: '-d DATA',
85
+ long: '--body_data DATA',
86
+ description: 'body data to send along',
87
+ default: nil
88
+
89
+ option :headers,
90
+ short: '-H HEADER',
91
+ long: '--headers HEADER',
92
+ description: 'set header field, comma separated',
93
+ default: ''
94
+
95
+ option :user_agent,
96
+ short: '-A USER_AGENT',
97
+ long: '--user-agent USER_AGENT',
98
+ description: 'set the user agent header',
99
+ default: nil
100
+
101
+
102
+ def run
103
+
104
+ unless config[:fields].empty?
105
+
106
+ # init variable
107
+ command = ""
108
+
109
+ # enable sudo use if requested
110
+ command += "sudo " if config[:sudo]
111
+
112
+ # basic command
113
+ command += "curl -sq "
114
+
115
+ # prepare domain part
116
+ domain_string = config[:address]
117
+ if config[:port]
118
+ config[:host] = config[:address] if !config[:host]
119
+ domain_string += ":#{config[:port]}"
120
+ end
121
+
122
+ # add all headers
123
+ config[:headers].split(',').each do |header_string|
124
+ command += "-H \"#{header_string.gsub(/"/, '\\"')}\" "
125
+ end
126
+
127
+ # prepare optional hostname override
128
+ if config[:host]
129
+ command += "-H \"Host: #{config[:host]}\" "
130
+ end
131
+
132
+ # add the selected fields
133
+ fields = config[:fields].split(',').map do |field|
134
+ "#{field} %{#{field}}"
135
+ end.join("\n")
136
+ command += "-w \"#{fields}\" "
137
+
138
+ # add body
139
+ command += "-d '#{config[:body_data].gsub(/'/, "\\'")}' " if config[:body_data]
140
+
141
+ # use specified method
142
+ command += "-X#{config[:method].upcase} " if config[:method]
143
+
144
+ # use given username and password
145
+ if config[:user]
146
+ command += "-u #{config[:user]}"
147
+ command += ":#{config[:pass]}"
148
+ command += " "
149
+ end
150
+
151
+ # add user agent
152
+ command += "-A '#{config[:user_agent].gsub(/'/, "\\'")}' " if config[:user_agent]
153
+
154
+ # squelch site output
155
+ command += '--output /dev/null '
156
+
157
+ # add target uri
158
+ command += "\"#{config[:protocol]}://#{domain_string}#{config[:url]}\""
159
+
160
+ # fetch stats
161
+ stats_string = `#{command}`
162
+
163
+ # send them along
164
+ base_path = config[:scheme]
165
+ base_path += ".#{config[:scheme_append]}" if config[:scheme_append]
166
+ base_path += ".http_response_time"
167
+ stats_string.split("\n").each do |stat_line|
168
+ stats = stat_line.split(' ').compact
169
+ output "#{base_path}.#{stats[0].gsub(/[^a-zA-Z0-9_\.]/, '_')}", stats[1]
170
+ end
171
+
172
+ end
173
+
174
+ ok
175
+ end
176
+
177
+ end
178
+
@@ -0,0 +1,2 @@
1
+ require 'sensu-checks-http-response-time/version.rb'
2
+
@@ -0,0 +1,10 @@
1
+ module SensuChecksHttpResponseTime
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ PATCH = 5
6
+
7
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
10
+
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-checks-http-response-time
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - vmpublishing development
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: sensu gem to get http response time checks and metrics. uses curl to
56
+ query the target host
57
+ email:
58
+ - dev@vmpublishing.com
59
+ executables:
60
+ - metric-http-response-time.rb
61
+ - check-http-response-time.rb
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - LICENSE
66
+ - README.md
67
+ - bin/check-http-response-time.rb
68
+ - bin/metric-http-response-time.rb
69
+ - lib/sensu-checks-http-response-time.rb
70
+ - lib/sensu-checks-http-response-time/version.rb
71
+ homepage: https://github.com/vmpublishing/sensu-checks-http-response-time
72
+ licenses:
73
+ - Nonstandard
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.5.1
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: sensu gem to get http response time checks and metrics.
95
+ test_files: []