sensu-plugins-elasticsearch 1.11.1 → 1.12.0

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
  SHA256:
3
- metadata.gz: 43a77c2890ac390f9a87543c86a1897318dac09570490a3f5fa9b6fc751feee2
4
- data.tar.gz: 6dda58f8156f3d22e5b9edc66172d0dd104cd1fc6ff42fd1acefb8e7cefa877b
3
+ metadata.gz: f4c7f8edc916e17c7ba571ef98759d0baaa87e911775ae2937add42081d731ba
4
+ data.tar.gz: 824f94d88b00f0fe2d0c569e4e081c9e6963b24a2bc2ef178f57a0918a4f35e6
5
5
  SHA512:
6
- metadata.gz: 7337b49b8aa4e86faf4dc5b5987d4cbf57e637b1945d137fb5e9dd0b0c621ce5c4d512fa4c54f501370e12d7b5f307da7e804e3c432fa1a5d0db66c0ef7acff5
7
- data.tar.gz: ad46dc14ab20e5424e5004f4a226b21e0ef6a32811de528fd943238eb7d36bf2a8b867230558f31050c61917a0f1ebab537c2dacefcf1f9eb0898dba3653f20a
6
+ metadata.gz: 50443d93f7171a791e8ed2c766407137c956d138ae5adbed7fb3138c1985e130aeda6133521b7ef711fb7a94ff2bd083fc18fb01d693b282b8b705c0abdd8c18
7
+ data.tar.gz: bdc41027de05096a2b75146cc4c36bcedb89e11004204026c2d062422c6a5849d220a6050f868b5416744d395c857a34b87e09dd57964b4dfb769c53a5f4da23
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [1.12.0] - 2018-03-01
9
+ ### Added
10
+ - check-es-indices-field-number.rb: check if the number of fields in index(es) is approaching limit (default to 1000 in ES) (@huynt1979)
11
+ ### Changed
12
+ - Address a couple of rubocop style violations (@huynt1979)
13
+
8
14
  ## [1.11.1] - 2018-02-27
9
15
  ### Changed
10
16
  - this is a no-op release to test the CI pipeline's ability to publish gems
@@ -230,7 +236,9 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
230
236
  - initial release
231
237
 
232
238
 
233
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.11.0...HEAD
239
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.12.0...HEAD
240
+ [1.12.0]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.11.1...1.12.0
241
+ [1.11.1]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.11.0...1.11.1
234
242
  [1.11.0]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.10.0...1.11.0
235
243
  [1.10.0]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.9.0...1.10.0
236
244
  [1.9.0]: https://github.com/sensu-plugins/sensu-plugins-elasticsearch/compare/1.8.1...1.9.0
data/README.md CHANGED
@@ -14,6 +14,7 @@
14
14
  * /bin/check-es-cluster-status.rb
15
15
  * /bin/check-es-file-descriptors.rb
16
16
  * /bin/check-es-heap.rb
17
+ * /bin/check-es-indices-field-count.rb
17
18
  * /bin/check-es-indexes.rb
18
19
  * /bin/check-es-indicies-sizes.rb
19
20
  * /bin/check-es-node-status.rb
@@ -42,13 +43,13 @@ Note: The test suite uses an elasticsearch instance in order to have passing tes
42
43
 
43
44
  ```bash
44
45
  docker run -d --name sensu-elasticsearch-6 docker.elastic.co/elasticsearch/elasticsearch:6.2.2
45
- ```
46
+ ```
46
47
 
47
48
  Running the tests:
48
49
 
49
50
  ```bash
50
51
  bundle install --path vendor/bundle
51
52
  bundle exec kitchen test
52
- ```
53
+ ```
53
54
 
54
- You can find sample output for all tests running successfully in [this gist](https://gist.github.com/alexandrustaetu/d19feea1296d2ce7e367542265252d7a).
55
+ You can find sample output for all tests running successfully in [this gist](https://gist.github.com/alexandrustaetu/d19feea1296d2ce7e367542265252d7a).
@@ -0,0 +1,194 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-es-indices-field-count
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks if the number of fields in ES index(es) is approaching limit. ES by default
7
+ # puts this limit at 1000 fields per index.
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # This example checks if the number of fields for an index is reaching its limit set in
20
+ # index.mapping.total_fields.limit. This check takes as paramater the index name or
21
+ # comma-separated list of indices, and optionally the type to check on. If type is not specified,
22
+ # all types in index are examined.
23
+ # You can also specify an optional value for the limit. When omitted, this will default to 1000.
24
+ #
25
+ # check-es-indices-field-count.rb -h <hostname or ip> -p 9200
26
+ # -i <index1>,<index2> --types <type_in_index> -w <pct> -c <pct>
27
+ #
28
+ # If any indices crossing the specified thresholds (warning/critical), beside the appropriate return code
29
+ # this check will also output a list of indices with the violated percentage for further troubleshooting.
30
+ # NOTES:
31
+ #
32
+ # LICENSE:
33
+ # CloudCruiser <devops@hpe.com>
34
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
35
+ # for details.
36
+ #
37
+
38
+ require 'sensu-plugin/check/cli'
39
+ require 'elasticsearch'
40
+ require 'sensu-plugins-elasticsearch'
41
+ require 'json'
42
+
43
+ #
44
+ # ES Indices Field Count
45
+ #
46
+ class ESIndicesFieldCount < Sensu::Plugin::Check::CLI
47
+ include ElasticsearchCommon
48
+
49
+ option :host,
50
+ description: 'Elasticsearch host',
51
+ short: '-h HOST',
52
+ long: '--host HOST',
53
+ default: 'localhost'
54
+
55
+ option :port,
56
+ description: 'Elasticsearch port',
57
+ short: '-p PORT',
58
+ long: '--port PORT',
59
+ proc: proc(&:to_i),
60
+ default: 9200
61
+
62
+ option :scheme,
63
+ description: 'Elasticsearch connection scheme, defaults to https for authenticated connections',
64
+ short: '-s SCHEME',
65
+ long: '--scheme SCHEME'
66
+
67
+ option :password,
68
+ description: 'Elasticsearch connection password',
69
+ short: '-P PASSWORD',
70
+ long: '--password PASSWORD'
71
+
72
+ option :user,
73
+ description: 'Elasticsearch connection user',
74
+ short: '-u USER',
75
+ long: '--user USER'
76
+
77
+ option :timeout,
78
+ description: 'Elasticsearch query timeout in seconds',
79
+ short: '-t TIMEOUT',
80
+ long: '--timeout TIMEOUT',
81
+ proc: proc(&:to_i),
82
+ default: 30
83
+
84
+ option :index,
85
+ description: 'Elasticsearch indices to check against.
86
+ Comma-separated list of index names to search.
87
+ Default to `_all` if omitted. Accepts wildcards',
88
+ short: '-i INDEX',
89
+ long: '--indices INDEX',
90
+ default: '_all'
91
+
92
+ option :types,
93
+ description: 'Elasticsearch types of index to check against.
94
+ Comma-separated list of types. When omitted, all types are checked against.',
95
+ short: '-T TYPES',
96
+ long: '--types TYPES'
97
+
98
+ option :limit,
99
+ description: 'Default number of fields limit to compare against.
100
+ Elasticsearch defaults this to 1000 if none is specied in index setting.',
101
+ short: '-l',
102
+ long: '--limit LIMIT',
103
+ proc: proc(&:to_i),
104
+ default: 1000
105
+
106
+ option :warn,
107
+ short: '-w PCT',
108
+ long: '--warn PCT',
109
+ description: 'WARNING threshold in percentage',
110
+ proc: proc(&:to_f),
111
+ default: 85.0
112
+
113
+ option :crit,
114
+ short: '-c N',
115
+ long: '--crit N',
116
+ description: 'CRITICAL threshold in percentage',
117
+ proc: proc(&:to_f),
118
+ default: 95.0
119
+
120
+ def indexfieldcount
121
+ index_field_count = {}
122
+ mappings = client.indices.get_mapping index: config[:index], type: config[:types]
123
+ mappings.each do |index, index_mapping|
124
+ unless index_mapping['mappings'].nil?
125
+ type_field_count = {}
126
+ index_mapping['mappings'].each do |type, type_mapping|
127
+ fieldcount = if type_mapping['properties'].nil?
128
+ 0
129
+ else
130
+ type_mapping['properties'].length
131
+ end
132
+ type_field_count[type] = fieldcount
133
+ end
134
+
135
+ index_field_count[index] = type_field_count
136
+ end
137
+ end
138
+
139
+ index_field_count
140
+ end
141
+
142
+ def fieldlimitsetting
143
+ field_limit_setting = {}
144
+ settings = client.indices.get_settings index: config[:index]
145
+ settings.each do |index, index_setting|
146
+ index_field_limit = index_setting['settings']['index.mapping.total_fields.limit']
147
+ # when no index.mapping.total_fields.limit, use value of the limit parameter, which defaults to 1000.
148
+ index_field_limit = config[:limit] if index_field_limit.nil?
149
+ field_limit_setting[index] = { 'limit' => index_field_limit }
150
+ end
151
+
152
+ field_limit_setting
153
+ end
154
+
155
+ def run
156
+ fieldcounts = indexfieldcount
157
+ limits = fieldlimitsetting
158
+
159
+ warnings = {}
160
+ criticals = {}
161
+
162
+ if fieldcounts.empty?
163
+ unknown "Can't find any indices."
164
+ end
165
+
166
+ fieldcounts.each do |index, counts|
167
+ counts.each do |type, count|
168
+ pct = count.to_f / limits[index]['limit'] * 100
169
+
170
+ if config[:warn] <= pct && pct < config[:crit]
171
+ warnings[index] = {} if warnings[index].nil?
172
+ warnings[index][type] = pct.round(2)
173
+ end
174
+
175
+ if config[:crit] <= pct
176
+ criticals[index] = {} if criticals[index].nil?
177
+ criticals[index][type] = pct.round(2)
178
+ end
179
+ end
180
+ end
181
+
182
+ unless criticals.empty?
183
+ critical "Number of fields in indices is at critical level.
184
+ #{JSON.pretty_generate(criticals)}"
185
+ end
186
+
187
+ unless warnings.empty?
188
+ warning "Number of fields in indices is at warning level.
189
+ #{JSON.pretty_generate(warnings)}"
190
+ end
191
+
192
+ ok
193
+ end
194
+ end
@@ -159,11 +159,12 @@ class ESCheckIndicesSizes < Sensu::Plugin::Check::CLI
159
159
  def run
160
160
  node_fs_stats = client.nodes.stats metric: 'fs,indices'
161
161
  nodes_being_used = node_fs_stats['nodes'].values.select { |node| node['indices']['store']['size_in_bytes'] > 0 }
162
+
162
163
  # TODO: come back and cleanup all these rubocop disables with a little refactor
163
- # rubocop:disable Style/SingleLineBlockParams
164
- used_in_bytes = nodes_being_used.map { |node| node['fs']['data'].map { |data| data['total_in_bytes'] - data['available_in_bytes'] }.flatten }.flatten.inject { |sum, x| sum + x } # rubocop:disable LineLength
164
+ # rubocop:disable Style/SingleLineBlockParams,Metrics/LineLength
165
+ used_in_bytes = nodes_being_used.map { |node| node['fs']['data'].map { |data| data['total_in_bytes'] - data['available_in_bytes'] }.flatten }.flatten.inject { |sum, x| sum + x }
165
166
  total_in_bytes = nodes_being_used.map { |node| node['fs']['data'].map { |data| data['total_in_bytes'] }.flatten }.flatten.inject { |sum, x| sum + x }
166
- # rubocop:enable Style/SingleLineBlockParams LineLength
167
+ # rubocop:enable Style/SingleLineBlockParams,Metrics/LineLength
167
168
 
168
169
  if config[:maximum_megabytes] > 0
169
170
  target_bytes_used = config[:maximum_megabytes] * 1_000_000
@@ -134,11 +134,11 @@ module ElasticsearchQuery
134
134
  end
135
135
 
136
136
  def es_date_math_string(end_time)
137
- if config[:minutes_previous] == 0 && \
138
- config[:hours_previous] == 0 && \
139
- config[:days_previous] == 0 && \
140
- config[:weeks_previous] == 0 && \
141
- config[:months_previous] == 0
137
+ if config[:minutes_previous].zero? && \
138
+ config[:hours_previous].zero? && \
139
+ config[:days_previous].zero? && \
140
+ config[:weeks_previous].zero? && \
141
+ config[:months_previous].zero?
142
142
  nil
143
143
  else
144
144
  es_math = "#{end_time.strftime '%Y-%m-%dT%H:%M:%S'}||"
@@ -1,8 +1,8 @@
1
1
  module SensuPluginsElasticsearch
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 11
5
- PATCH = 1
4
+ MINOR = 12
5
+ PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
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.11.1
4
+ version: 1.12.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: 2018-02-28 00:00:00.000000000 Z
11
+ date: 2018-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-es-transport
@@ -262,6 +262,7 @@ executables:
262
262
  - check-es-indices-sizes.rb
263
263
  - metrics-es-node-graphite.rb
264
264
  - check-es-circuit-breakers.rb
265
+ - check-es-indices-field-count.rb
265
266
  - check-es-query-count.rb
266
267
  - check-es-query-exists.rb
267
268
  - check-es-shard-allocation-status.rb
@@ -281,6 +282,7 @@ files:
281
282
  - bin/check-es-file-descriptors.rb
282
283
  - bin/check-es-heap.rb
283
284
  - bin/check-es-indexes.rb
285
+ - bin/check-es-indices-field-count.rb
284
286
  - bin/check-es-indices-sizes.rb
285
287
  - bin/check-es-node-status.rb
286
288
  - bin/check-es-query-average.rb