sensu 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sensu/client.rb CHANGED
@@ -8,6 +8,7 @@ module Sensu
8
8
  client.setup_amqp
9
9
  client.setup_keepalives
10
10
  client.setup_subscriptions
11
+ client.monitor_queues
11
12
 
12
13
  Signal.trap('INT') do
13
14
  EM.stop
@@ -28,14 +29,14 @@ module Sensu
28
29
  def setup_amqp
29
30
  connection = AMQP.connect(symbolize_keys(@settings['rabbitmq']))
30
31
  @amq = MQ.new(connection)
32
+ @keepalive_queue = @amq.queue('keepalives')
31
33
  @result_queue = @amq.queue('results')
32
34
  end
33
35
 
34
36
  def setup_keepalives
35
- keepalive_queue = @amq.queue('keepalives')
36
- keepalive_queue.publish(@settings['client'].merge({'timestamp' => Time.now.to_i}).to_json)
37
+ @keepalive_queue.publish(@settings['client'].merge({'timestamp' => Time.now.to_i}).to_json)
37
38
  EM.add_periodic_timer(30) do
38
- keepalive_queue.publish(@settings['client'].merge({'timestamp' => Time.now.to_i}).to_json)
39
+ @keepalive_queue.publish(@settings['client'].merge({'timestamp' => Time.now.to_i}).to_json)
39
40
  end
40
41
  end
41
42
 
@@ -70,16 +71,22 @@ module Sensu
70
71
  end
71
72
 
72
73
  def setup_subscriptions
73
- uniq_queue = @amq.queue(UUIDTools::UUID.random_create.to_s, :exclusive => true)
74
+ @uniq_queue = @amq.queue(UUIDTools::UUID.random_create.to_s, :exclusive => true)
74
75
  @settings['client']['subscriptions'].each do |exchange|
75
- uniq_queue.bind(@amq.fanout(exchange))
76
+ @uniq_queue.bind(@amq.fanout(exchange))
76
77
  end
77
- EM.add_periodic_timer(0.5) do
78
- unless uniq_queue.subscribed?
79
- uniq_queue.subscribe(:ack => true) do |header, check_json|
80
- header.ack
81
- check = JSON.parse(check_json)
82
- execute_check(check)
78
+ @uniq_queue.subscribe do |check_json|
79
+ check = JSON.parse(check_json)
80
+ execute_check(check)
81
+ end
82
+ end
83
+
84
+ def monitor_queues
85
+ EM.add_periodic_timer(5) do
86
+ unless @uniq_queue.subscribed?
87
+ @uniq_queue.delete
88
+ EM.add_timer(1) do
89
+ setup_subscriptions
83
90
  end
84
91
  end
85
92
  end
data/lib/sensu/server.rb CHANGED
@@ -17,6 +17,7 @@ module Sensu
17
17
  server.setup_results
18
18
  server.setup_publisher
19
19
  server.setup_keepalive_monitor
20
+ server.monitor_queues
20
21
 
21
22
  Signal.trap('INT') do
22
23
  EM.stop
@@ -48,16 +49,11 @@ module Sensu
48
49
  end
49
50
 
50
51
  def setup_keepalives
51
- keepalive_queue = @amq.queue('keepalives')
52
- EM.add_periodic_timer(0.5) do
53
- unless keepalive_queue.subscribed?
54
- keepalive_queue.subscribe(:ack => true) do |header, keepalive_json|
55
- header.ack
56
- client = JSON.parse(keepalive_json)['name']
57
- @redis.set('client:' + client, keepalive_json).callback do
58
- @redis.sadd('clients', client)
59
- end
60
- end
52
+ @keepalive_queue = @amq.queue('keepalives')
53
+ @keepalive_queue.subscribe do |keepalive_json|
54
+ client = JSON.parse(keepalive_json)['name']
55
+ @redis.set('client:' + client, keepalive_json).callback do
56
+ @redis.sadd('clients', client)
61
57
  end
62
58
  end
63
59
  end
@@ -132,15 +128,10 @@ module Sensu
132
128
  end
133
129
 
134
130
  def setup_results
135
- result_queue = @amq.queue('results')
136
- EM.add_periodic_timer(0.5) do
137
- unless result_queue.subscribed?
138
- result_queue.subscribe(:ack => true) do |header, result_json|
139
- header.ack
140
- result = JSON.parse(result_json)
141
- process_result(result)
142
- end
143
- end
131
+ @result_queue = @amq.queue('results')
132
+ @result_queue.subscribe do |result_json|
133
+ result = JSON.parse(result_json)
134
+ process_result(result)
144
135
  end
145
136
  end
146
137
 
@@ -192,5 +183,22 @@ module Sensu
192
183
  end
193
184
  end
194
185
  end
186
+
187
+ def monitor_queues
188
+ EM.add_periodic_timer(5) do
189
+ unless @keepalive_queue.subscribed?
190
+ @keepalive_queue.delete
191
+ EM.add_timer(1) do
192
+ setup_keepalives
193
+ end
194
+ end
195
+ unless @result_queue.subscribed?
196
+ @result_queue.delete
197
+ EM.add_timer(1) do
198
+ setup_results
199
+ end
200
+ end
201
+ end
202
+ end
195
203
  end
196
204
  end
data/sensu.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sensu"
3
- s.version = "0.5.11"
3
+ s.version = "0.5.12"
4
4
  s.authors = ["Sean Porter", "Justin Kolberg"]
5
5
  s.email = ["sean.porter@sonian.net", "justin.kolberg@sonian.net"]
6
6
  s.homepage = "https://github.com/sonian/sensu"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.11
5
+ version: 0.5.12
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sean Porter