sensu-plugins-influxdb-q 0.0.3 → 0.0.4

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: 7b7059d174d108584e0f38ab72f78c75d69f53b9
4
- data.tar.gz: 1ec6c04c7dc24ef1f72b80b9f9753d47780ba832
3
+ metadata.gz: 6e650968fffac29cb93668649219d88c11010a53
4
+ data.tar.gz: a15f03566144a6e6eba9ba7433f8ded3cee56b57
5
5
  SHA512:
6
- metadata.gz: 768c35b38aa6dcb0d498c1a0a3713833200430631e558f2b645a3b6df3c4a3dba14c48e06a2fc6577cffeb33eab4cf5c6a6dc6840a4ee00a7e63005e1af65667
7
- data.tar.gz: 6a398275e80392f80597439bab0dc1d63e11ae99242953cf11c7123c402bb9e97854cf22b8b26ba40fbc97e342ac59c30093ae13e7ca20911604120111e12b9a
6
+ metadata.gz: 6737956edaf435950c5ccef0d4cac958a38be02586634868732e545cab8f84a3e550e935a51b6817dafabcd52758d6a263d185d27f06ef438cccc04d35305fd8
7
+ data.tar.gz: e53267e4e3890564d0400b54e7ae0bc36508bb9677828fe33580b6a5ba34ffe4ede05dd27b0e44d2b570f63adf6b29887d2a7ac4fc6458178a10b47e9fd6c385
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## Unreleased
7
7
 
8
+ ## [0.0.4] - 2016-01-08
9
+ ### Added
10
+ - Made --json-path optional and got rid of --debug
11
+
8
12
  ## [0.0.3] - 2016-01-08
9
13
  ### Added
10
14
  - Reverted back to source
data/README.md CHANGED
@@ -19,11 +19,10 @@ Usage: check-influxdb-q.rb (options)
19
19
  --check-name <CHECK_NAME> Check name (default: %{name}-%{tags.instance}-%{tags.type})
20
20
  -c, --crit <EXPR> Critical expression (e.g. value >= 10)
21
21
  --database <DATABASE> InfluxDB database (default: collectd)
22
- --debug Enable debug mode
23
22
  --dryrun Do not send events to sensu client socket
24
23
  --host <HOST> InfluxDB host (default: localhost)
25
24
  --host-field <FIELD> InfluxDB measurement host field (default: host)
26
- -j, --json-path <PATH> JSON path for value matching (docs at http://goessner.net/articles/JsonPath) (required)
25
+ -j, --json-path <PATH> JSON path for value matching (docs at http://goessner.net/articles/JsonPath)
27
26
  -m, --msg <MESSAGE> Message to use for OK/WARNING/CRITICAL, supports variable interpolation (e.g. %{tags.instance}) (required)
28
27
  --port <PORT> InfluxDB port (default: 8086)
29
28
  -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)
@@ -42,7 +41,7 @@ check-influxdb-q.rb -q "SELECT DERIVATIVE(LAST(value), 1m) AS value FROM interfa
42
41
 
43
42
  An handy feature is the ability to interpolate the query result hash attributes into the --check-name and --msg command line flags.
44
43
 
45
- So, for query above the result might look like the following (run with --debug to inspect the result):
44
+ So, for query above the result might look like the following (run without --json-path to inspect the result):
46
45
 
47
46
  ```
48
47
  {"name"=>"interface_rx", "tags"=>{"instance"=>"ens255f0", "type"=>"if_errors"}, "values"=>[{"time"=>"2016-01-07T21:43:00Z", "value"=>0}, {"time"=>"2016-01-07T21:44:00Z", "value"=>0}, {"time"=>"2016-01-07T21:45:00Z", "value"=>0}, {"time"=>"2016-01-07T21:46:00Z", "value"=>0}, {"time"=>"2016-01-07T21:47:00Z", "value"=>0}]}
@@ -45,7 +45,7 @@ class CheckInfluxDbQ < Sensu::Plugin::Check::CLI
45
45
  :description => "JSON path for value matching (docs at http://goessner.net/articles/JsonPath)",
46
46
  :short => "-j <PATH>",
47
47
  :long => "--json-path <PATH>",
48
- :required => true
48
+ :default => nil
49
49
 
50
50
  option :check_name,
51
51
  :description => "Check name (default: %{name}-%{tags.instance}-%{tags.type})",
@@ -97,12 +97,6 @@ class CheckInfluxDbQ < Sensu::Plugin::Check::CLI
97
97
  :long => "--crit <EXPR>",
98
98
  :default => nil
99
99
 
100
- option :debug,
101
- :description => "Enable debug mode",
102
- :long => "--debug",
103
- :boolean => true,
104
- :default => false
105
-
106
100
  option :dryrun,
107
101
  :description => "Do not send events to sensu client socket",
108
102
  :long => "--dryrun",
@@ -120,7 +114,11 @@ class CheckInfluxDbQ < Sensu::Plugin::Check::CLI
120
114
  }
121
115
 
122
116
  @calculator = Dentaku::Calculator.new
123
- @json_path = JsonPath.new(config[:json_path])
117
+ if config[:json_path]
118
+ @json_path = JsonPath.new(config[:json_path])
119
+ else
120
+ @json_path = nil
121
+ end
124
122
  @influxdb = InfluxDB::Client.new(cfg)
125
123
 
126
124
  # get list of hosts
@@ -192,31 +190,34 @@ class CheckInfluxDbQ < Sensu::Plugin::Check::CLI
192
190
 
193
191
  @clients.each do |client|
194
192
  query = config[:query].gsub(" WHERE ", " WHERE #{config[:host_field]} = '#{client}' AND ")
195
- puts "* Query: #{query.inspect}" if config[:debug]
196
193
  begin
197
194
  records = @influxdb.query(query)
198
195
  records.each do |record|
199
- puts " - Result: #{record.inspect}" if config[:debug]
200
-
201
- value = @json_path.on(record).first
202
-
203
- record_s = record.symbolize_recursive
204
- check_name = "influxdb-q-#{interpolate(config[:check_name], record_s)}"
205
- msg = interpolate(config[:msg], record_s)
206
-
207
- if value != nil
208
- if config[:crit] and @calculator.evaluate(config[:crit], value: value)
209
- send_critical(check_name, client, "#{msg} - Value: #{value} (#{config[:crit]})")
210
- elsif config[:warn] and @calculator.evaluate(config[:warn], value: value)
211
- send_warning(check_name, client, "#{msg} - Value: #{value} (#{config[:warn]})")
196
+ if @json_path
197
+ value = @json_path.on(record).first
198
+
199
+ record_s = record.symbolize_recursive
200
+ check_name = "influxdb-q-#{interpolate(config[:check_name], record_s)}"
201
+ msg = interpolate(config[:msg], record_s)
202
+
203
+ if value != nil
204
+ if config[:crit] and @calculator.evaluate(config[:crit], value: value)
205
+ send_critical(check_name, client, "#{msg} - Value: #{value} (#{config[:crit]})")
206
+ elsif config[:warn] and @calculator.evaluate(config[:warn], value: value)
207
+ send_warning(check_name, client, "#{msg} - Value: #{value} (#{config[:warn]})")
208
+ else
209
+ send_ok(check_name, client, "#{msg} - Value: #{value}")
210
+ end
212
211
  else
213
- send_ok(check_name, client, "#{msg} - Value: #{value}")
212
+ send_unknown(check_name, client, "#{msg} - Value: N/A")
214
213
  end
215
214
  else
216
- send_unknown(check_name, client, "#{msg} - Value: N/A")
215
+ puts "InfluxDB query [#{query}] held the following result (use --json-path to retrieve a single value)"
216
+ puts
217
+ puts JSON.pretty_generate(record)
218
+ puts
217
219
  end
218
220
  end
219
- puts if config[:debug]
220
221
  rescue
221
222
  STDERR.puts($!)
222
223
  problems += 1
@@ -2,7 +2,7 @@ module SensuPluginsInfluxDbQ
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 3
5
+ PATCH = 4
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Cerutti