sensu-plugins-green-dragon 0.1.1 → 0.1.2
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 +4 -4
- data/bin/check-non-sucess-ratio.rb +161 -0
- data/lib/green-dragon-plugins/version.rb +1 -1
- metadata +3 -3
- data/bin/my-check.rb +0 -229
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1623808ee8db84a9e326a768e042cc9e2cf1745
|
4
|
+
data.tar.gz: 0f5f9506c8e50ceed2afb962a0c4121837b1c8a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7c4a84b0df94b49e4e4f7a4129ad845b5c71f0d03a1290443af0e933e89c11710d509f93c3f45a3a8861b5e327bd2022d59235540b6dcc1392c360399687e65
|
7
|
+
data.tar.gz: c2c5976a2338b50f17237b6b2e7f3fb30d3007a2527a4cd837da4aab4c53640d81cbf60d6df31364ee1c996e9a25ee42557c5282168d087d769352421181b26e
|
@@ -0,0 +1,161 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-non-success-ratio
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Check non-success call ratio
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: sensu-plugin
|
16
|
+
# gem: jsonpath
|
17
|
+
# gem: json
|
18
|
+
# gem: dentaku
|
19
|
+
#
|
20
|
+
# USAGE:
|
21
|
+
# check-non-success-ratio.rb -H localhost -d my_database -u my_user -p my_password -w 'value >= 0.5' -c 'value >= 0.75'
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'influxdb'
|
25
|
+
require 'sensu-plugin/check/cli'
|
26
|
+
require 'json'
|
27
|
+
require 'jsonpath'
|
28
|
+
require 'dentaku'
|
29
|
+
|
30
|
+
# VERSION = '0.1.0'
|
31
|
+
|
32
|
+
#
|
33
|
+
# Check Influxdb Query
|
34
|
+
#
|
35
|
+
class CheckInfluxdbQuery < Sensu::Plugin::Check::CLI
|
36
|
+
check_name nil
|
37
|
+
option :host,
|
38
|
+
short: '-H HOST',
|
39
|
+
long: '--host HOST',
|
40
|
+
default: 'localhost',
|
41
|
+
description: 'InfluxDB host'
|
42
|
+
|
43
|
+
option :port,
|
44
|
+
short: '-P PORT',
|
45
|
+
long: '--port PORT',
|
46
|
+
default: '8086',
|
47
|
+
description: 'InfluxDB port'
|
48
|
+
|
49
|
+
option :use_ssl,
|
50
|
+
description: 'Turn on/off SSL (default: false)',
|
51
|
+
short: '-s',
|
52
|
+
long: '--use_ssl',
|
53
|
+
boolean: true,
|
54
|
+
default: false
|
55
|
+
|
56
|
+
option :verify_ssl,
|
57
|
+
description: 'Turn on/off using SSL certificate (default: false)',
|
58
|
+
short: '-v',
|
59
|
+
long: '--verify_ssl',
|
60
|
+
boolean: true,
|
61
|
+
default: false
|
62
|
+
|
63
|
+
option :ssl_ca_cert,
|
64
|
+
description: 'Path to the ssl ca certificate to connect to the InfluxDB server',
|
65
|
+
short: '-C CA_CERT',
|
66
|
+
long: '--ssl_ca_cert CA_CERT'
|
67
|
+
|
68
|
+
option :database,
|
69
|
+
short: '-d DATABASE',
|
70
|
+
long: '--database DATABASE',
|
71
|
+
default: 'influxdb',
|
72
|
+
description: 'InfluxDB database name'
|
73
|
+
|
74
|
+
option :retry,
|
75
|
+
short: '-r RETRY',
|
76
|
+
long: '--retry RETRY',
|
77
|
+
description: 'InfluxDB retry count with exponential back-off',
|
78
|
+
proc: proc(&:to_i),
|
79
|
+
default: 12
|
80
|
+
|
81
|
+
option :username,
|
82
|
+
short: '-u USERNAME',
|
83
|
+
long: '--username USERNAME',
|
84
|
+
default: 'root',
|
85
|
+
description: 'API username'
|
86
|
+
|
87
|
+
option :password,
|
88
|
+
short: '-p PASSWORD',
|
89
|
+
long: '--password PASSWORD',
|
90
|
+
default: 'root',
|
91
|
+
description: 'API password'
|
92
|
+
|
93
|
+
option :app,
|
94
|
+
short: '-a APP',
|
95
|
+
long: '--app APP',
|
96
|
+
default: nil,
|
97
|
+
description: 'Application for which the check is executed'
|
98
|
+
|
99
|
+
option :warning,
|
100
|
+
short: '-w WARNING',
|
101
|
+
long: '--warning WARNING',
|
102
|
+
default: nil,
|
103
|
+
description: "Warning threshold expression. E.g. 'value >= 10'. See https://github.com/rubysolo/dentaku"
|
104
|
+
|
105
|
+
option :critical,
|
106
|
+
short: '-c CRITICAL',
|
107
|
+
long: '--critical CRITICAL',
|
108
|
+
default: nil,
|
109
|
+
description: "Critical threshold expression. E.g. 'value >= 20'. See https://github.com/rubysolo/dentaku"
|
110
|
+
|
111
|
+
option :help,
|
112
|
+
short: '-h',
|
113
|
+
long: '--help',
|
114
|
+
description: 'Show this message',
|
115
|
+
on: :tail,
|
116
|
+
boolean: true,
|
117
|
+
show_options: true,
|
118
|
+
exit: 0
|
119
|
+
|
120
|
+
def run
|
121
|
+
influxdb = InfluxDB::Client.new config[:database],
|
122
|
+
host: config[:host],
|
123
|
+
port: config[:port],
|
124
|
+
use_ssl: config[:use_ssl],
|
125
|
+
verify_ssl: config[:verify_ssl],
|
126
|
+
ssl_ca_cert: config[:ssl_ca_cert],
|
127
|
+
retry: config[:retry],
|
128
|
+
username: config[:username],
|
129
|
+
password: config[:password]
|
130
|
+
|
131
|
+
success_responses_result = influxdb.query "select sum(value) from counter_httpResponseCode where httpStatus = '200' and application = '#{config[:app]}' and time > now() - 2h"
|
132
|
+
non_success_responses_result = influxdb.query "select sum(value) from counter_httpResponseCode where httpStatus != '200' and application = '#{config[:app]}' and time > now() - 2h"
|
133
|
+
|
134
|
+
if success_responses_result.empty?
|
135
|
+
critical 'No result for success query'
|
136
|
+
elsif non_success_responses.empty?
|
137
|
+
critical 'No result for non-success query'
|
138
|
+
end
|
139
|
+
|
140
|
+
result_json_path = JsonPath.new('$..values[0][1]')
|
141
|
+
|
142
|
+
success_responses_value = get_single_value(result_json_path, success_responses_result)
|
143
|
+
non_success_responses_value = get_single_value(result_json_path, non_success_responses_result)
|
144
|
+
|
145
|
+
ratio = non_success_responses_value / (success_responses_value + non_success_responses_value)
|
146
|
+
|
147
|
+
calc = Dentaku::Calculator.new
|
148
|
+
if config[:critical] && calc.evaluate(config[:critical], value: ratio)
|
149
|
+
critical "Value '#{ratio}' matched '#{config[:critical]}'"
|
150
|
+
elsif config[:warning] && calc.evaluate(config[:warning], value: ratio)
|
151
|
+
warning "Value '#{ratio}' matched '#{config[:warning]}'"
|
152
|
+
else
|
153
|
+
ok "Value '#{ratio}' ok"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def get_single_value(jpath, value)
|
158
|
+
return 0 if jpath.on(value).empty?
|
159
|
+
jpath.on(value).first
|
160
|
+
end
|
161
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-green-dragon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grzegorz Ziemonski
|
@@ -98,7 +98,7 @@ description:
|
|
98
98
|
email:
|
99
99
|
- grzegorz.ziemonski@zooplus.com
|
100
100
|
executables:
|
101
|
-
-
|
101
|
+
- check-non-sucess-ratio.rb
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
@@ -106,7 +106,7 @@ files:
|
|
106
106
|
- Gemfile
|
107
107
|
- README.md
|
108
108
|
- Rakefile
|
109
|
-
- bin/
|
109
|
+
- bin/check-non-sucess-ratio.rb
|
110
110
|
- lib/green-dragon-plugins/version.rb
|
111
111
|
- lib/plugins.rb
|
112
112
|
- sensu-plugins-green-dragon.gemspec
|
data/bin/my-check.rb
DELETED
@@ -1,229 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# check-influxdb-query
|
4
|
-
#
|
5
|
-
# DESCRIPTION:
|
6
|
-
# Check InfluxDB queries
|
7
|
-
#
|
8
|
-
# OUTPUT:
|
9
|
-
# plain text
|
10
|
-
#
|
11
|
-
# PLATFORMS:
|
12
|
-
# Linux
|
13
|
-
#
|
14
|
-
# DEPENDENCIES:
|
15
|
-
# gem: sensu-plugin
|
16
|
-
# gem: jsonpath
|
17
|
-
# gem: json
|
18
|
-
# gem: dentaku
|
19
|
-
#
|
20
|
-
# USAGE:
|
21
|
-
# example commands
|
22
|
-
#
|
23
|
-
# NOTES:
|
24
|
-
# See the README here https://github.com/zeroXten/check_influxdb_query
|
25
|
-
#
|
26
|
-
# LICENSE:
|
27
|
-
# Copyright 2014, Fraser Scott <fraser.scott@gmail.com>
|
28
|
-
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
29
|
-
# for details.
|
30
|
-
#
|
31
|
-
|
32
|
-
require 'influxdb'
|
33
|
-
require 'sensu-plugin/check/cli'
|
34
|
-
require 'json'
|
35
|
-
require 'jsonpath'
|
36
|
-
require 'dentaku'
|
37
|
-
|
38
|
-
# VERSION = '0.1.0'
|
39
|
-
|
40
|
-
#
|
41
|
-
# Check Influxdb Query
|
42
|
-
#
|
43
|
-
class CheckInfluxdbQuery < Sensu::Plugin::Check::CLI
|
44
|
-
check_name nil
|
45
|
-
option :host,
|
46
|
-
short: '-H HOST',
|
47
|
-
long: '--host HOST',
|
48
|
-
default: 'localhost',
|
49
|
-
description: 'InfluxDB host'
|
50
|
-
|
51
|
-
option :port,
|
52
|
-
short: '-P PORT',
|
53
|
-
long: '--port PORT',
|
54
|
-
default: '8086',
|
55
|
-
description: 'InfluxDB port'
|
56
|
-
|
57
|
-
option :use_ssl,
|
58
|
-
description: 'Turn on/off SSL (default: false)',
|
59
|
-
short: '-s',
|
60
|
-
long: '--use_ssl',
|
61
|
-
boolean: true,
|
62
|
-
default: false
|
63
|
-
|
64
|
-
option :verify_ssl,
|
65
|
-
description: 'Turn on/off using SSL certificate (default: false)',
|
66
|
-
short: '-v',
|
67
|
-
long: '--verify_ssl',
|
68
|
-
boolean: true,
|
69
|
-
default: false
|
70
|
-
|
71
|
-
option :ssl_ca_cert,
|
72
|
-
description: 'Path to the ssl ca certificate to connect to the InfluxDB server',
|
73
|
-
short: '-C CA_CERT',
|
74
|
-
long: '--ssl_ca_cert CA_CERT'
|
75
|
-
|
76
|
-
option :database,
|
77
|
-
short: '-d DATABASE',
|
78
|
-
long: '--database DATABASE',
|
79
|
-
default: 'influxdb',
|
80
|
-
description: 'InfluxDB database name'
|
81
|
-
|
82
|
-
option :retry,
|
83
|
-
short: '-r RETRY',
|
84
|
-
long: '--retry RETRY',
|
85
|
-
description: 'InfluxDB retry count with exponential back-off',
|
86
|
-
proc: proc(&:to_i),
|
87
|
-
default: 12
|
88
|
-
|
89
|
-
option :username,
|
90
|
-
short: '-u USERNAME',
|
91
|
-
long: '--username USERNAME',
|
92
|
-
default: 'root',
|
93
|
-
description: 'API username'
|
94
|
-
|
95
|
-
option :password,
|
96
|
-
short: '-p PASSWORD',
|
97
|
-
long: '--password PASSWORD',
|
98
|
-
default: 'root',
|
99
|
-
description: 'API password'
|
100
|
-
|
101
|
-
option :query,
|
102
|
-
short: '-q QUERY',
|
103
|
-
long: '--query QUERY',
|
104
|
-
required: true,
|
105
|
-
description: 'Query to run. See https://influxdb.com/docs/v0.9/query_language/query_syntax.html'
|
106
|
-
|
107
|
-
option :alias,
|
108
|
-
short: '-a ALIAS',
|
109
|
-
long: '--alias ALIAS',
|
110
|
-
default: nil,
|
111
|
-
description: 'Alias of query (e.g. if query and output gets too long)'
|
112
|
-
|
113
|
-
option :mode,
|
114
|
-
short: '-m MODE',
|
115
|
-
long: '--mode MODE',
|
116
|
-
default: 'first',
|
117
|
-
description: 'How the results are being checked (one of "first", "last", "max", "min", "avg") when the query returns more than one value'
|
118
|
-
|
119
|
-
option :jsonpath,
|
120
|
-
short: '-j JSONPATH',
|
121
|
-
long: '--jsonpath JSONPATH',
|
122
|
-
default: nil,
|
123
|
-
description: 'Json path to select value. Takes the first value, or 0 if none. See http://goessner.net/articles/JsonPath/'
|
124
|
-
|
125
|
-
option :noresult,
|
126
|
-
short: '-n',
|
127
|
-
long: '--noresult',
|
128
|
-
boolean: true,
|
129
|
-
description: 'Go critical for no result from query'
|
130
|
-
|
131
|
-
option :warning,
|
132
|
-
short: '-w WARNING',
|
133
|
-
long: '--warning WARNING',
|
134
|
-
default: nil,
|
135
|
-
description: "Warning threshold expression. E.g. 'value >= 10'. See https://github.com/rubysolo/dentaku"
|
136
|
-
|
137
|
-
option :critical,
|
138
|
-
short: '-c CRITICAL',
|
139
|
-
long: '--critical CRITICAL',
|
140
|
-
default: nil,
|
141
|
-
description: "Critical threshold expression. E.g. 'value >= 20'. See https://github.com/rubysolo/dentaku"
|
142
|
-
|
143
|
-
option :help,
|
144
|
-
short: '-h',
|
145
|
-
long: '--help',
|
146
|
-
description: 'Show this message',
|
147
|
-
on: :tail,
|
148
|
-
boolean: true,
|
149
|
-
show_options: true,
|
150
|
-
exit: 0
|
151
|
-
|
152
|
-
# option :version,
|
153
|
-
# short: '-v',
|
154
|
-
# long: '--version',
|
155
|
-
# description: 'Show version',
|
156
|
-
# on: :tail,
|
157
|
-
# boolean: true,
|
158
|
-
# proc: proc { puts "Version #{VERSION}" },
|
159
|
-
# exit: 0
|
160
|
-
|
161
|
-
def run
|
162
|
-
influxdb = InfluxDB::Client.new config[:database],
|
163
|
-
host: config[:host],
|
164
|
-
port: config[:port],
|
165
|
-
use_ssl: config[:use_ssl],
|
166
|
-
verify_ssl: config[:verify_ssl],
|
167
|
-
ssl_ca_cert: config[:ssl_ca_cert],
|
168
|
-
retry: config[:retry],
|
169
|
-
username: config[:username],
|
170
|
-
password: config[:password]
|
171
|
-
|
172
|
-
value = influxdb.query config[:query]
|
173
|
-
|
174
|
-
query_name = if config[:alias]
|
175
|
-
config[:alias]
|
176
|
-
else
|
177
|
-
config[:query]
|
178
|
-
end
|
179
|
-
|
180
|
-
if config[:noresult] && value.empty?
|
181
|
-
critical "No result for query '#{query_name}'"
|
182
|
-
elsif config[:noresult] && !config[:jsonpath] && !value.empty?
|
183
|
-
ok "Value returned for query '#{query_name}'"
|
184
|
-
end
|
185
|
-
|
186
|
-
if config[:jsonpath]
|
187
|
-
json_path = JsonPath.new(config[:jsonpath])
|
188
|
-
calc = Dentaku::Calculator.new
|
189
|
-
if config[:mode] == 'any' && json_path.on(value).length >= 1
|
190
|
-
json_path.on(value).each do |hashval|
|
191
|
-
if config[:critical] && calc.evaluate(config[:critical], value: hashval)
|
192
|
-
critical "Value '#{value}' matched '#{config[:critical]}' for query '#{query_name}'"
|
193
|
-
elsif config[:warning] && calc.evaluate(config[:warning], value: hashval)
|
194
|
-
warning "Value '#{value}' matched '#{config[:warning]}' for query '#{query_name}'"
|
195
|
-
end
|
196
|
-
end
|
197
|
-
ok 'All values OK!'
|
198
|
-
else
|
199
|
-
value = get_single_value(json_path, value)
|
200
|
-
if config[:critical] && calc.evaluate(config[:critical], value: value)
|
201
|
-
critical "Value '#{value}' matched '#{config[:critical]}' for query '#{query_name}'"
|
202
|
-
elsif config[:warning] && calc.evaluate(config[:warning], value: value)
|
203
|
-
warning "Value '#{value}' matched '#{config[:warning]}' for query '#{query_name}'"
|
204
|
-
else
|
205
|
-
ok "Value '#{value}' ok for query '#{query_name}'"
|
206
|
-
end
|
207
|
-
end
|
208
|
-
else
|
209
|
-
puts 'Debug output. Use -j to check value...'
|
210
|
-
puts JSON.pretty_generate(value)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
def get_single_value(jpath, value)
|
215
|
-
return 0 if jpath.on(value).empty?
|
216
|
-
case config[:mode]
|
217
|
-
when 'last'
|
218
|
-
jpath.on(value).last
|
219
|
-
when 'min'
|
220
|
-
jpath.on(value).min
|
221
|
-
when 'max'
|
222
|
-
jpath.on(value).max
|
223
|
-
when 'avg', 'average'
|
224
|
-
jpath.on(value).inject(:+).to_f / jpath.on(value).length
|
225
|
-
else
|
226
|
-
jpath.on(value).first
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|