sensu-plugins-influxdb-q 0.0.7 → 0.0.8
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/CHANGELOG.md +4 -0
- data/README.md +7 -6
- data/bin/check-influxdb-q.rb +28 -20
- data/lib/sensu-plugins-influxdb-q/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d24cae40e61200c0f3fbc7007498f0a3eedaf04
|
4
|
+
data.tar.gz: 4c611a05196d5f388fb03f5dbb467d57b3f4893b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ecd6223a8bdb04a03a4ef6f428c371b421fab02dc172b39f14694c8d03f66f016ed23ff69b2acd850d1a3afad5fcad1f4d08d4dfa35ab4584218650023c111e
|
7
|
+
data.tar.gz: afeca730f93429da2ae027ee0b521ea4dbeb06ed75ce197b7ff0bc2b2bfab5df5d8fe52c3bf1e09c59fa361017b14e1851ce23cbd0dc81f8c31cad54078d16bc
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
3
3
|
|
4
4
|
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
5
|
|
6
|
+
## [0.0.8] - 2016-01-18
|
7
|
+
### Added
|
8
|
+
- Not filtering by sensu clients anymore
|
9
|
+
|
6
10
|
## [0.0.7] - 2016-01-18
|
7
11
|
### Added
|
8
12
|
- Fixing closing bracket
|
data/README.md
CHANGED
@@ -4,9 +4,9 @@ A sensu plugin that extends Sensu with the ability to run queries against Influx
|
|
4
4
|
|
5
5
|
This is generally useful when you have to evaluate an issue using some analytics functions (e.g. moving average, derivative etc.).
|
6
6
|
|
7
|
-
The plugin
|
8
|
-
|
9
|
-
|
7
|
+
The plugin generates multiple OK/WARN/CRIT/UNKNOWN events via the sensu client socket (https://sensuapp.org/docs/latest/clients#client-socket-input),
|
8
|
+
making sure to override the client source (in the check result) so that the check shows up as if it was triggered by the original sensu client. The client
|
9
|
+
source is overriden ONLY if the host field (--host-field) is present in the results returned by the InfluxDB query.
|
10
10
|
|
11
11
|
The plugin is inspired by https://github.com/sensu-plugins/sensu-plugins-influxdb.
|
12
12
|
|
@@ -20,13 +20,14 @@ Usage: check-influxdb-q.rb (options)
|
|
20
20
|
-c, --crit <EXPR> Critical expression (e.g. value >= 10)
|
21
21
|
--database <DATABASE> InfluxDB database (default: collectd)
|
22
22
|
--dryrun Do not send events to sensu client socket
|
23
|
-
--handlers <
|
23
|
+
--handlers <HANDLER> Comma separated list of handlers
|
24
24
|
--host <HOST> InfluxDB host (default: localhost)
|
25
25
|
--host-field <FIELD> InfluxDB measurement host field (default: host)
|
26
26
|
-j, --json-path <PATH> JSON path for value matching (docs at http://goessner.net/articles/JsonPath)
|
27
27
|
-m, --msg <MESSAGE> Message to use for OK/WARNING/CRITICAL, supports variable interpolation (e.g. %{tags.instance}) (required)
|
28
28
|
--port <PORT> InfluxDB port (default: 8086)
|
29
|
-
-q, --query <QUERY> Query to execute [e.g. SELECT DERIVATIVE(LAST(value), 1m) AS value FROM interface_rx WHERE type = 'if_errors' AND time > now() - 5m group by time(1m), instance, type fill(none)] (required)
|
29
|
+
-q, --query <QUERY> Query to execute [e.g. SELECT DERIVATIVE(LAST(value), 1m) AS value FROM interface_rx WHERE type = 'if_errors' AND time > now() - 5m group by time(1m), host, instance, type fill(none)] (required)
|
30
|
+
--timeout <SECONDS> InfluxDB query timeout (default: 3)
|
30
31
|
--use-ssl InfluxDB SSL (default: false)
|
31
32
|
-w, --warn <EXPR> Warning expression (e.g. value >= 5)
|
32
33
|
```
|
@@ -39,7 +40,7 @@ A typical example could be the monitoring of interface errors when using the 'in
|
|
39
40
|
|
40
41
|
|
41
42
|
```
|
42
|
-
check-influxdb-q.rb -q "SELECT DERIVATIVE(LAST(value), 1m) AS value FROM interface_rx WHERE type = 'if_errors' AND time > now() - 5m group by time(1m), instance, type fill(none)" -j '$.values[-1].value' -w 'value > 0' --msg "Number of RX errors on interface %{tags.instance}"
|
43
|
+
check-influxdb-q.rb -q "SELECT DERIVATIVE(LAST(value), 1m) AS value FROM interface_rx WHERE type = 'if_errors' AND time > now() - 5m group by time(1m), host, instance, type fill(none)" -j '$.values[-1].value' -w 'value > 0' --msg "Number of RX errors on interface %{tags.instance}"
|
43
44
|
```
|
44
45
|
|
45
46
|
An handy feature is the ability to interpolate the query result hash attributes into the --check-name and --msg command line flags.
|
data/bin/check-influxdb-q.rb
CHANGED
@@ -37,7 +37,7 @@ class CheckInfluxDbQ < Sensu::Plugin::Check::CLI
|
|
37
37
|
include Sensu::Plugin::Utils
|
38
38
|
|
39
39
|
option :query,
|
40
|
-
:description => "Query to execute [e.g. SELECT DERIVATIVE(LAST(value), 1m) AS value FROM interface_rx WHERE type = 'if_errors' AND time > now() - 5m group by time(1m), instance, type fill(none)]",
|
40
|
+
:description => "Query to execute [e.g. SELECT DERIVATIVE(LAST(value), 1m) AS value FROM interface_rx WHERE type = 'if_errors' AND time > now() - 5m group by time(1m), host, instance, type fill(none)]",
|
41
41
|
:short => "-q <QUERY>",
|
42
42
|
:long => "--query <QUERY>",
|
43
43
|
:required => true
|
@@ -92,6 +92,12 @@ class CheckInfluxDbQ < Sensu::Plugin::Check::CLI
|
|
92
92
|
:long => "--host-field <FIELD>",
|
93
93
|
:default => "host"
|
94
94
|
|
95
|
+
option :only_sensu_clients,
|
96
|
+
:description => "Only consider measurements of known sensu clients",
|
97
|
+
:long => "--only-sensu-clients",
|
98
|
+
:boolean => true
|
99
|
+
:default => false
|
100
|
+
|
95
101
|
option :handlers,
|
96
102
|
:description => "Comma separated list of handlers",
|
97
103
|
:long => "--handlers <HANDLER>",
|
@@ -201,13 +207,21 @@ class CheckInfluxDbQ < Sensu::Plugin::Check::CLI
|
|
201
207
|
def run()
|
202
208
|
problems = 0
|
203
209
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
records = @influxdb.query(query)
|
210
|
+
begin
|
211
|
+
timeout(config[:timeout]) do
|
212
|
+
begin
|
213
|
+
records = @influxdb.query(query)
|
214
|
+
if records.size > 0
|
210
215
|
records.each do |record|
|
216
|
+
if record.has_key?(config[:host_field])
|
217
|
+
client = record[config[:host_field]]
|
218
|
+
|
219
|
+
# skip client if it's not already known by Sensu
|
220
|
+
next if config[:only_sensu_clients] and ! @clients.include?(client)
|
221
|
+
else
|
222
|
+
client = nil
|
223
|
+
end
|
224
|
+
|
211
225
|
if @json_path
|
212
226
|
value = @json_path.on(record).first
|
213
227
|
|
@@ -233,23 +247,17 @@ class CheckInfluxDbQ < Sensu::Plugin::Check::CLI
|
|
233
247
|
puts
|
234
248
|
end
|
235
249
|
end
|
236
|
-
|
237
|
-
|
238
|
-
problems += 1
|
250
|
+
else
|
251
|
+
unknown("InfluxDB query [#{query}] held no results")
|
239
252
|
end
|
253
|
+
rescue
|
254
|
+
critical("InfluxDB query [#{query}] failed - (#{$!})")
|
240
255
|
end
|
241
|
-
rescue Timeout::Error
|
242
|
-
STDERR.puts("InfluxDB query [#{query}] timed out")
|
243
|
-
problems += 1
|
244
256
|
end
|
257
|
+
rescue Timeout::Error
|
258
|
+
unknown("InfluxDB query [#{query}] timed out")
|
245
259
|
end
|
246
260
|
|
247
|
-
|
248
|
-
message("Failed to run query for #{problems} clients")
|
249
|
-
critical if config[:crit]
|
250
|
-
warning
|
251
|
-
else
|
252
|
-
ok("Query executed successfully for #{@clients.size} clients")
|
253
|
-
end
|
261
|
+
ok("Query executed successfully")
|
254
262
|
end
|
255
263
|
end
|