sensu 0.12.6 → 0.13.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0e1b021d3461d4daef8432adea63250ae659bb10
4
+ data.tar.gz: b00ffdcb7989eba387b66777b5b6cd04abf1264d
5
+ SHA512:
6
+ metadata.gz: d324be84c52252df92c88c1e1691a4917aba28c29c520a482ea27b4c46c7c3fcfe30a569cde6cd6464ecaecf631fee7f86b9cc99186ec5d6725cb27a8c9af7f0
7
+ data.tar.gz: 1c0d83d4bcf511709f0abed6624e293ad5037a32e3f221225c46247ebef1284fc5a332aaa3013b951b075b4233c85a9bdb3e94f9e1f60338a3a1f5da4ec07094
data/CHANGELOG.md CHANGED
@@ -1,3 +1,44 @@
1
+ ## 0.13.0 - TBD
2
+
3
+ ### Non-backwards compatible changes
4
+
5
+ API GET /events now provides all event data, the same data passed to event
6
+ handlers.
7
+
8
+ Standalone check results are no longer merged with check definitions
9
+ residing on the server(s).
10
+
11
+ Removed the generic extension type.
12
+
13
+ Extension stop() no longer takes a callback, and is called when the
14
+ eventmachine reactor is stopped.
15
+
16
+ ### Features
17
+
18
+ Abstracted the transport layer, opening Sensu up to alternative messaging
19
+ services.
20
+
21
+ Event bridge extension type, allowing all events to be relayed to other
22
+ services.
23
+
24
+ Client keepalives now contain the Sensu version.
25
+
26
+ ### Other
27
+
28
+ Clients now only load instances of check extensions, and servers load
29
+ everything but check extensions.
30
+
31
+ Fixed standalone check scheduling, no longer mutating definitions.
32
+
33
+ Fixed command token substitution, allowing for the use of colons.
34
+
35
+ Log events are flushed when the eventmachine reactor stops.
36
+
37
+ Dropped the Oj JSON parser, heap allocation issues and memory leaks.
38
+
39
+ Client RabbitMQ queues are no longer server named (bugs), they are now
40
+ composed of the client name, Sensu version, and the timestamp at creation.
41
+
1
42
  ## 0.12.6 - 2014-02-19
2
43
 
3
44
  ### Non-backwards compatible changes
data/lib/sensu/api.rb CHANGED
@@ -1,5 +1,4 @@
1
- require File.join(File.dirname(__FILE__), 'base')
2
- require File.join(File.dirname(__FILE__), 'redis')
1
+ require 'sensu/daemon'
3
2
 
4
3
  gem 'thin', '1.5.0'
5
4
  gem 'sinatra', '1.3.5'
@@ -13,97 +12,45 @@ module Sensu
13
12
  register Sinatra::Async
14
13
 
15
14
  class << self
15
+ include Daemon
16
+
16
17
  def run(options={})
18
+ bootstrap(options)
17
19
  EM::run do
18
- bootstrap(options)
19
20
  start
20
- trap_signals
21
+ setup_signal_traps
21
22
  end
22
23
  end
23
24
 
24
- def bootstrap(options={})
25
- base = Base.new(options)
26
- $logger = base.logger
27
- $settings = base.settings
28
- base.setup_process
29
- if $settings[:api][:user] && $settings[:api][:password]
25
+ def bootstrap(options)
26
+ setup_logger(options)
27
+ set :logger, @logger
28
+ load_settings(options)
29
+ if @settings[:api][:user] && @settings[:api][:password]
30
30
  use Rack::Auth::Basic do |user, password|
31
- user == $settings[:api][:user] && password == $settings[:api][:password]
31
+ user == @settings[:api][:user] && password == @settings[:api][:password]
32
32
  end
33
33
  end
34
- end
35
-
36
- def setup_redis
37
- $logger.debug('connecting to redis', {
38
- :settings => $settings[:redis]
39
- })
40
- $redis = Redis.connect($settings[:redis])
41
- $redis.on_error do |error|
42
- $logger.fatal('redis connection error', {
43
- :error => error.to_s
44
- })
45
- stop
46
- end
47
- $redis.before_reconnect do
48
- $logger.warn('reconnecting to redis')
49
- end
50
- $redis.after_reconnect do
51
- $logger.info('reconnected to redis')
52
- end
53
- end
54
-
55
- def setup_rabbitmq
56
- $logger.debug('connecting to rabbitmq', {
57
- :settings => $settings[:rabbitmq]
58
- })
59
- $rabbitmq = RabbitMQ.connect($settings[:rabbitmq])
60
- $rabbitmq.on_error do |error|
61
- $logger.fatal('rabbitmq connection error', {
62
- :error => error.to_s
63
- })
64
- stop
65
- end
66
- $rabbitmq.before_reconnect do
67
- $logger.warn('reconnecting to rabbitmq')
68
- end
69
- $rabbitmq.after_reconnect do
70
- $logger.info('reconnected to rabbitmq')
71
- end
72
- $amq = $rabbitmq.channel
34
+ set :checks, @settings[:checks]
35
+ set :all_checks, @settings.checks
36
+ setup_process(options)
73
37
  end
74
38
 
75
39
  def start
76
40
  setup_redis
77
- setup_rabbitmq
41
+ set :redis, @redis
42
+ setup_transport
43
+ set :transport, @transport
78
44
  Thin::Logging.silent = true
79
- bind = $settings[:api][:bind] || '0.0.0.0'
80
- Thin::Server.start(bind, $settings[:api][:port], self)
45
+ bind = @settings[:api][:bind] || '0.0.0.0'
46
+ Thin::Server.start(bind, @settings[:api][:port], self)
81
47
  end
82
48
 
83
49
  def stop
84
- $logger.warn('stopping')
85
- $rabbitmq.close
86
- $redis.close
87
- $logger.warn('stopping reactor')
88
- EM::stop_event_loop
89
- end
90
-
91
- def trap_signals
92
- $signals = Array.new
93
- STOP_SIGNALS.each do |signal|
94
- Signal.trap(signal) do
95
- $signals << signal
96
- end
97
- end
98
- EM::PeriodicTimer.new(1) do
99
- signal = $signals.shift
100
- if STOP_SIGNALS.include?(signal)
101
- $logger.warn('received signal', {
102
- :signal => signal
103
- })
104
- stop
105
- end
106
- end
50
+ @logger.warn('stopping')
51
+ @redis.close
52
+ @transport.close
53
+ super
107
54
  end
108
55
 
109
56
  def test(options={})
@@ -127,7 +74,7 @@ module Sensu
127
74
 
128
75
  helpers do
129
76
  def request_log_line
130
- $logger.info([env['REQUEST_METHOD'], env['REQUEST_PATH']].join(' '), {
77
+ settings.logger.info([env['REQUEST_METHOD'], env['REQUEST_PATH']].join(' '), {
131
78
  :remote_address => env['REMOTE_ADDR'],
132
79
  :user_agent => env['HTTP_USER_AGENT'],
133
80
  :request_method => env['REQUEST_METHOD'],
@@ -160,7 +107,7 @@ module Sensu
160
107
  end
161
108
 
162
109
  def issued!
163
- accepted!(Oj.dump(:issued => Time.now.to_i))
110
+ accepted!(MultiJson.dump(:issued => Time.now.to_i))
164
111
  end
165
112
 
166
113
  def no_content!
@@ -170,7 +117,7 @@ module Sensu
170
117
 
171
118
  def read_data(rules={}, &block)
172
119
  begin
173
- data = Oj.load(env['rack.input'].read)
120
+ data = MultiJson.load(env['rack.input'].read)
174
121
  valid = rules.all? do |key, rule|
175
122
  data[key].is_a?(rule[:type]) || (rule[:nil_ok] && data[key].nil?)
176
123
  end
@@ -179,7 +126,7 @@ module Sensu
179
126
  else
180
127
  bad_request!
181
128
  end
182
- rescue Oj::ParseError
129
+ rescue MultiJson::ParseError
183
130
  bad_request!
184
131
  end
185
132
  end
@@ -192,7 +139,7 @@ module Sensu
192
139
  limit = integer_parameter(params[:limit])
193
140
  offset = integer_parameter(params[:offset]) || 0
194
141
  unless limit.nil?
195
- headers['X-Pagination'] = Oj.dump(
142
+ headers['X-Pagination'] = MultiJson.dump(
196
143
  :limit => limit,
197
144
  :offset => offset,
198
145
  :total => items.size
@@ -204,7 +151,7 @@ module Sensu
204
151
  end
205
152
  end
206
153
 
207
- def rabbitmq_info(&block)
154
+ def transport_info(&block)
208
155
  info = {
209
156
  :keepalives => {
210
157
  :messages => nil,
@@ -214,15 +161,13 @@ module Sensu
214
161
  :messages => nil,
215
162
  :consumers => nil
216
163
  },
217
- :connected => $rabbitmq.connected?
164
+ :connected => settings.transport.connected?
218
165
  }
219
- if $rabbitmq.connected?
220
- $amq.queue('keepalives', :auto_delete => true).status do |messages, consumers|
221
- info[:keepalives][:messages] = messages
222
- info[:keepalives][:consumers] = consumers
223
- $amq.queue('results', :auto_delete => true).status do |messages, consumers|
224
- info[:results][:messages] = messages
225
- info[:results][:consumers] = consumers
166
+ if settings.transport.connected?
167
+ settings.transport.stats('keepalives') do |stats|
168
+ info[:keepalives] = stats
169
+ settings.transport.stats('results') do |stats|
170
+ info[:results] = stats
226
171
  block.call(info)
227
172
  end
228
173
  end
@@ -231,35 +176,30 @@ module Sensu
231
176
  end
232
177
  end
233
178
 
234
- def event_hash(event_json, client_name, check_name)
235
- Oj.load(event_json).merge(
236
- :client => client_name,
237
- :check => check_name
179
+ def resolve_event(event_json)
180
+ event = MultiJson.load(event_json)
181
+ check = event[:check].merge(
182
+ :output => 'Resolving on request of the API',
183
+ :status => 0,
184
+ :issued => Time.now.to_i,
185
+ :executed => Time.now.to_i,
186
+ :force_resolve => true
238
187
  )
239
- end
240
-
241
- def resolve_event(event)
188
+ check.delete(:history)
242
189
  payload = {
243
- :client => event[:client],
244
- :check => {
245
- :name => event[:check],
246
- :output => 'Resolving on request of the API',
247
- :status => 0,
248
- :issued => Time.now.to_i,
249
- :handlers => event[:handlers],
250
- :force_resolve => true
251
- }
190
+ :client => event[:client][:name],
191
+ :check => check
252
192
  }
253
- $logger.info('publishing check result', {
193
+ settings.logger.info('publishing check result', {
254
194
  :payload => payload
255
195
  })
256
- begin
257
- $amq.direct('results').publish(Oj.dump(payload))
258
- rescue AMQ::Client::ConnectionClosedError => error
259
- $logger.error('failed to publish check result', {
260
- :payload => payload,
261
- :error => error.to_s
262
- })
196
+ settings.transport.publish(:direct, 'results', MultiJson.dump(payload)) do |info|
197
+ if info[:error]
198
+ settings.logger.error('failed to publish check result', {
199
+ :payload => payload,
200
+ :error => info[:error].to_s
201
+ })
202
+ end
263
203
  end
264
204
  end
265
205
  end
@@ -270,26 +210,26 @@ module Sensu
270
210
  end
271
211
 
272
212
  aget '/info/?' do
273
- rabbitmq_info do |info|
213
+ transport_info do |info|
274
214
  response = {
275
215
  :sensu => {
276
216
  :version => VERSION
277
217
  },
278
- :rabbitmq => info,
218
+ :transport => info,
279
219
  :redis => {
280
- :connected => $redis.connected?
220
+ :connected => settings.redis.connected?
281
221
  }
282
222
  }
283
- body Oj.dump(response)
223
+ body MultiJson.dump(response)
284
224
  end
285
225
  end
286
226
 
287
227
  aget '/health/?' do
288
- if $redis.connected? && $rabbitmq.connected?
228
+ if settings.redis.connected? && settings.transport.connected?
289
229
  healthy = Array.new
290
230
  min_consumers = integer_parameter(params[:consumers])
291
231
  max_messages = integer_parameter(params[:messages])
292
- rabbitmq_info do |info|
232
+ transport_info do |info|
293
233
  if min_consumers
294
234
  healthy << (info[:keepalives][:consumers] >= min_consumers)
295
235
  healthy << (info[:results][:consumers] >= min_consumers)
@@ -307,25 +247,25 @@ module Sensu
307
247
 
308
248
  aget '/clients/?' do
309
249
  response = Array.new
310
- $redis.smembers('clients') do |clients|
250
+ settings.redis.smembers('clients') do |clients|
311
251
  clients = pagination(clients)
312
252
  unless clients.empty?
313
253
  clients.each_with_index do |client_name, index|
314
- $redis.get('client:' + client_name) do |client_json|
315
- response << Oj.load(client_json)
254
+ settings.redis.get('client:' + client_name) do |client_json|
255
+ response << MultiJson.load(client_json)
316
256
  if index == clients.size - 1
317
- body Oj.dump(response)
257
+ body MultiJson.dump(response)
318
258
  end
319
259
  end
320
260
  end
321
261
  else
322
- body Oj.dump(response)
262
+ body MultiJson.dump(response)
323
263
  end
324
264
  end
325
265
  end
326
266
 
327
267
  aget %r{/clients?/([\w\.-]+)/?$} do |client_name|
328
- $redis.get('client:' + client_name) do |client_json|
268
+ settings.redis.get('client:' + client_name) do |client_json|
329
269
  unless client_json.nil?
330
270
  body client_json
331
271
  else
@@ -336,16 +276,16 @@ module Sensu
336
276
 
337
277
  aget %r{/clients/([\w\.-]+)/history/?$} do |client_name|
338
278
  response = Array.new
339
- $redis.smembers('history:' + client_name) do |checks|
279
+ settings.redis.smembers('history:' + client_name) do |checks|
340
280
  unless checks.empty?
341
281
  checks.each_with_index do |check_name, index|
342
282
  history_key = 'history:' + client_name + ':' + check_name
343
- $redis.lrange(history_key, -21, -1) do |history|
283
+ settings.redis.lrange(history_key, -21, -1) do |history|
344
284
  history.map! do |status|
345
285
  status.to_i
346
286
  end
347
287
  execution_key = 'execution:' + client_name + ':' + check_name
348
- $redis.get(execution_key) do |last_execution|
288
+ settings.redis.get(execution_key) do |last_execution|
349
289
  unless history.empty? || last_execution.nil?
350
290
  item = {
351
291
  :check => check_name,
@@ -356,38 +296,38 @@ module Sensu
356
296
  response << item
357
297
  end
358
298
  if index == checks.size - 1
359
- body Oj.dump(response)
299
+ body MultiJson.dump(response)
360
300
  end
361
301
  end
362
302
  end
363
303
  end
364
304
  else
365
- body Oj.dump(response)
305
+ body MultiJson.dump(response)
366
306
  end
367
307
  end
368
308
  end
369
309
 
370
310
  adelete %r{/clients?/([\w\.-]+)/?$} do |client_name|
371
- $redis.get('client:' + client_name) do |client_json|
311
+ settings.redis.get('client:' + client_name) do |client_json|
372
312
  unless client_json.nil?
373
- $redis.hgetall('events:' + client_name) do |events|
313
+ settings.redis.hgetall('events:' + client_name) do |events|
374
314
  events.each do |check_name, event_json|
375
- resolve_event(event_hash(event_json, client_name, check_name))
315
+ resolve_event(event_json)
376
316
  end
377
317
  EM::Timer.new(5) do
378
- client = Oj.load(client_json)
379
- $logger.info('deleting client', {
318
+ client = MultiJson.load(client_json)
319
+ settings.logger.info('deleting client', {
380
320
  :client => client
381
321
  })
382
- $redis.srem('clients', client_name) do
383
- $redis.del('client:' + client_name)
384
- $redis.del('events:' + client_name)
385
- $redis.smembers('history:' + client_name) do |checks|
322
+ settings.redis.srem('clients', client_name) do
323
+ settings.redis.del('client:' + client_name)
324
+ settings.redis.del('events:' + client_name)
325
+ settings.redis.smembers('history:' + client_name) do |checks|
386
326
  checks.each do |check_name|
387
- $redis.del('history:' + client_name + ':' + check_name)
388
- $redis.del('execution:' + client_name + ':' + check_name)
327
+ settings.redis.del('history:' + client_name + ':' + check_name)
328
+ settings.redis.del('execution:' + client_name + ':' + check_name)
389
329
  end
390
- $redis.del('history:' + client_name)
330
+ settings.redis.del('history:' + client_name)
391
331
  end
392
332
  end
393
333
  end
@@ -400,13 +340,13 @@ module Sensu
400
340
  end
401
341
 
402
342
  aget '/checks/?' do
403
- body Oj.dump($settings.checks)
343
+ body MultiJson.dump(settings.all_checks)
404
344
  end
405
345
 
406
346
  aget %r{/checks?/([\w\.-]+)/?$} do |check_name|
407
- if $settings.check_exists?(check_name)
408
- response = $settings[:checks][check_name].merge(:name => check_name)
409
- body Oj.dump(response)
347
+ if settings.checks[check_name]
348
+ response = settings.checks[check_name].merge(:name => check_name)
349
+ body MultiJson.dump(response)
410
350
  else
411
351
  not_found!
412
352
  end
@@ -418,27 +358,27 @@ module Sensu
418
358
  :subscribers => {:type => Array, :nil_ok => true}
419
359
  }
420
360
  read_data(rules) do |data|
421
- if $settings.check_exists?(data[:check])
422
- check = $settings[:checks][data[:check]]
361
+ if settings.checks[data[:check]]
362
+ check = settings.checks[data[:check]]
423
363
  subscribers = data[:subscribers] || check[:subscribers] || Array.new
424
364
  payload = {
425
365
  :name => data[:check],
426
366
  :command => check[:command],
427
367
  :issued => Time.now.to_i
428
368
  }
429
- $logger.info('publishing check request', {
369
+ settings.logger.info('publishing check request', {
430
370
  :payload => payload,
431
371
  :subscribers => subscribers
432
372
  })
433
373
  subscribers.uniq.each do |exchange_name|
434
- begin
435
- $amq.fanout(exchange_name).publish(Oj.dump(payload))
436
- rescue AMQ::Client::ConnectionClosedError => error
437
- $logger.error('failed to publish check request', {
438
- :exchange_name => exchange_name,
439
- :payload => payload,
440
- :error => error.to_s
441
- })
374
+ settings.transport.publish(:fanout, exchange_name, MultiJson.dump(payload)) do |info|
375
+ if info[:error]
376
+ settings.logger.error('failed to publish check request', {
377
+ :exchange_name => exchange_name,
378
+ :payload => payload,
379
+ :error => info[:error].to_s
380
+ })
381
+ end
442
382
  end
443
383
  end
444
384
  issued!
@@ -450,39 +390,39 @@ module Sensu
450
390
 
451
391
  aget '/events/?' do
452
392
  response = Array.new
453
- $redis.smembers('clients') do |clients|
393
+ settings.redis.smembers('clients') do |clients|
454
394
  unless clients.empty?
455
395
  clients.each_with_index do |client_name, index|
456
- $redis.hgetall('events:' + client_name) do |events|
396
+ settings.redis.hgetall('events:' + client_name) do |events|
457
397
  events.each do |check_name, event_json|
458
- response << event_hash(event_json, client_name, check_name)
398
+ response << MultiJson.load(event_json)
459
399
  end
460
400
  if index == clients.size - 1
461
- body Oj.dump(response)
401
+ body MultiJson.dump(response)
462
402
  end
463
403
  end
464
404
  end
465
405
  else
466
- body Oj.dump(response)
406
+ body MultiJson.dump(response)
467
407
  end
468
408
  end
469
409
  end
470
410
 
471
411
  aget %r{/events/([\w\.-]+)/?$} do |client_name|
472
412
  response = Array.new
473
- $redis.hgetall('events:' + client_name) do |events|
413
+ settings.redis.hgetall('events:' + client_name) do |events|
474
414
  events.each do |check_name, event_json|
475
- response << event_hash(event_json, client_name, check_name)
415
+ response << MultiJson.load(event_json)
476
416
  end
477
- body Oj.dump(response)
417
+ body MultiJson.dump(response)
478
418
  end
479
419
  end
480
420
 
481
421
  aget %r{/events?/([\w\.-]+)/([\w\.-]+)/?$} do |client_name, check_name|
482
- $redis.hgetall('events:' + client_name) do |events|
422
+ settings.redis.hgetall('events:' + client_name) do |events|
483
423
  event_json = events[check_name]
484
424
  unless event_json.nil?
485
- body Oj.dump(event_hash(event_json, client_name, check_name))
425
+ body event_json
486
426
  else
487
427
  not_found!
488
428
  end
@@ -490,9 +430,9 @@ module Sensu
490
430
  end
491
431
 
492
432
  adelete %r{/events?/([\w\.-]+)/([\w\.-]+)/?$} do |client_name, check_name|
493
- $redis.hgetall('events:' + client_name) do |events|
433
+ settings.redis.hgetall('events:' + client_name) do |events|
494
434
  if events.include?(check_name)
495
- resolve_event(event_hash(events[check_name], client_name, check_name))
435
+ resolve_event(events[check_name])
496
436
  issued!
497
437
  else
498
438
  not_found!
@@ -506,9 +446,9 @@ module Sensu
506
446
  :check => {:type => String, :nil_ok => false}
507
447
  }
508
448
  read_data(rules) do |data|
509
- $redis.hgetall('events:' + data[:client]) do |events|
449
+ settings.redis.hgetall('events:' + data[:client]) do |events|
510
450
  if events.include?(data[:check])
511
- resolve_event(event_hash(events[data[:check]], data[:client], data[:check]))
451
+ resolve_event(events[data[:check]])
512
452
  issued!
513
453
  else
514
454
  not_found!
@@ -519,10 +459,10 @@ module Sensu
519
459
 
520
460
  aget '/aggregates/?' do
521
461
  response = Array.new
522
- $redis.smembers('aggregates') do |checks|
462
+ settings.redis.smembers('aggregates') do |checks|
523
463
  unless checks.empty?
524
464
  checks.each_with_index do |check_name, index|
525
- $redis.smembers('aggregates:' + check_name) do |aggregates|
465
+ settings.redis.smembers('aggregates:' + check_name) do |aggregates|
526
466
  aggregates.reverse!
527
467
  aggregates.map! do |issued|
528
468
  issued.to_i
@@ -533,18 +473,18 @@ module Sensu
533
473
  }
534
474
  response << item
535
475
  if index == checks.size - 1
536
- body Oj.dump(response)
476
+ body MultiJson.dump(response)
537
477
  end
538
478
  end
539
479
  end
540
480
  else
541
- body Oj.dump(response)
481
+ body MultiJson.dump(response)
542
482
  end
543
483
  end
544
484
  end
545
485
 
546
486
  aget %r{/aggregates/([\w\.-]+)/?$} do |check_name|
547
- $redis.smembers('aggregates:' + check_name) do |aggregates|
487
+ settings.redis.smembers('aggregates:' + check_name) do |aggregates|
548
488
  unless aggregates.empty?
549
489
  aggregates.reverse!
550
490
  aggregates.map! do |issued|
@@ -557,7 +497,7 @@ module Sensu
557
497
  issued > timestamp
558
498
  end
559
499
  end
560
- body Oj.dump(pagination(aggregates))
500
+ body MultiJson.dump(pagination(aggregates))
561
501
  else
562
502
  not_found!
563
503
  end
@@ -565,15 +505,15 @@ module Sensu
565
505
  end
566
506
 
567
507
  adelete %r{/aggregates/([\w\.-]+)/?$} do |check_name|
568
- $redis.smembers('aggregates:' + check_name) do |aggregates|
508
+ settings.redis.smembers('aggregates:' + check_name) do |aggregates|
569
509
  unless aggregates.empty?
570
510
  aggregates.each do |check_issued|
571
511
  result_set = check_name + ':' + check_issued
572
- $redis.del('aggregation:' + result_set)
573
- $redis.del('aggregate:' + result_set)
512
+ settings.redis.del('aggregation:' + result_set)
513
+ settings.redis.del('aggregate:' + result_set)
574
514
  end
575
- $redis.del('aggregates:' + check_name) do
576
- $redis.srem('aggregates', check_name) do
515
+ settings.redis.del('aggregates:' + check_name) do
516
+ settings.redis.srem('aggregates', check_name) do
577
517
  no_content!
578
518
  end
579
519
  end
@@ -585,15 +525,15 @@ module Sensu
585
525
 
586
526
  aget %r{/aggregates?/([\w\.-]+)/([\w\.-]+)/?$} do |check_name, check_issued|
587
527
  result_set = check_name + ':' + check_issued
588
- $redis.hgetall('aggregate:' + result_set) do |aggregate|
528
+ settings.redis.hgetall('aggregate:' + result_set) do |aggregate|
589
529
  unless aggregate.empty?
590
530
  response = aggregate.inject(Hash.new) do |totals, (status, count)|
591
531
  totals[status] = Integer(count)
592
532
  totals
593
533
  end
594
- $redis.hgetall('aggregation:' + result_set) do |results|
534
+ settings.redis.hgetall('aggregation:' + result_set) do |results|
595
535
  parsed_results = results.inject(Array.new) do |parsed, (client_name, check_json)|
596
- check = Oj.load(check_json)
536
+ check = MultiJson.load(check_json)
597
537
  parsed << check.merge(:client => client_name)
598
538
  end
599
539
  if params[:summarize]
@@ -609,7 +549,7 @@ module Sensu
609
549
  if params[:results]
610
550
  response[:results] = parsed_results
611
551
  end
612
- body Oj.dump(response)
552
+ body MultiJson.dump(response)
613
553
  end
614
554
  else
615
555
  not_found!
@@ -619,16 +559,16 @@ module Sensu
619
559
 
620
560
  apost %r{/stash(?:es)?/(.*)/?} do |path|
621
561
  read_data do |data|
622
- $redis.set('stash:' + path, Oj.dump(data)) do
623
- $redis.sadd('stashes', path) do
624
- created!(Oj.dump(:path => path))
562
+ settings.redis.set('stash:' + path, MultiJson.dump(data)) do
563
+ settings.redis.sadd('stashes', path) do
564
+ created!(MultiJson.dump(:path => path))
625
565
  end
626
566
  end
627
567
  end
628
568
  end
629
569
 
630
570
  aget %r{/stash(?:es)?/(.*)/?} do |path|
631
- $redis.get('stash:' + path) do |stash_json|
571
+ settings.redis.get('stash:' + path) do |stash_json|
632
572
  unless stash_json.nil?
633
573
  body stash_json
634
574
  else
@@ -638,10 +578,10 @@ module Sensu
638
578
  end
639
579
 
640
580
  adelete %r{/stash(?:es)?/(.*)/?} do |path|
641
- $redis.exists('stash:' + path) do |stash_exists|
581
+ settings.redis.exists('stash:' + path) do |stash_exists|
642
582
  if stash_exists
643
- $redis.srem('stashes', path) do
644
- $redis.del('stash:' + path) do
583
+ settings.redis.srem('stashes', path) do
584
+ settings.redis.del('stash:' + path) do
645
585
  no_content!
646
586
  end
647
587
  end
@@ -653,29 +593,29 @@ module Sensu
653
593
 
654
594
  aget '/stashes/?' do
655
595
  response = Array.new
656
- $redis.smembers('stashes') do |stashes|
596
+ settings.redis.smembers('stashes') do |stashes|
657
597
  unless stashes.empty?
658
598
  stashes.each_with_index do |path, index|
659
- $redis.get('stash:' + path) do |stash_json|
660
- $redis.ttl('stash:' + path) do |ttl|
599
+ settings.redis.get('stash:' + path) do |stash_json|
600
+ settings.redis.ttl('stash:' + path) do |ttl|
661
601
  unless stash_json.nil?
662
602
  item = {
663
603
  :path => path,
664
- :content => Oj.load(stash_json),
604
+ :content => MultiJson.load(stash_json),
665
605
  :expire => ttl
666
606
  }
667
607
  response << item
668
608
  else
669
- $redis.srem('stashes', path)
609
+ settings.redis.srem('stashes', path)
670
610
  end
671
611
  if index == stashes.size - 1
672
- body Oj.dump(pagination(response))
612
+ body MultiJson.dump(pagination(response))
673
613
  end
674
614
  end
675
615
  end
676
616
  end
677
617
  else
678
- body Oj.dump(response)
618
+ body MultiJson.dump(response)
679
619
  end
680
620
  end
681
621
  end
@@ -688,11 +628,11 @@ module Sensu
688
628
  }
689
629
  read_data(rules) do |data|
690
630
  stash_key = 'stash:' + data[:path]
691
- $redis.set(stash_key, Oj.dump(data[:content])) do
692
- $redis.sadd('stashes', data[:path]) do
693
- response = Oj.dump(:path => data[:path])
631
+ settings.redis.set(stash_key, MultiJson.dump(data[:content])) do
632
+ settings.redis.sadd('stashes', data[:path]) do
633
+ response = MultiJson.dump(:path => data[:path])
694
634
  if data[:expire]
695
- $redis.expire(stash_key, data[:expire]) do
635
+ settings.redis.expire(stash_key, data[:expire]) do
696
636
  created!(response)
697
637
  end
698
638
  else