sensu 0.9.0.beta.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sensu.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sensu
2
- VERSION = "0.9.0.beta.4"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/sensu/api.rb CHANGED
@@ -29,7 +29,9 @@ module Sensu
29
29
  if options[:daemonize]
30
30
  Process.daemonize
31
31
  end
32
- Process.write_pid(options[:pid_file])
32
+ if options[:pid_file]
33
+ Process.write_pid(options[:pid_file])
34
+ end
33
35
  $logger.debug('[setup] -- connecting to redis')
34
36
  $redis = Redis.connect($settings.redis.to_hash.symbolize_keys)
35
37
  $logger.debug('[setup] -- connecting to rabbitmq')
data/lib/sensu/client.rb CHANGED
@@ -7,7 +7,9 @@ module Sensu
7
7
  if options[:daemonize]
8
8
  Process.daemonize
9
9
  end
10
- Process.write_pid(options[:pid_file])
10
+ if options[:pid_file]
11
+ Process.write_pid(options[:pid_file])
12
+ end
11
13
  EM.run do
12
14
  client.setup_amqp
13
15
  client.setup_keepalives
@@ -30,7 +32,7 @@ module Sensu
30
32
  end
31
33
 
32
34
  def stop(signal)
33
- @logger.warn('[process] -- ' + signal + ' -- stopping sensu client')
35
+ @logger.warn('[stop] -- stopping sensu client -- ' + signal)
34
36
  EM.add_timer(1) do
35
37
  EM.stop
36
38
  end
@@ -160,7 +162,7 @@ module Sensu
160
162
  @logger.debug('[monitor] -- setup queue monitor')
161
163
  EM.add_periodic_timer(5) do
162
164
  unless @check_queue.subscribed?
163
- @logger.warn('[monitor] -- reconnecting to rabbitmq')
165
+ @logger.warn('[monitor] -- re-subscribing to subscriptions')
164
166
  @check_queue.delete
165
167
  EM.add_timer(1) do
166
168
  setup_subscriptions
@@ -170,7 +172,7 @@ module Sensu
170
172
  end
171
173
 
172
174
  def setup_socket
173
- @logger.debug('[socket] -- starting up socket server')
175
+ @logger.debug('[socket] -- starting up socket')
174
176
  EM.start_server('127.0.0.1', 3030, ClientSocket) do |socket|
175
177
  socket.settings = @settings
176
178
  socket.logger = @logger
@@ -196,7 +198,7 @@ module Sensu
196
198
  :check => check.to_hash
197
199
  }.to_json)
198
200
  else
199
- @logger.warn('[socket] -- a check name, exit status, and output are required -- e.g. {name: x, status: 0, output: "y"}')
201
+ @logger.warn('[socket] -- a check name, exit status, and output are required -- e.g. {"name": "x", "status": 0, output: "y"}')
200
202
  end
201
203
  rescue JSON::ParserError => error
202
204
  @logger.warn('[socket] -- check result must be valid JSON: ' + error.to_s)
data/lib/sensu/config.rb CHANGED
@@ -55,8 +55,10 @@ module Sensu
55
55
  end
56
56
  @logger.subscribe(Cabin::Outputs::EmStdlibLogger.new(ruby_logger))
57
57
  @logger.level = @options[:verbose] ? :debug : :info
58
- Signal.trap('USR1') do
59
- @logger.level = @logger.level == :info ? :debug : :info
58
+ if Signal.list.include?('USR1')
59
+ Signal.trap('USR1') do
60
+ @logger.level = @logger.level == :info ? :debug : :info
61
+ end
60
62
  end
61
63
  @logger
62
64
  end
data/lib/sensu/server.rb CHANGED
@@ -13,7 +13,9 @@ module Sensu
13
13
  if options[:daemonize]
14
14
  Process.daemonize
15
15
  end
16
- Process.write_pid(options[:pid_file])
16
+ if options[:pid_file]
17
+ Process.write_pid(options[:pid_file])
18
+ end
17
19
  EM.threadpool_size = 16
18
20
  EM.run do
19
21
  server.setup_redis
@@ -35,15 +37,19 @@ module Sensu
35
37
  config = Sensu::Config.new(options)
36
38
  @settings = config.settings
37
39
  @logger = config.logger || config.open_log
40
+ @status = nil
38
41
  end
39
42
 
40
- def stop(signal)
41
- @logger.warn('[process] -- ' + signal + ' -- stopping sensu server')
42
- EM.add_timer(1) do
43
+ def stop_reactor
44
+ EM.add_timer(3) do
43
45
  EM.stop
44
46
  end
45
47
  end
46
48
 
49
+ def stopping?
50
+ @status == :stopping
51
+ end
52
+
47
53
  def setup_redis
48
54
  @logger.debug('[redis] -- connecting to redis')
49
55
  @redis = Redis.connect(@settings.redis.to_hash.symbolize_keys)
@@ -230,9 +236,11 @@ module Sensu
230
236
  end
231
237
  interval = options[:test] ? 0.5 : details.interval
232
238
  EM.add_periodic_timer(interval) do
233
- check_request.issued = Time.now.to_i
234
- @logger.info('[publisher] -- publishing check -- ' + name + ' -- ' + exchange)
235
- @amq.fanout(exchange).publish(check_request.to_json)
239
+ unless stopping?
240
+ check_request.issued = Time.now.to_i
241
+ @logger.info('[publisher] -- publishing check -- ' + name + ' -- ' + exchange)
242
+ @amq.fanout(exchange).publish(check_request.to_json)
243
+ end
236
244
  end
237
245
  end
238
246
  end
@@ -243,34 +251,36 @@ module Sensu
243
251
  def setup_keepalive_monitor
244
252
  @logger.debug('[keepalive] -- setup keepalive monitor')
245
253
  EM.add_periodic_timer(30) do
246
- @logger.debug('[keepalive] -- checking for stale clients')
247
- @redis.smembers('clients').callback do |clients|
248
- clients.each do |client_id|
249
- @redis.get('client:' + client_id).callback do |client_json|
250
- client = Hashie::Mash.new(JSON.parse(client_json))
251
- time_since_last_keepalive = Time.now.to_i - client.timestamp
252
- result = Hashie::Mash.new({
253
- :client => client.name,
254
- :check => {
255
- :name => 'keepalive',
256
- :issued => Time.now.to_i
257
- }
258
- })
259
- case
260
- when time_since_last_keepalive >= 180
261
- result.check.status = 2
262
- result.check.output = 'No keep-alive sent from host in over 180 seconds'
263
- @amq.queue('results').publish(result.to_json)
264
- when time_since_last_keepalive >= 120
265
- result.check.status = 1
266
- result.check.output = 'No keep-alive sent from host in over 120 seconds'
267
- @amq.queue('results').publish(result.to_json)
268
- else
269
- @redis.hexists('events:' + client_id, 'keepalive').callback do |exists|
270
- if exists
271
- result.check.status = 0
272
- result.check.output = 'Keep-alive sent from host'
273
- @amq.queue('results').publish(result.to_json)
254
+ unless stopping?
255
+ @logger.debug('[keepalive] -- checking for stale clients')
256
+ @redis.smembers('clients').callback do |clients|
257
+ clients.each do |client_id|
258
+ @redis.get('client:' + client_id).callback do |client_json|
259
+ client = Hashie::Mash.new(JSON.parse(client_json))
260
+ time_since_last_keepalive = Time.now.to_i - client.timestamp
261
+ result = Hashie::Mash.new({
262
+ :client => client.name,
263
+ :check => {
264
+ :name => 'keepalive',
265
+ :issued => Time.now.to_i
266
+ }
267
+ })
268
+ case
269
+ when time_since_last_keepalive >= 180
270
+ result.check.status = 2
271
+ result.check.output = 'No keep-alive sent from host in over 180 seconds'
272
+ @amq.queue('results').publish(result.to_json)
273
+ when time_since_last_keepalive >= 120
274
+ result.check.status = 1
275
+ result.check.output = 'No keep-alive sent from host in over 120 seconds'
276
+ @amq.queue('results').publish(result.to_json)
277
+ else
278
+ @redis.hexists('events:' + client_id, 'keepalive').callback do |exists|
279
+ if exists
280
+ result.check.status = 0
281
+ result.check.output = 'Keep-alive sent from host'
282
+ @amq.queue('results').publish(result.to_json)
283
+ end
274
284
  end
275
285
  end
276
286
  end
@@ -311,13 +321,15 @@ module Sensu
311
321
  def setup_master_monitor
312
322
  request_master_election
313
323
  EM.add_periodic_timer(20) do
314
- if @is_master
315
- timestamp = Time.now.to_i
316
- @redis.set('lock:master', timestamp).callback do
317
- @logger.debug('[master] -- updated master lock timestamp -- ' + timestamp.to_s)
324
+ unless stopping?
325
+ if @is_master
326
+ timestamp = Time.now.to_i
327
+ @redis.set('lock:master', timestamp).callback do
328
+ @logger.debug('[master] -- updated master lock timestamp -- ' + timestamp.to_s)
329
+ end
330
+ else
331
+ request_master_election
318
332
  end
319
- else
320
- request_master_election
321
333
  end
322
334
  end
323
335
  end
@@ -325,13 +337,34 @@ module Sensu
325
337
  def setup_queue_monitor
326
338
  @logger.debug('[monitor] -- setup queue monitor')
327
339
  EM.add_periodic_timer(5) do
328
- unless @keepalive_queue.subscribed?
329
- @logger.warn('[monitor] -- reconnecting to rabbitmq -- keepalives')
330
- setup_keepalives
340
+ unless stopping?
341
+ unless @keepalive_queue.subscribed?
342
+ @logger.warn('[monitor] -- re-subscribing to rabbitmq queue -- keepalives')
343
+ setup_keepalives
344
+ end
345
+ unless @result_queue.subscribed?
346
+ @logger.warn('[monitor] -- re-subscribing to rabbitmq queue -- results')
347
+ setup_results
348
+ end
331
349
  end
332
- unless @result_queue.subscribed?
333
- @logger.warn('[monitor] -- reconnecting to rabbitmq -- results')
334
- setup_results
350
+ end
351
+ end
352
+
353
+ def stop(signal)
354
+ @logger.warn('[stop] -- stopping sensu server -- ' + signal)
355
+ @status = :stopping
356
+ @keepalive_queue.unsubscribe do
357
+ @logger.warn('[stop] -- unsubscribed from rabbitmq queue -- keepalives')
358
+ @result_queue.unsubscribe do
359
+ @logger.warn('[stop] -- unsubscribed from rabbitmq queue -- results')
360
+ if @is_master
361
+ @redis.del('lock:master').callback do
362
+ @logger.warn('[stop] -- resigned as master')
363
+ stop_reactor
364
+ end
365
+ else
366
+ stop_reactor
367
+ end
335
368
  end
336
369
  end
337
370
  end
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196283
5
- prerelease: true
4
+ hash: 59
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 0
10
- - beta
11
- - 4
12
- version: 0.9.0.beta.4
10
+ version: 0.9.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Sean Porter
@@ -260,14 +258,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
260
258
  required_rubygems_version: !ruby/object:Gem::Requirement
261
259
  none: false
262
260
  requirements:
263
- - - ">"
261
+ - - ">="
264
262
  - !ruby/object:Gem::Version
265
- hash: 25
263
+ hash: 3
266
264
  segments:
267
- - 1
268
- - 3
269
- - 1
270
- version: 1.3.1
265
+ - 0
266
+ version: "0"
271
267
  requirements: []
272
268
 
273
269
  rubyforge_project: