sensu 0.9.5.beta.3 → 0.9.5.beta.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sensu/client.rb +26 -18
- data/lib/sensu/config.rb +2 -2
- data/lib/sensu/patches/redis.rb +3 -3
- data/lib/sensu/patches/ruby.rb +3 -3
- data/lib/sensu/server.rb +28 -18
- data/lib/sensu/version.rb +1 -1
- metadata +4 -4
data/lib/sensu/client.rb
CHANGED
@@ -12,10 +12,10 @@ module Sensu
|
|
12
12
|
end
|
13
13
|
EM::threadpool_size = 14
|
14
14
|
EM::run do
|
15
|
-
client.
|
15
|
+
client.setup_rabbitmq
|
16
16
|
client.setup_keepalives
|
17
17
|
client.setup_subscriptions
|
18
|
-
client.
|
18
|
+
client.setup_rabbitmq_monitor
|
19
19
|
client.setup_standalone
|
20
20
|
client.setup_socket
|
21
21
|
|
@@ -35,8 +35,8 @@ module Sensu
|
|
35
35
|
@checks_in_progress = Array.new
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
39
|
-
@logger.debug('[
|
38
|
+
def setup_rabbitmq
|
39
|
+
@logger.debug('[rabbitmq] -- connecting to rabbitmq')
|
40
40
|
@rabbitmq = AMQP.connect(@settings.rabbitmq.to_hash.symbolize_keys)
|
41
41
|
@amq = AMQP::Channel.new(@rabbitmq)
|
42
42
|
end
|
@@ -51,7 +51,9 @@ module Sensu
|
|
51
51
|
@logger.debug('[keepalive] -- setup keepalives')
|
52
52
|
publish_keepalive
|
53
53
|
@timers << EM::PeriodicTimer.new(30) do
|
54
|
-
|
54
|
+
unless @rabbitmq.reconnecting?
|
55
|
+
publish_keepalive
|
56
|
+
end
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -118,7 +120,7 @@ module Sensu
|
|
118
120
|
@checks_in_progress.delete(check.name)
|
119
121
|
end
|
120
122
|
else
|
121
|
-
@logger.
|
123
|
+
@logger.warn('[execute] -- previous check execution still in progress -- ' + check.name)
|
122
124
|
end
|
123
125
|
else
|
124
126
|
@logger.warn('[execute] -- unkown check -- ' + check.name)
|
@@ -148,23 +150,27 @@ module Sensu
|
|
148
150
|
@logger.warn('[subscribe] -- invalid check request: ' + check_request_json)
|
149
151
|
end
|
150
152
|
rescue JSON::ParserError => error
|
151
|
-
@logger.warn('[subscribe] -- check request must be valid
|
153
|
+
@logger.warn('[subscribe] -- check request must be valid json: ' + error.to_s)
|
152
154
|
end
|
153
155
|
end
|
154
156
|
end
|
155
157
|
|
156
|
-
def
|
157
|
-
@logger.debug('[monitor] -- setup
|
158
|
+
def setup_rabbitmq_monitor
|
159
|
+
@logger.debug('[monitor] -- setup rabbitmq monitor')
|
158
160
|
@timers << EM::PeriodicTimer.new(5) do
|
159
|
-
|
160
|
-
@logger.warn('[monitor] --
|
161
|
-
|
161
|
+
if @rabbitmq.reconnecting?
|
162
|
+
@logger.warn('[monitor] -- reconnecting to rabbitmq')
|
163
|
+
else
|
164
|
+
unless @check_request_queue.subscribed?
|
165
|
+
@logger.warn('[monitor] -- re-subscribing to client subscriptions')
|
166
|
+
setup_subscriptions
|
167
|
+
end
|
162
168
|
end
|
163
169
|
end
|
164
170
|
end
|
165
171
|
|
166
172
|
def setup_standalone(options={})
|
167
|
-
@logger.debug('[standalone] -- setup standalone')
|
173
|
+
@logger.debug('[standalone] -- setup standalone checks')
|
168
174
|
standalone_check_count = 0
|
169
175
|
@settings.checks.each do |name, details|
|
170
176
|
if details.standalone
|
@@ -174,8 +180,10 @@ module Sensu
|
|
174
180
|
@timers << EM::Timer.new(stagger*standalone_check_count) do
|
175
181
|
interval = options[:test] ? 0.5 : details.interval
|
176
182
|
@timers << EM::PeriodicTimer.new(interval) do
|
177
|
-
|
178
|
-
|
183
|
+
unless @rabbitmq.reconnecting?
|
184
|
+
check.issued = Time.now.to_i
|
185
|
+
execute_check(check)
|
186
|
+
end
|
179
187
|
end
|
180
188
|
end
|
181
189
|
end
|
@@ -183,7 +191,7 @@ module Sensu
|
|
183
191
|
end
|
184
192
|
|
185
193
|
def setup_socket
|
186
|
-
@logger.debug('[socket] -- starting up socket')
|
194
|
+
@logger.debug('[socket] -- starting up client tcp socket')
|
187
195
|
EM::start_server('127.0.0.1', 3030, ClientSocket) do |socket|
|
188
196
|
socket.settings = @settings
|
189
197
|
socket.logger = @logger
|
@@ -212,7 +220,7 @@ module Sensu
|
|
212
220
|
timer.cancel
|
213
221
|
end
|
214
222
|
unless @rabbitmq.reconnecting?
|
215
|
-
@logger.warn('[stop] -- unsubscribing from subscriptions')
|
223
|
+
@logger.warn('[stop] -- unsubscribing from client subscriptions')
|
216
224
|
@check_request_queue.unsubscribe do
|
217
225
|
stop_reactor
|
218
226
|
end
|
@@ -250,7 +258,7 @@ module Sensu
|
|
250
258
|
send_data('invalid')
|
251
259
|
end
|
252
260
|
rescue JSON::ParserError => error
|
253
|
-
@logger.warn('[socket] -- check result must be valid
|
261
|
+
@logger.warn('[socket] -- check result must be valid json: ' + error.to_s)
|
254
262
|
send_data('invalid')
|
255
263
|
end
|
256
264
|
end
|
data/lib/sensu/config.rb
CHANGED
@@ -204,7 +204,7 @@ module Sensu
|
|
204
204
|
config_hash[key] ||= Hash.new
|
205
205
|
end
|
206
206
|
rescue JSON::ParserError => error
|
207
|
-
invalid_config('configuration file (' + @options[:config_file] + ') must be valid
|
207
|
+
invalid_config('configuration file (' + @options[:config_file] + ') must be valid json: ' + error.to_s)
|
208
208
|
end
|
209
209
|
@settings = Hashie::Mash.new(config_hash)
|
210
210
|
else
|
@@ -216,7 +216,7 @@ module Sensu
|
|
216
216
|
begin
|
217
217
|
snippet_hash = JSON.parse(File.open(snippet_file, 'r').read)
|
218
218
|
rescue JSON::ParserError => error
|
219
|
-
invalid_config('configuration snippet file (' + snippet_file + ') must be valid
|
219
|
+
invalid_config('configuration snippet file (' + snippet_file + ') must be valid json: ' + error.to_s)
|
220
220
|
end
|
221
221
|
merged_settings = @settings.to_hash.deep_merge(snippet_hash)
|
222
222
|
@logger.warn('[settings] -- configuration snippet (' + snippet_file + ') applied changes: ' + @settings.deep_diff(merged_settings).to_json)
|
data/lib/sensu/patches/redis.rb
CHANGED
@@ -8,14 +8,14 @@ module Redis
|
|
8
8
|
if @redis_password
|
9
9
|
auth(@redis_password).callback do |reply|
|
10
10
|
unless reply == "OK"
|
11
|
-
raise
|
11
|
+
raise('could not authenticate')
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
info.callback do |reply|
|
16
16
|
redis_version = reply.split(/\n/).first.split(/:/).last
|
17
17
|
unless redis_version.to_i >= 2
|
18
|
-
raise
|
18
|
+
raise('redis version must be >= 2.0')
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -36,7 +36,7 @@ module Redis
|
|
36
36
|
@queue.shift.fail RuntimeError.new('connection closed')
|
37
37
|
end
|
38
38
|
unless @connected
|
39
|
-
raise
|
39
|
+
raise('could not connect to redis')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
data/lib/sensu/patches/ruby.rb
CHANGED
@@ -48,14 +48,14 @@ end
|
|
48
48
|
module Process
|
49
49
|
def self.write_pid(pid_file)
|
50
50
|
if pid_file.nil?
|
51
|
-
raise
|
51
|
+
raise('a pid file path must be provided')
|
52
52
|
end
|
53
53
|
begin
|
54
54
|
File.open(pid_file, 'w') do |file|
|
55
55
|
file.write(self.pid.to_s + "\n")
|
56
56
|
end
|
57
57
|
rescue
|
58
|
-
raise
|
58
|
+
raise('could not write to pid file: ' + pid_file)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -63,7 +63,7 @@ module Process
|
|
63
63
|
srand
|
64
64
|
fork and exit
|
65
65
|
unless session_id = self.setsid
|
66
|
-
raise
|
66
|
+
raise('cannot detach from controlling terminal')
|
67
67
|
end
|
68
68
|
trap 'SIGHUP', 'IGNORE'
|
69
69
|
if pid = fork
|
data/lib/sensu/server.rb
CHANGED
@@ -19,11 +19,11 @@ module Sensu
|
|
19
19
|
EM::threadpool_size = 14
|
20
20
|
EM::run do
|
21
21
|
server.setup_redis
|
22
|
-
server.
|
22
|
+
server.setup_rabbitmq
|
23
23
|
server.setup_keepalives
|
24
24
|
server.setup_results
|
25
25
|
server.setup_master_monitor
|
26
|
-
server.
|
26
|
+
server.setup_rabbitmq_monitor
|
27
27
|
|
28
28
|
%w[INT TERM].each do |signal|
|
29
29
|
Signal.trap(signal) do
|
@@ -46,8 +46,8 @@ module Sensu
|
|
46
46
|
@redis = Redis.connect(@settings.redis.to_hash.symbolize_keys)
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
@logger.debug('[
|
49
|
+
def setup_rabbitmq
|
50
|
+
@logger.debug('[rabbitmq] -- connecting to rabbitmq')
|
51
51
|
@rabbitmq = AMQP.connect(@settings.rabbitmq.to_hash.symbolize_keys)
|
52
52
|
@amq = AMQP::Channel.new(@rabbitmq)
|
53
53
|
end
|
@@ -243,9 +243,11 @@ module Sensu
|
|
243
243
|
details.subscribers.each do |exchange|
|
244
244
|
interval = options[:test] ? 0.5 : details.interval
|
245
245
|
@timers << EM::PeriodicTimer.new(interval) do
|
246
|
-
@
|
247
|
-
|
248
|
-
|
246
|
+
unless @rabbitmq.reconnecting?
|
247
|
+
@logger.info('[publisher] -- publishing check request -- ' + name + ' -- ' + exchange)
|
248
|
+
check_request.issued = Time.now.to_i
|
249
|
+
@amq.fanout(exchange).publish(check_request.to_json)
|
250
|
+
end
|
249
251
|
end
|
250
252
|
end
|
251
253
|
end
|
@@ -325,11 +327,15 @@ module Sensu
|
|
325
327
|
if @is_master
|
326
328
|
@redis.del('lock:master').callback do
|
327
329
|
@logger.warn('[master] -- resigned as master')
|
328
|
-
|
330
|
+
if block
|
331
|
+
block.call
|
332
|
+
end
|
329
333
|
end
|
330
334
|
else
|
331
335
|
@logger.warn('[master] -- not currently master')
|
332
|
-
|
336
|
+
if block
|
337
|
+
block.call
|
338
|
+
end
|
333
339
|
end
|
334
340
|
end
|
335
341
|
|
@@ -347,16 +353,20 @@ module Sensu
|
|
347
353
|
end
|
348
354
|
end
|
349
355
|
|
350
|
-
def
|
351
|
-
@logger.debug('[monitor] -- setup
|
356
|
+
def setup_rabbitmq_monitor
|
357
|
+
@logger.debug('[monitor] -- setup rabbitmq monitor')
|
352
358
|
@timers << EM::PeriodicTimer.new(5) do
|
353
|
-
|
354
|
-
@logger.warn('[monitor] --
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
359
|
+
if @rabbitmq.reconnecting?
|
360
|
+
@logger.warn('[monitor] -- reconnecting to rabbitmq')
|
361
|
+
else
|
362
|
+
unless @keepalive_queue.subscribed?
|
363
|
+
@logger.warn('[monitor] -- re-subscribing to keepalives')
|
364
|
+
setup_keepalives
|
365
|
+
end
|
366
|
+
unless @result_queue.subscribed?
|
367
|
+
@logger.warn('[monitor] -- re-subscribing to results')
|
368
|
+
setup_results
|
369
|
+
end
|
360
370
|
end
|
361
371
|
end
|
362
372
|
end
|
data/lib/sensu/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196243
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
9
|
- 5
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 0.9.5.beta.
|
11
|
+
- 4
|
12
|
+
version: 0.9.5.beta.4
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Sean Porter
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2012-03-
|
21
|
+
date: 2012-03-27 00:00:00 -07:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|