sensu 0.22.0-java → 0.22.1-java

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: 73757e84a5155b38c15ce352679aa2eca78f1997
4
- data.tar.gz: 649ab07db89ac71d47a6da2356a80745dd72e0d1
3
+ metadata.gz: c651d2f52905f365c70aca036d7f2d20664f85b7
4
+ data.tar.gz: 93699da175d7769f06d050fa310071a0126bb4c3
5
5
  SHA512:
6
- metadata.gz: 0d668a4a69cd27e43d3616d75003139e3657844034a25ebea67f4674e0a39ca3172b7ceaf5aadbcc066e804c40203009100befe1b8a00f1e28939bbe9e6154b2
7
- data.tar.gz: d01dd07906de000ded0042f79bbeee09ef7379d9192b80f822f383f098d162e11935f8fe1b678ef93bdcd4c7219e4c5ee84a1d5305a5e32c6a545866982805f0
6
+ metadata.gz: f5ec81b81a6b3a844e853fda4b1b49c9d08dacd16adb3ff4874bb22e84803c006f7cb55d2ee269f0a8edd2e01f44f7d380f8022ca92a7467c441ef7c28284b1a
7
+ data.tar.gz: 0b43edb919da5426f5416f198f1a5ddf83a3fb59e27157884c0cabaa3655f3dc83f080650088df9ef4e23199eaac19f0b509939c17293959c8e46fa7d2ecaa13
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 0.22.1 - 2016-03-01
2
+
3
+ ### Other
4
+
5
+ Performance improvements. Using frozen constants for common values and
6
+ comparisons. Reduced the use of block arguments for callbacks.
7
+
8
+ Improved RabbitMQ transport channel error handling.
9
+
10
+ Fixed client signatures inspection/comparison when upgrading from a
11
+ previous release.
12
+
1
13
  ## 0.22.0 - 2016-01-29
2
14
 
3
15
  ### Features
@@ -65,11 +65,11 @@ module Sensu
65
65
  @thin.start
66
66
  end
67
67
 
68
- def stop_server(&callback)
68
+ def stop_server
69
69
  @thin.stop
70
70
  retry_until_true do
71
71
  unless @thin.running?
72
- callback.call
72
+ yield
73
73
  true
74
74
  end
75
75
  end
@@ -171,7 +171,7 @@ module Sensu
171
171
  body ""
172
172
  end
173
173
 
174
- def read_data(rules={}, &callback)
174
+ def read_data(rules={})
175
175
  begin
176
176
  data = MultiJson.load(env["rack.input"].read)
177
177
  valid = rules.all? do |key, rule|
@@ -181,7 +181,7 @@ module Sensu
181
181
  (rule[:regex] && (value =~ rule[:regex]) == 0)
182
182
  end
183
183
  if valid
184
- callback.call(data)
184
+ yield(data)
185
185
  else
186
186
  bad_request!
187
187
  end
@@ -210,7 +210,7 @@ module Sensu
210
210
  end
211
211
  end
212
212
 
213
- def transport_info(&callback)
213
+ def transport_info
214
214
  info = {
215
215
  :keepalives => {
216
216
  :messages => nil,
@@ -227,11 +227,11 @@ module Sensu
227
227
  info[:keepalives] = stats
228
228
  settings.transport.stats("results") do |stats|
229
229
  info[:results] = stats
230
- callback.call(info)
230
+ yield(info)
231
231
  end
232
232
  end
233
233
  else
234
- callback.call(info)
234
+ yield(info)
235
235
  end
236
236
  end
237
237
 
@@ -369,13 +369,13 @@ module Sensu
369
369
  # check the condition every 0.5 seconds until `true` is
370
370
  # returned.
371
371
  #
372
- # @param callback [Proc] called when there are no check
372
+ # @yield [] callback/block called when there are no check
373
373
  # executions in progress.
374
- def complete_checks_in_progress(&callback)
374
+ def complete_checks_in_progress
375
375
  @logger.info("completing checks in progress", :checks_in_progress => @checks_in_progress)
376
376
  retry_until_true do
377
377
  if @checks_in_progress.empty?
378
- callback.call
378
+ yield
379
379
  true
380
380
  end
381
381
  end
@@ -68,6 +68,9 @@ module Sensu
68
68
  # chunks of data in this mode, the connection is being closed.
69
69
  MODE_REJECT = :REJECT
70
70
 
71
+ # PING request string, identifying a connection ping request.
72
+ PING_REQUEST = "ping".freeze
73
+
71
74
  # Initialize instance variables that will be used throughout the
72
75
  # lifetime of the connection. This method is called when the
73
76
  # network connection has been established, and immediately after
@@ -184,7 +187,7 @@ module Sensu
184
187
  #
185
188
  # @param [String] data to be processed.
186
189
  def process_data(data)
187
- if data.strip == "ping"
190
+ if data.strip == PING_REQUEST
188
191
  @logger.debug("socket received ping")
189
192
  respond("pong")
190
193
  else
@@ -1,12 +1,12 @@
1
1
  module Sensu
2
2
  unless defined?(Sensu::VERSION)
3
3
  # Sensu release version.
4
- VERSION = "0.22.0"
4
+ VERSION = "0.22.1".freeze
5
5
 
6
6
  # Sensu check severities.
7
- SEVERITIES = %w[ok warning critical unknown]
7
+ SEVERITIES = %w[ok warning critical unknown].freeze
8
8
 
9
9
  # Process signals that trigger a Sensu process stop.
10
- STOP_SIGNALS = %w[INT TERM]
10
+ STOP_SIGNALS = %w[INT TERM].freeze
11
11
  end
12
12
  end
data/lib/sensu/daemon.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  require "rubygems"
2
2
 
3
3
  gem "multi_json", "1.11.2"
4
- gem "eventmachine", "1.0.8"
4
+ gem "eventmachine", "1.0.9.1"
5
5
 
6
6
  gem "sensu-logger", "1.1.0"
7
7
  gem "sensu-settings", "3.3.0"
8
8
  gem "sensu-extension", "1.3.0"
9
9
  gem "sensu-extensions", "1.4.0"
10
- gem "sensu-transport", "3.3.0"
11
- gem "sensu-spawn", "1.6.0"
10
+ gem "sensu-transport", "4.0.0"
11
+ gem "sensu-spawn", "1.7.0"
12
12
 
13
13
  require "time"
14
14
  require "uri"
@@ -228,21 +228,24 @@ module Sensu
228
228
  #
229
229
  # @param filter_name [String]
230
230
  # @param event [Hash]
231
- # @param callback [Proc]
232
- def event_filter(filter_name, event, &callback)
231
+ # @yield [filtered] callback/block called with a single
232
+ # parameter to indicate if the event was filtered.
233
+ # @yieldparam filtered [TrueClass,FalseClass] indicating if the
234
+ # event was filtered.
235
+ def event_filter(filter_name, event)
233
236
  case
234
237
  when @settings.filter_exists?(filter_name)
235
238
  filter = @settings[:filters][filter_name]
236
239
  matched = filter_attributes_match?(filter[:attributes], event)
237
- callback.call(filter[:negate] ? matched : !matched)
240
+ yield(filter[:negate] ? matched : !matched)
238
241
  when @extensions.filter_exists?(filter_name)
239
242
  extension = @extensions[:filters][filter_name]
240
243
  extension.safe_run(event) do |output, status|
241
- callback.call(status == 0)
244
+ yield(status == 0)
242
245
  end
243
246
  else
244
247
  @logger.error("unknown filter", :filter_name => filter_name)
245
- callback.call(false)
248
+ yield(false)
246
249
  end
247
250
  end
248
251
 
@@ -255,23 +258,26 @@ module Sensu
255
258
  #
256
259
  # @param handler [Hash] definition.
257
260
  # @param event [Hash]
258
- # @param callback [Proc]
259
- def event_filtered?(handler, event, &callback)
261
+ # @yield [filtered] callback/block called with a single
262
+ # parameter to indicate if the event was filtered.
263
+ # @yieldparam filtered [TrueClass,FalseClass] indicating if the
264
+ # event was filtered.
265
+ def event_filtered?(handler, event)
260
266
  if handler.has_key?(:filters) || handler.has_key?(:filter)
261
267
  filter_list = Array(handler[:filters] || handler[:filter]).dup
262
268
  filter = Proc.new do |filter_list|
263
269
  filter_name = filter_list.shift
264
270
  if filter_name.nil?
265
- callback.call(false)
271
+ yield(false)
266
272
  else
267
273
  event_filter(filter_name, event) do |filtered|
268
- filtered ? callback.call(true) : EM.next_tick { filter.call(filter_list) }
274
+ filtered ? yield(true) : EM.next_tick { filter.call(filter_list) }
269
275
  end
270
276
  end
271
277
  end
272
- EM.next_tick { filter.call(filter_list) }
278
+ filter.call(filter_list)
273
279
  else
274
- callback.call(false)
280
+ yield(false)
275
281
  end
276
282
  end
277
283
 
@@ -283,8 +289,10 @@ module Sensu
283
289
  #
284
290
  # @param handler [Hash] definition.
285
291
  # @param event [Hash]
286
- # @param callback [Proc]
287
- def filter_event(handler, event, &callback)
292
+ # @yield [event] callback/block called if the event has not been
293
+ # filtered.
294
+ # @yieldparam event [Hash]
295
+ def filter_event(handler, event)
288
296
  details = {:handler => handler, :event => event}
289
297
  filter_message = case
290
298
  when handling_disabled?(event)
@@ -302,7 +310,7 @@ module Sensu
302
310
  else
303
311
  event_filtered?(handler, event) do |filtered|
304
312
  unless filtered
305
- callback.call(event)
313
+ yield(event)
306
314
  else
307
315
  @logger.info("event was filtered", details)
308
316
  @handling_event_count -= 1 if @handling_event_count
@@ -13,6 +13,12 @@ module Sensu
13
13
 
14
14
  attr_reader :is_leader, :handling_event_count
15
15
 
16
+ METRIC_CHECK_TYPE = "metric".freeze
17
+
18
+ EVENT_FLAPPING_ACTION = "flapping".freeze
19
+
20
+ DEFAULT_HANDLER_NAME = "default".freeze
21
+
16
22
  # Create an instance of the Sensu server process, start the
17
23
  # server within the EventMachine event loop, and set up server
18
24
  # process signal traps (for stopping).
@@ -105,24 +111,25 @@ module Sensu
105
111
  # used for the stored client data.
106
112
  #
107
113
  # @param client [Hash]
108
- # @param callback [Proc] to call with the success status
109
- # (true/false) indicating if the client data has been added to
110
- # (or updated) the registry or discarded due to client signature
111
- # mismatch.
112
- def update_client_registry(client, &callback)
114
+ # @yield [success] passes success status to optional
115
+ # callback/block.
116
+ # @yieldparam success [TrueClass,FalseClass] indicating if the
117
+ # client registry update was a success or the client data was
118
+ # discarded due to client signature mismatch.
119
+ def update_client_registry(client)
113
120
  @logger.debug("updating client registry", :client => client)
114
121
  client_key = "client:#{client[:name]}"
115
122
  signature_key = "#{client_key}:signature"
116
123
  @redis.setnx(signature_key, client[:signature]) do |created|
117
124
  process_client_registration(client) if created
118
125
  @redis.get(signature_key) do |signature|
119
- if signature.empty? && client[:signature]
126
+ if (signature.nil? || signature.empty?) && client[:signature]
120
127
  @redis.set(signature_key, client[:signature])
121
128
  end
122
- if signature.empty? || (client[:signature] == signature)
129
+ if signature.nil? || signature.empty? || (client[:signature] == signature)
123
130
  @redis.set(client_key, MultiJson.dump(client)) do
124
131
  @redis.sadd("clients", client[:name]) do
125
- callback.call(true) if callback
132
+ yield(true) if block_given?
126
133
  end
127
134
  end
128
135
  else
@@ -131,7 +138,7 @@ module Sensu
131
138
  :signature => signature
132
139
  })
133
140
  @logger.warn("not updating client in the registry", :client => client)
134
- callback.call(false) if callback
141
+ yield(false) if block_given?
135
142
  end
136
143
  end
137
144
  end
@@ -218,9 +225,9 @@ module Sensu
218
225
  #
219
226
  # @param event [Hash]
220
227
  def process_event(event)
221
- log_level = event[:check][:type] == "metric" ? :debug : :info
228
+ log_level = event[:check][:type] == METRIC_CHECK_TYPE ? :debug : :info
222
229
  @logger.send(log_level, "processing event", :event => event)
223
- handler_list = Array((event[:check][:handlers] || event[:check][:handler]) || "default")
230
+ handler_list = Array((event[:check][:handlers] || event[:check][:handler]) || DEFAULT_HANDLER_NAME)
224
231
  handlers = derive_handlers(handler_list)
225
232
  handlers.each do |handler|
226
233
  @handling_event_count += 1
@@ -291,7 +298,7 @@ module Sensu
291
298
  # @return [Hash] check with truncated output.
292
299
  def truncate_check_output(check)
293
300
  case check[:type]
294
- when "metric"
301
+ when METRIC_CHECK_TYPE
295
302
  output_lines = check[:output].split("\n")
296
303
  output = output_lines.first || check[:output]
297
304
  if output_lines.size > 1 || output.length > 255
@@ -312,9 +319,9 @@ module Sensu
312
319
  #
313
320
  # @param client [Hash]
314
321
  # @param check [Hash]
315
- # @param callback [Proc] to call when the check result data has
316
- # been stored (history, etc).
317
- def store_check_result(client, check, &callback)
322
+ # @yield [] callback/block called after the check data has been
323
+ # stored (history, etc).
324
+ def store_check_result(client, check)
318
325
  @logger.debug("storing check result", :check => check)
319
326
  @redis.sadd("result:#{client[:name]}", check[:name])
320
327
  result_key = "#{client[:name]}:#{check[:name]}"
@@ -323,7 +330,7 @@ module Sensu
323
330
  history_key = "history:#{result_key}"
324
331
  @redis.rpush(history_key, check[:status]) do
325
332
  @redis.ltrim(history_key, -21, -1)
326
- callback.call
333
+ yield
327
334
  end
328
335
  end
329
336
  end
@@ -337,9 +344,14 @@ module Sensu
337
344
  #
338
345
  # @param client [Hash]
339
346
  # @param check [Hash]
340
- # @param callback [Proc] to be called with the check history and
341
- # total state change value.
342
- def check_history(client, check, &callback)
347
+ # @yield [history, total_state_change] callback/block to call
348
+ # with the check history and calculated total state change
349
+ # value.
350
+ # @yieldparam history [Array] containing the last 21 check
351
+ # result exit status codes.
352
+ # @yieldparam total_state_change [Float] percentage for the
353
+ # check history (exit status codes).
354
+ def check_history(client, check)
343
355
  history_key = "history:#{client[:name]}:#{check[:name]}"
344
356
  @redis.lrange(history_key, -21, -1) do |history|
345
357
  total_state_change = 0
@@ -356,7 +368,7 @@ module Sensu
356
368
  end
357
369
  total_state_change = (state_changes.fdiv(20) * 100).to_i
358
370
  end
359
- callback.call(history, total_state_change)
371
+ yield(history, total_state_change)
360
372
  end
361
373
  end
362
374
 
@@ -380,7 +392,7 @@ module Sensu
380
392
  # @return [TrueClass, FalseClass]
381
393
  def check_flapping?(stored_event, check)
382
394
  if check.has_key?(:low_flap_threshold) && check.has_key?(:high_flap_threshold)
383
- was_flapping = stored_event && stored_event[:action] == "flapping"
395
+ was_flapping = stored_event && stored_event[:action] == EVENT_FLAPPING_ACTION
384
396
  if was_flapping
385
397
  check[:total_state_change] > check[:low_flap_threshold]
386
398
  else
@@ -409,10 +421,11 @@ module Sensu
409
421
  #
410
422
  # @param client [Hash]
411
423
  # @param check [Hash]
412
- # @param callback [Proc] to be called with the resulting event
413
- # data if the event registry is updated, or the check is of
414
- # type `:metric`.
415
- def update_event_registry(client, check, &callback)
424
+ # @yield callback [event] callback/block called with the
425
+ # resulting event data if the event registry is updated, or
426
+ # the check is of type `:metric`.
427
+ # @yieldparam event [Hash]
428
+ def update_event_registry(client, check)
416
429
  @redis.hget("events:#{client[:name]}", check[:name]) do |event_json|
417
430
  stored_event = event_json ? MultiJson.load(event_json) : nil
418
431
  flapping = check_flapping?(stored_event, check)
@@ -429,18 +442,18 @@ module Sensu
429
442
  event[:occurrences] = stored_event[:occurrences] + 1
430
443
  end
431
444
  @redis.hset("events:#{client[:name]}", check[:name], MultiJson.dump(event)) do
432
- callback.call(event)
445
+ yield(event)
433
446
  end
434
447
  elsif stored_event
435
448
  event[:occurrences] = stored_event[:occurrences]
436
449
  event[:action] = :resolve
437
450
  unless check[:auto_resolve] == false && !check[:force_resolve]
438
451
  @redis.hdel("events:#{client[:name]}", check[:name]) do
439
- callback.call(event)
452
+ yield(event)
440
453
  end
441
454
  end
442
- elsif check[:type] == "metric"
443
- callback.call(event)
455
+ elsif check[:type] == METRIC_CHECK_TYPE
456
+ yield(event)
444
457
  end
445
458
  event_bridges(event)
446
459
  end
@@ -454,9 +467,10 @@ module Sensu
454
467
  # `false`.
455
468
  #
456
469
  # @param name [Hash] to use for the client.
457
- # @param callback [Proc] to be called with the dynamically
458
- # created client data.
459
- def create_client(name, &callback)
470
+ # @yield [client] callback/block to be called with the
471
+ # dynamically created client data.
472
+ # @yieldparam client [Hash]
473
+ def create_client(name)
460
474
  client = {
461
475
  :name => name,
462
476
  :address => "unknown",
@@ -465,7 +479,7 @@ module Sensu
465
479
  :version => VERSION
466
480
  }
467
481
  update_client_registry(client) do
468
- callback.call(client)
482
+ yield(client)
469
483
  end
470
484
  end
471
485
 
@@ -477,16 +491,17 @@ module Sensu
477
491
  # result must have a matching signature or it is discarded.
478
492
  #
479
493
  # @param result [Hash] data.
480
- # @param callback [Proc] to be called with client data, either
481
- # retrieved from Redis, or dynamically created.
482
- def retrieve_client(result, &callback)
494
+ # @yield [client] callback/block to be called with client data,
495
+ # either retrieved from Redis, or dynamically created.
496
+ # @yieldparam client [Hash]
497
+ def retrieve_client(result)
483
498
  client_key = result[:check][:source] || result[:client]
484
499
  @redis.get("client:#{client_key}") do |client_json|
485
500
  unless client_json.nil?
486
501
  client = MultiJson.load(client_json)
487
502
  if client[:signature]
488
503
  if client[:signature] == result[:signature]
489
- callback.call(client)
504
+ yield(client)
490
505
  else
491
506
  @logger.warn("invalid check result signature", {
492
507
  :result => result,
@@ -495,10 +510,12 @@ module Sensu
495
510
  @logger.warn("not retrieving client from the registry", :result => result)
496
511
  end
497
512
  else
498
- callback.call(client)
513
+ yield(client)
499
514
  end
500
515
  else
501
- create_client(client_key, &callback)
516
+ create_client(client_key) do |client|
517
+ yield(client)
518
+ end
502
519
  end
503
520
  end
504
521
  end
@@ -1014,15 +1031,15 @@ module Sensu
1014
1031
  # is complete, when it is equal to `0`. The provided callback is
1015
1032
  # called when handling is complete.
1016
1033
  #
1017
- # @param callback [Proc] to call when event handling is
1034
+ # @yield [] callback/block to call when event handling is
1018
1035
  # complete.
1019
- def complete_event_handling(&callback)
1036
+ def complete_event_handling
1020
1037
  @logger.info("completing event handling in progress", {
1021
1038
  :handling_event_count => @handling_event_count
1022
1039
  })
1023
1040
  retry_until_true do
1024
1041
  if @handling_event_count == 0
1025
- callback.call
1042
+ yield
1026
1043
  true
1027
1044
  end
1028
1045
  end
data/sensu.gemspec CHANGED
@@ -16,13 +16,13 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency "json" if RUBY_VERSION < "1.9"
17
17
  s.add_dependency "multi_json", "1.11.2"
18
18
  s.add_dependency "uuidtools", "2.1.5"
19
- s.add_dependency "eventmachine", "1.0.8"
19
+ s.add_dependency "eventmachine", "1.0.9.1"
20
20
  s.add_dependency "sensu-logger", "1.1.0"
21
21
  s.add_dependency "sensu-settings", "3.3.0"
22
22
  s.add_dependency "sensu-extension", "1.3.0"
23
23
  s.add_dependency "sensu-extensions", "1.4.0"
24
- s.add_dependency "sensu-transport", "3.3.0"
25
- s.add_dependency "sensu-spawn", "1.6.0"
24
+ s.add_dependency "sensu-transport", "4.0.0"
25
+ s.add_dependency "sensu-spawn", "1.7.0"
26
26
  s.add_dependency "em-redis-unified", "1.0.1"
27
27
  s.add_dependency "sinatra", "1.4.6"
28
28
  s.add_dependency "async_sinatra", "1.2.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0
4
+ version: 0.22.1
5
5
  platform: java
6
6
  authors:
7
7
  - Sean Porter
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-01-29 00:00:00.000000000 Z
12
+ date: 2016-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -45,12 +45,12 @@ dependencies:
45
45
  requirements:
46
46
  - - '='
47
47
  - !ruby/object:Gem::Version
48
- version: 1.0.8
48
+ version: 1.0.9.1
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 1.0.8
53
+ version: 1.0.9.1
54
54
  prerelease: false
55
55
  type: :runtime
56
56
  - !ruby/object:Gem::Dependency
@@ -115,12 +115,12 @@ dependencies:
115
115
  requirements:
116
116
  - - '='
117
117
  - !ruby/object:Gem::Version
118
- version: 3.3.0
118
+ version: 4.0.0
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - '='
122
122
  - !ruby/object:Gem::Version
123
- version: 3.3.0
123
+ version: 4.0.0
124
124
  prerelease: false
125
125
  type: :runtime
126
126
  - !ruby/object:Gem::Dependency
@@ -129,12 +129,12 @@ dependencies:
129
129
  requirements:
130
130
  - - '='
131
131
  - !ruby/object:Gem::Version
132
- version: 1.6.0
132
+ version: 1.7.0
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - '='
136
136
  - !ruby/object:Gem::Version
137
- version: 1.6.0
137
+ version: 1.7.0
138
138
  prerelease: false
139
139
  type: :runtime
140
140
  - !ruby/object:Gem::Dependency