sensu-plugins-influxdb-q 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2289304a9e9317ebe88e5c9f8675cb0a8749cf9f
4
- data.tar.gz: 44aae20b6adc5ee9e58b1e6344e12bf8fab8c522
3
+ metadata.gz: 0d24cae40e61200c0f3fbc7007498f0a3eedaf04
4
+ data.tar.gz: 4c611a05196d5f388fb03f5dbb467d57b3f4893b
5
5
  SHA512:
6
- metadata.gz: 03ad4e0226f543b3d2b072a5b0fdb23e50c25a065818ed98de8146d835634cfe2c2dc248d8076efbcac8a1744d6648a34f1c40eb8560272259487a239f26f147
7
- data.tar.gz: 946ea02f53b7f5c9f92ffcb8111afc3558c3b8cd3a89f8940d98223a5b405059abcc936e17e1719e96bccbec60e0e7d3fa9dd432c2689bd3987b139a9443d5a5
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 discovers all active sensu clients via the Sensu REST API and then runs for each client the InfluxDB query filtering by host.
8
- The plugin then generates multiple OK/WARN/CRIT/UNKNOWN events via the sensu client socket (https://sensuapp.org/docs/latest/clients#client-socket-input),
9
- 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.
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 <HANDLERS> Comma separated list of 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.
@@ -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
- @clients.each do |client|
205
- query = config[:query].gsub(" WHERE ", " WHERE #{config[:host_field]} = '#{client}' AND ")
206
- begin
207
- timeout(config[:timeout]) do
208
- begin
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
- rescue
237
- STDERR.puts($!)
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
- if problems > 0
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
@@ -2,7 +2,7 @@ module SensuPluginsInfluxDbQ
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 7
5
+ PATCH = 8
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-influxdb-q
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti