sensu-plugins-mesos 2.4.0 → 2.5.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: 66f974c1746c5c76ec41774dfa2d2c883be9ec69833343ca8d059dbe1ed81fb7
4
- data.tar.gz: 21d72c1e2cdd1b959b99cfb1e86638d8d6511b690b9b726b9ac166724198c206
3
+ metadata.gz: c0455a91f822ab180c60c318b9b45bc7827d0275864aa216b6a0ce38130a2172
4
+ data.tar.gz: f1a8f7e299a7cca50ced16d55c5693cec9c57c13488a40af8a75989bb1aeeb4e
5
5
  SHA512:
6
- metadata.gz: c3f7a279c708dd1601b34b0b40b08da212b8c3f28de668b27756328889d1246ac0ad622b083549bf8eb587ec2c1ce81982a40e315b4b82f2849d01c2f8f5d90c
7
- data.tar.gz: 2fb9fe06014643337d6b4af8daea52e3596df0cea134b1aeafad721f8a5041f62732a1d3e4107591cd5dcb68e079a79b834fec9d9eb594fa1cea74b5838c8096
6
+ metadata.gz: ea6fcb40f99c999daecb92fb89a35906980da5af6fbd24b0838c4b9792006405cd6314d0337be1642a9cb9b436e4a38142405b269c0cc9dff57b3a4c2fc514de
7
+ data.tar.gz: 603c621b9a19813cf0a67ea8d4aa6a1795d8bff83866b6f7a1a5673d2b15f6c7c7da174bff9863e62f3c906753dc717d9664d13ffac338138ddd543b25c9a0cb
@@ -5,6 +5,13 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [2.5.0] - 2018-09-10
9
+ ### Fixed
10
+ - check-marathon-apps.rb: script should not fail on first faulty result (@bergerx)
11
+
12
+ ### Added
13
+ - check-marathon-apps.rb: introduced `check-config-overrides` flag (@bergerx)
14
+
8
15
  ## [2.4.0] - 2018-03-20
9
16
  ### Changed
10
17
  - check-marathon-apps.rb: minor fixes and documentation update for this check (@bergerx)
@@ -98,7 +105,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
98
105
  ### Added
99
106
  - initial release
100
107
 
101
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/2.4.0...HEAD
108
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/2.5.0...HEAD
109
+ [2.5.0]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/2.4.0...2.5.0
102
110
  [2.4.0]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/2.3.0...2.4.0
103
111
  [2.3.0]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/2.2.2...2.3.0
104
112
  [2.2.2]: https://github.com/sensu-plugins/sensu-plugins-mesos/compare/2.1.2...2.2.2
data/README.md CHANGED
@@ -38,7 +38,10 @@ another check result for the apps `status`.
38
38
  Check results can be customised by two ways:
39
39
 
40
40
  1. Default check result fields thats applied to all will be provided by a
41
- default check config. Please see th esource code to see the whole defaults.
41
+ default check config. Please see the source code to see the whole defaults.
42
+ Since the whole default check config tends to be big, you can also use
43
+ `check-config-overrides` flag just to provide few new fields or override
44
+ existing defaults.
42
45
  2. Application owners can override check results by using marathon labels. This
43
46
  allows each application to have different fields in the published result.
44
47
  e.g. per app escalation or aggregate can be controlled by applying Marathon
@@ -172,6 +172,13 @@ class MarathonAppsCheck < Sensu::Plugin::Check::CLI
172
172
  description: 'Similar to `--default-check-config` but read from given file. If both parameters are provided '\
173
173
  '`--default-check-config` will override this one.'
174
174
 
175
+ option :check_config_overrides,
176
+ long: '--check-config-overrides CHECK_CONFIG_OVERRIDES',
177
+ description: 'Instead of providing whole default-check-config if you just want to introduce some new fields '\
178
+ 'to the check config without having to provide whole config, this will be merged to the '\
179
+ 'default-check-config.',
180
+ default: '{}'
181
+
175
182
  option :sensu_client_url,
176
183
  description: 'Sensu client HTTP URL',
177
184
  long: '--sensu-client-url url',
@@ -203,57 +210,78 @@ class MarathonAppsCheck < Sensu::Plugin::Check::CLI
203
210
  else
204
211
  DEFAULT_CHECK_CONFIG
205
212
  end
206
- check_config = parse_json(check_config_str)
213
+ default_check_config = parse_json(check_config_str)
214
+ check_config_overrides = parse_json(config[:check_config_overrides])
215
+ check_config = default_check_config.merge(check_config_overrides)
207
216
 
208
217
  # Filter apps, if both exists exclude pattern will override match pattern
209
218
  apps.keep_if { |app| app['id'][/#{config[:match_pattern]}/] } if config[:match_pattern]
210
219
  apps.delete_if { |app| app['id'][/#{config[:exclude_pat]}/] } if config[:exclude_pat]
211
220
 
221
+ failed_apps_to_be_reported = 0
212
222
  apps.each do |app|
213
- # Select app queue if any
214
- app_queue = queue.select { |q| q['app']['id'][/^#{app['id']}$/] }.to_a.first
215
-
216
- # Build check result
217
- check_result = check_result_scaffold(app)
218
-
219
- # Parse Marathon app labels
220
- labels_config = parse_app_labels(app['labels'].to_h)
221
-
222
- REFERENCES.each do |reference|
223
- # / is and invalid character
224
- check_result['name'] = "check_marathon_app#{app['id'].tr('/', '_')}_#{reference}"
225
-
226
- state = case reference
227
- when 'health'
228
- get_marathon_app_health(app)
229
- when 'status'
230
- get_marathon_app_status(app, app_queue.to_h)
231
- end
232
-
233
- # Merge user provided check config
234
- check_result.merge!(check_config.dig('_').to_h)
235
- check_result.merge!(check_config.dig(reference, '_').to_h)
236
- check_result.merge!(check_config.dig(reference, state).to_h)
237
-
238
- # Merge Marathon parsed check config
239
- check_result.merge!(labels_config.dig('_').to_h)
240
- check_result.merge!(labels_config.dig(reference, '_').to_h)
241
- check_result.merge!(labels_config.dig(reference, state).to_h)
242
-
243
- # Build check result output
244
- check_result['output'] = "#{reference.upcase} #{state.capitalize} - "\
245
- "tasksRunning(#{app['tasksRunning'].to_i}), tasksStaged(#{app['tasksStaged'].to_i}), "\
246
- "tasksHealthy(#{app['tasksHealthy'].to_i}), tasksUnhealthy(#{app['tasksUnhealthy'].to_i})"
247
-
248
- # Make sure that check result data types are correct
249
- enforce_sensu_field_types(check_result)
250
-
251
- # Send the result to sensu-client HTTP socket
252
- post_check_result(check_result)
253
- end
223
+ failed_apps_to_be_reported += 1 unless process_app_results(app, queue, check_config)
224
+ end
225
+
226
+ if failed_apps_to_be_reported > 0
227
+ critical "#{failed_apps_to_be_reported} apps are failed to be reported to sensu"
228
+ else
229
+ ok 'Marathon Apps Status and Health check is running properly'
254
230
  end
231
+ end
232
+
233
+ def process_app_results(app, queue, check_config)
234
+ app_result_pushed = true
235
+
236
+ # Select app queue if any
237
+ app_queue = queue.select { |q| q['app']['id'][/^#{app['id']}$/] }.to_a.first
238
+
239
+ # Build check result
240
+ check_result = check_result_scaffold(app)
255
241
 
256
- ok 'Marathon Apps Status and Health check is running properly'
242
+ # Parse Marathon app labels
243
+ labels_config = parse_app_labels(app['labels'].to_h)
244
+
245
+ REFERENCES.each do |reference|
246
+ # / is and invalid character
247
+ check_result['name'] = "check_marathon_app#{app['id'].tr('/', '_')}_#{reference}"
248
+
249
+ state = case reference
250
+ when 'health'
251
+ get_marathon_app_health(app)
252
+ when 'status'
253
+ get_marathon_app_status(app, app_queue.to_h)
254
+ end
255
+
256
+ # Merge user provided check config
257
+ check_result.merge!(check_config.dig('_').to_h)
258
+ check_result.merge!(check_config.dig(reference, '_').to_h)
259
+ check_result.merge!(check_config.dig(reference, state).to_h)
260
+
261
+ # Merge Marathon parsed check config
262
+ check_result.merge!(labels_config.dig('_').to_h)
263
+ check_result.merge!(labels_config.dig(reference, '_').to_h)
264
+ check_result.merge!(labels_config.dig(reference, state).to_h)
265
+
266
+ # Build check result output
267
+ check_result['output'] = "#{reference.upcase} #{state.capitalize} - "\
268
+ "tasksRunning(#{app['tasksRunning'].to_i}), tasksStaged(#{app['tasksStaged'].to_i}), "\
269
+ "tasksHealthy(#{app['tasksHealthy'].to_i}), tasksUnhealthy(#{app['tasksUnhealthy'].to_i})"
270
+
271
+ # Make sure that check result data types are correct
272
+ enforce_sensu_field_types(check_result)
273
+
274
+ # Send the result to sensu-client HTTP socket
275
+ app_result = post_check_result(check_result)
276
+
277
+ # mark if result cant be posted to sensu
278
+ app_result_pushed = if app_result_pushed && app_result
279
+ true
280
+ else
281
+ false
282
+ end
283
+ end
284
+ app_result_pushed
257
285
  end
258
286
 
259
287
  def check_result_scaffold(app)
@@ -311,8 +339,11 @@ class MarathonAppsCheck < Sensu::Plugin::Check::CLI
311
339
  data.to_json,
312
340
  content_type: 'application/json',
313
341
  timeout: config[:timeout])
342
+ true
314
343
  rescue RestClient::ExceptionWithResponse => e
315
- critical "Error while trying to POST check result (#{config[:sensu_client_url]}/results): #{e.response}"
344
+ # print a message about failing POST but keep going
345
+ STDERR.puts "Error while trying to POST check result for #{data} (#{config[:sensu_client_url]}/results): #{e.response}"
346
+ false
316
347
  end
317
348
 
318
349
  def parse_json(json)
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsMesos
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 4
4
+ MINOR = 5
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-mesos
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.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-03-21 00:00:00.000000000 Z
11
+ date: 2018-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -332,7 +332,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
332
332
  version: '0'
333
333
  requirements: []
334
334
  rubyforge_project:
335
- rubygems_version: 2.7.6
335
+ rubygems_version: 2.7.7
336
336
  signing_key:
337
337
  specification_version: 4
338
338
  summary: Sensu plugins for checking mesos