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 +18 -11
- data/lib/sensu/server.rb +27 -19
- data/sensu.gemspec +1 -1
- metadata +1 -1
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
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
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