sensu-plugins-elasticsearch 1.0.0 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 916ac07d3bae1f72dfe1b147803712caf0051397
4
- data.tar.gz: 49eb92c702d9b07a3f7d607f0cf412e32acf230d
3
+ metadata.gz: 4ed5007f08f3c8b041dbdefc02e3048eedea4344
4
+ data.tar.gz: bae5313f706c29f0ac15b9c6f1d14ca5f62ec548
5
5
  SHA512:
6
- metadata.gz: 6e1845230c4cf9911e5843f032d56bfee2cbdeccc370bf43ed5d0873665dca17b1e3c51b01416b5aac9ca008f77ae619da5804f095edbd925b76975c57c46f29
7
- data.tar.gz: 80a2ea4fc5e0ebe877eb57f76d4510fee044fa95c1bd871c9813195109233462b890dc06957c887c197ad73fa455ee417a699b99d662f279787de8d087460f82
6
+ metadata.gz: 4c98a9beafb8521e83dbfe30a1d2899f06408637f87e5541f3e21c517cde5de050c9edbb2e2e153f2a31f35b3c667457e197ff9e3867de29ba8140f24a14a349
7
+ data.tar.gz: 063d44a9119a86445aa315e2d192c62e0ade50722482be8b7a15103b845a83d5f7eef000fb055a79b4fa54ed4b0f5cf5798e40347019e4184b9a6205bca1f461
data/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [1.1.0] - 2016-11-14
9
+ ### Changed
10
+ - Changed check-es-heap.rb to be compatible with Elasticsearch 5.0 (@christianherro)
11
+
12
+ ### Added
13
+ - Added check-es-query-ratio.tb to support ratio-type checks (@alcasim)
14
+ - Added direct support to check-es-indices-size.rb to delete indicies without the handler-es-delete-indices.rb
15
+
16
+ ### Fixed
17
+ - aws-sdk 2.5.x breaks aws-es-transport (@sstarcher)
18
+ - check-es-indicies-size - fix array mapping by (@nyxcharon)
19
+
8
20
  ## [1.0.0] - 2016-07-29
9
21
  ### Added
10
22
  - Added AWS transport gem and configuration for check-es-query-* sensu calls to use --transport=AWS (@brendangibat)
@@ -26,6 +38,9 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
26
38
  ### Changed
27
39
  - Update to Rubocop 0.40 and cleanup (@eheydrick)
28
40
 
41
+ ### Fixed
42
+ - check-es-indicies-size.rb - broken for newer updates
43
+
29
44
  ## [0.5.3] - 2016-04-02
30
45
  ### Added
31
46
  - check-es-indexes (check for dup indexes) (Yieldbot)
@@ -107,7 +122,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
107
122
  ### Added
108
123
  - initial release
109
124
 
110
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.0.0...HEAD
125
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.1.0...HEAD
126
+ [1.1.0]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.0.0...1.1.0
111
127
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/0.5.3...1.0.0
112
128
  [0.5.3]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/0.4.3...0.5.3
113
129
  [0.4.3]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/0.4.2...0.4.3
data/README.md CHANGED
@@ -19,6 +19,7 @@
19
19
  * /bin/check-es-node-status.rb
20
20
  * /bin/check-es-query-count.rb
21
21
  * /bin/check-es-query-exists.rb
22
+ * /bin/check-es-query-ratio.rb
22
23
  * /bin/check-es-shard-allocation-status.rb
23
24
  * /bin/handler-es-delete-indices.rb
24
25
  * /bin/metrics-es-cluster.rb
data/bin/check-es-heap.rb CHANGED
@@ -122,9 +122,9 @@ class ESHeap < Sensu::Plugin::Check::CLI
122
122
 
123
123
  def acquire_heap_data(return_max = false)
124
124
  stats = if Gem::Version.new(acquire_es_version) >= Gem::Version.new('1.0.0')
125
- acquire_es_resource('/_nodes/_local/stats?jvm=true')
125
+ acquire_es_resource('/_nodes/_local/stats')
126
126
  else
127
- acquire_es_resource('/_cluster/nodes/_local/stats?jvm=true')
127
+ acquire_es_resource('/_cluster/nodes/_local/stats')
128
128
  end
129
129
  node = stats['nodes'].keys.first
130
130
  begin
@@ -99,6 +99,13 @@ class ESCheckIndicesSizes < Sensu::Plugin::Check::CLI
99
99
  long: '--pattern-regex PATTERN_REGEX',
100
100
  default: '^(?<pattern>.*)-(?<year>\d\d\d\d)\.(?<month>\d\d?).(?<day>\d\d?)$'
101
101
 
102
+ option :delete,
103
+ description: 'Instead of alerting deletes the indicies',
104
+ short: '-d',
105
+ long: '--delete',
106
+ boolean: true,
107
+ default: false
108
+
102
109
  def get_indices_to_delete(starting_date, total_bytes_to_delete, indices_with_sizes)
103
110
  total_bytes_deleted = 0
104
111
  curr_date = DateTime.now
@@ -109,13 +116,13 @@ class ESCheckIndicesSizes < Sensu::Plugin::Check::CLI
109
116
  while total_bytes_deleted < total_bytes_to_delete && starting_date < curr_date
110
117
  same_day_indices = indices_with_sizes.values.map do |pattern|
111
118
  pattern.select do |index|
112
- index['date'] == starting_date
119
+ index[:date] == starting_date
113
120
  end
114
121
  end.flatten
115
122
  same_day_indices.each do |index|
116
123
  if total_bytes_deleted < total_bytes_to_delete
117
- indices_to_delete.push(index['index'])
118
- total_bytes_deleted += index['size']
124
+ indices_to_delete.push(index[:index])
125
+ total_bytes_deleted += index[:size]
119
126
  end
120
127
  end
121
128
  starting_date += 1
@@ -175,11 +182,16 @@ class ESCheckIndicesSizes < Sensu::Plugin::Check::CLI
175
182
 
176
183
  indices_with_sizes = build_indices_with_sizes
177
184
 
178
- oldest = indices_with_sizes.values.flatten.map { |index| index['date'] }.min
185
+ oldest = indices_with_sizes.values.flatten.map { |index| index[:date] }.min
179
186
  indices_to_delete = get_indices_to_delete(oldest, total_bytes_to_delete, indices_with_sizes)
180
187
 
181
- critical "Not enough space, #{total_bytes_to_delete} bytes need to be deleted. Used space in bytes: " \
188
+ if config[:delete]
189
+ client.indices.delete index: indices_to_delete
190
+ ok "Cleaned up space: #{total_bytes_to_delete}"
191
+ else
192
+ critical "Not enough space, #{total_bytes_to_delete} bytes need to be deleted. Used space in bytes: " \
182
193
  "#{used_in_bytes}, Total in bytes: #{total_in_bytes}. Indices to delete: " \
183
194
  "#{indices_to_delete.sort.map { |i| "INDEX[#{i}]" }.join(', ')}"
195
+ end
184
196
  end
185
197
  end
@@ -0,0 +1,290 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-es-query
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks ratio between results of two Elasticsearch queries
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: elasticsearch
17
+ # gem: aws_es_transport
18
+ #
19
+ # USAGE:
20
+ # This example checks the ratio from the count of two different queries
21
+ # as dividend and divisor at the host elasticsearch.service.consul for the past 90 minutes
22
+ # will warn if percentage is lower than 10 and critical if percentage is lower than 5
23
+ # (The invert flag warns if results are _below_ the critical and warning values)
24
+ # check-es-query-ratio.rb -h elasticsearch.service.consul -Q "orders:*"
25
+ # -q "orders:OK" --invert --types special_type -d 'logging-%Y.%m.%d'
26
+ # --minutes-previous 90 -p 9200 -c 5 -w 10
27
+ #
28
+ #
29
+ # NOTES:
30
+ #
31
+ # LICENSE:
32
+ #
33
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
34
+ # for details.
35
+ #
36
+
37
+ require 'sensu-plugin/check/cli'
38
+ require 'elasticsearch'
39
+ require 'time'
40
+ require 'uri'
41
+ require 'aws_es_transport'
42
+ require 'sensu-plugins-elasticsearch'
43
+
44
+ #
45
+ # ES Query Count
46
+ #
47
+ class ESQueryRatio < Sensu::Plugin::Check::CLI
48
+ include ElasticsearchCommon
49
+
50
+ option :index,
51
+ description: 'Elasticsearch indices to query.
52
+ Comma-separated list of index names to search.
53
+ Use `_all` or empty string to perform the operation on all indices.
54
+ Accepts wildcards',
55
+ short: '-i INDEX',
56
+ long: '--indices INDEX'
57
+
58
+ option :transport,
59
+ long: '--transport TRANSPORT',
60
+ description: 'Transport to use to communicate with ES. Use "AWS" for signed AWS transports.'
61
+
62
+ option :region,
63
+ long: '--region REGION',
64
+ description: 'Region (necessary for AWS Transport)'
65
+
66
+ option :types,
67
+ description: 'Elasticsearch types to limit searches to, comma separated list.',
68
+ long: '--types TYPES'
69
+
70
+ option :timestamp_field,
71
+ description: 'Field to use instead of @timestamp for query.',
72
+ long: '--timestamp-field FIELD_NAME',
73
+ default: '@timestamp'
74
+
75
+ option :offset,
76
+ description: 'Seconds before offset to end @timestamp against query.',
77
+ long: '--offset OFFSET',
78
+ proc: proc(&:to_i),
79
+ default: 0
80
+
81
+ option :ignore_unavailable,
82
+ description: 'Ignore unavailable indices.',
83
+ long: '--ignore-unavailable',
84
+ boolean: true,
85
+ default: true
86
+
87
+ option :minutes_previous,
88
+ description: 'Minutes before offset to check @timestamp against query.',
89
+ long: '--minutes-previous MINUTES_PREVIOUS',
90
+ proc: proc(&:to_i),
91
+ default: 0
92
+
93
+ option :hours_previous,
94
+ description: 'Hours before offset to check @timestamp against query.',
95
+ long: '--hours-previous HOURS_PREVIOUS',
96
+ proc: proc(&:to_i),
97
+ default: 0
98
+
99
+ option :days_previous,
100
+ description: 'Days before offset to check @timestamp against query.',
101
+ long: '--days-previous DAYS_PREVIOUS',
102
+ proc: proc(&:to_i),
103
+ default: 0
104
+
105
+ option :weeks_previous,
106
+ description: 'Weeks before offset to check @timestamp against query.',
107
+ long: '--weeks-previous WEEKS_PREVIOUS',
108
+ proc: proc(&:to_i),
109
+ default: 0
110
+
111
+ option :months_previous,
112
+ description: 'Months before offset to check @timestamp against query.',
113
+ long: '--months-previous MONTHS_PREVIOUS',
114
+ proc: proc(&:to_i),
115
+ default: 0
116
+
117
+ option :date_index,
118
+ description: 'Elasticsearch time based index.
119
+ Accepts format from http://ruby-doc.org/core-2.2.0/Time.html#method-i-strftime',
120
+ short: '-d DATE_INDEX',
121
+ long: '--date-index DATE_INDEX'
122
+
123
+ option :date_repeat_daily,
124
+ description: 'Elasticsearch date based index repeats daily.',
125
+ long: '--repeat-daily',
126
+ boolean: true,
127
+ default: true
128
+
129
+ option :date_repeat_hourly,
130
+ description: 'Elasticsearch date based index repeats hourly.',
131
+ long: '--repeat-hourly',
132
+ boolean: true,
133
+ default: false
134
+
135
+ option :search_field,
136
+ description: 'The Elasticsearch document field to search for your query string.',
137
+ short: '-f FIELD',
138
+ long: '--field FIELD',
139
+ required: false,
140
+ default: 'message'
141
+
142
+ option :dividend,
143
+ description: 'Elasticsearch query where percentage is calculated for',
144
+ short: '-Q QUERY',
145
+ long: '--dividend QUERY',
146
+ required: true
147
+
148
+ option :divisor,
149
+ description: 'Elasticsearch query where percentage is calculated from',
150
+ short: '-q QUERY',
151
+ long: '--divisor QUERY',
152
+ required: true
153
+
154
+ option :host,
155
+ description: 'Elasticsearch host',
156
+ short: '-h HOST',
157
+ long: '--host HOST',
158
+ default: 'localhost'
159
+
160
+ option :port,
161
+ description: 'Elasticsearch port',
162
+ short: '-p PORT',
163
+ long: '--port PORT',
164
+ proc: proc(&:to_i),
165
+ default: 9200
166
+
167
+ option :scheme,
168
+ description: 'Elasticsearch connection scheme, defaults to https for authenticated connections',
169
+ short: '-s SCHEME',
170
+ long: '--scheme SCHEME'
171
+
172
+ option :password,
173
+ description: 'Elasticsearch connection password',
174
+ short: '-P PASSWORD',
175
+ long: '--password PASSWORD'
176
+
177
+ option :user,
178
+ description: 'Elasticsearch connection user',
179
+ short: '-u USER',
180
+ long: '--user USER'
181
+
182
+ option :timeout,
183
+ description: 'Elasticsearch query timeout in seconds',
184
+ short: '-t TIMEOUT',
185
+ long: '--timeout TIMEOUT',
186
+ proc: proc(&:to_i),
187
+ default: 30
188
+
189
+ option :warn,
190
+ short: '-w N',
191
+ long: '--warn N',
192
+ description: 'Result count WARNING threshold',
193
+ proc: proc(&:to_i),
194
+ default: 0
195
+
196
+ option :crit,
197
+ short: '-c N',
198
+ long: '--crit N',
199
+ description: 'Result count CRITICAL threshold',
200
+ proc: proc(&:to_i),
201
+ default: 0
202
+
203
+ option :invert,
204
+ long: '--invert',
205
+ description: 'Invert thresholds',
206
+ boolean: true
207
+
208
+ option :kibana_url,
209
+ long: '--kibana-url KIBANA_URL',
210
+ description: 'Kibana URL query prefix that will be in critical / warning response output.'
211
+
212
+ def kibana_info
213
+ kibana_date_format = '%Y-%m-%dT%H:%M:%S.%LZ'
214
+ unless config[:kibana_url].nil?
215
+ index = config[:index]
216
+ unless config[:date_index].nil?
217
+ date_index_partition = config[:date_index].split('%')
218
+ index = "[#{date_index_partition.first}]" \
219
+ "#{date_index_partition[1..-1].join.sub('Y', 'YYYY').sub('y', 'YY').sub('m', 'MM').sub('d', 'DD').sub('j', 'DDDD').sub('H', 'hh')}"
220
+ end
221
+ end_time = Time.now.utc.to_i
222
+ start_time = end_time
223
+ if config[:minutes_previous] != 0
224
+ start_time -= (config[:minutes_previous] * 60)
225
+ end
226
+ if config[:hours_previous] != 0
227
+ start_time -= (config[:hours_previous] * 60 * 60)
228
+ end
229
+ if config[:days_previous] != 0
230
+ start_time -= (config[:days_previous] * 60 * 60 * 24)
231
+ end
232
+ if config[:weeks_previous] != 0
233
+ start_time -= (config[:weeks_previous] * 60 * 60 * 24 * 7)
234
+ end
235
+ if config[:months_previous] != 0
236
+ start_time -= (config[:months_previous] * 60 * 60 * 24 * 7 * 31)
237
+ end
238
+ "Kibana logs: #{config[:kibana_url]}/#/discover?_g=" \
239
+ "(refreshInterval:(display:Off,section:0,value:0),time:(from:'" \
240
+ "#{URI.escape(Time.at(start_time).utc.strftime kibana_date_format)}',mode:absolute,to:'" \
241
+ "#{URI.escape(Time.at(end_time).utc.strftime kibana_date_format)}'))&_a=(columns:!(_source),index:" \
242
+ "#{URI.escape(index)},interval:auto,query:(query_string:(analyze_wildcard:!t,query:'" \
243
+ "#{URI.escape(config[:query])}')),sort:!('@timestamp',desc))&dummy"
244
+ end
245
+ end
246
+
247
+ def run
248
+ dividend_query = config[:dividend]
249
+ divisor_query = config[:divisor]
250
+ config.delete(:dividend)
251
+ config.delete(:divisor)
252
+ config[:query] = dividend_query
253
+ dividend = client.count(build_request_options)
254
+ config[:query] = divisor_query
255
+ divisor = client.count(build_request_options)
256
+ if divisor == 0
257
+ critical 'Divisor is 0, ratio check cannot be performed, raising an alert'
258
+ else
259
+ response = {}
260
+ response['count'] = (dividend['count'] / divisor['count']).round
261
+ end
262
+ if config[:invert]
263
+ if response['count'] < config[:crit]
264
+ critical "Query count (#{response['count']}) was below critical threshold. #{kibana_info}"
265
+ elsif response['count'] < config[:warn]
266
+ warning "Query count (#{response['count']}) was below warning threshold. #{kibana_info}"
267
+ else
268
+ ok "Query count (#{response['count']}) was ok"
269
+ end
270
+ elsif response['count'] > config[:crit]
271
+ critical "Query count (#{response['count']}) was above critical threshold. #{kibana_info}"
272
+ elsif response['count'] > config[:warn]
273
+ warning "Query count (#{response['count']}) was above warning threshold. #{kibana_info}"
274
+ else
275
+ ok "Query count (#{response['count']}) was ok"
276
+ end
277
+ rescue Elasticsearch::Transport::Transport::Errors::NotFound
278
+ if config[:invert]
279
+ if response['count'] < config[:crit]
280
+ critical "Query count (#{response['count']}) was below critical threshold. #{kibana_info}"
281
+ elsif response['count'] < config[:warn]
282
+ warning "Query count (#{response['count']}) was below warning threshold. #{kibana_info}"
283
+ else
284
+ ok "Query count (#{response['count']}) was ok"
285
+ end
286
+ else
287
+ ok 'No results found, count was below thresholds'
288
+ end
289
+ end
290
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsElasticsearch
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 0
4
+ MINOR = 1
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-elasticsearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -53,33 +53,45 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.1'
55
55
  - !ruby/object:Gem::Dependency
56
- name: sensu-plugin
56
+ name: aws-sdk
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.14
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '2.5'
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '1.2'
67
+ version: '2.1'
62
68
  type: :runtime
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.1.14
75
+ - - "<"
76
+ - !ruby/object:Gem::Version
77
+ version: '2.5'
66
78
  - - "~>"
67
79
  - !ruby/object:Gem::Version
68
- version: '1.2'
80
+ version: '2.1'
69
81
  - !ruby/object:Gem::Dependency
70
- name: json
82
+ name: sensu-plugin
71
83
  requirement: !ruby/object:Gem::Requirement
72
84
  requirements:
73
85
  - - "~>"
74
86
  - !ruby/object:Gem::Version
75
- version: '1.8'
87
+ version: '1.2'
76
88
  type: :runtime
77
89
  prerelease: false
78
90
  version_requirements: !ruby/object:Gem::Requirement
79
91
  requirements:
80
92
  - - "~>"
81
93
  - !ruby/object:Gem::Version
82
- version: '1.8'
94
+ version: '1.2'
83
95
  - !ruby/object:Gem::Dependency
84
96
  name: bundler
85
97
  requirement: !ruby/object:Gem::Requirement
@@ -222,6 +234,7 @@ executables:
222
234
  - check-es-node-status.rb
223
235
  - check-es-query-count.rb
224
236
  - check-es-query-exists.rb
237
+ - check-es-query-ratio.rb
225
238
  - check-es-shard-allocation-status.rb
226
239
  - handler-es-delete-indices.rb
227
240
  - metrics-es-cluster.rb
@@ -243,6 +256,7 @@ files:
243
256
  - bin/check-es-node-status.rb
244
257
  - bin/check-es-query-count.rb
245
258
  - bin/check-es-query-exists.rb
259
+ - bin/check-es-query-ratio.rb
246
260
  - bin/check-es-shard-allocation-status.rb
247
261
  - bin/handler-es-delete-indices.rb
248
262
  - bin/metrics-es-cluster.rb
@@ -278,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
278
292
  version: '0'
279
293
  requirements: []
280
294
  rubyforge_project:
281
- rubygems_version: 2.5.1
295
+ rubygems_version: 2.4.5
282
296
  signing_key:
283
297
  specification_version: 4
284
298
  summary: Sensu plugins for elasticsearch