sensu 0.11.0.beta.1 → 0.11.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +15 -2
- data/lib/sensu/api.rb +41 -40
- data/lib/sensu/client.rb +8 -4
- data/lib/sensu/constants.rb +1 -1
- data/lib/sensu/rabbitmq.rb +10 -5
- data/lib/sensu/server.rb +54 -48
- data/lib/sensu/settings.rb +15 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -15,8 +15,14 @@ You can specify the Sensu log severity level using the -L (--log_level)
|
|
15
15
|
CLI argument, providing a valid level (eg. warn).
|
16
16
|
|
17
17
|
You can specify custom sensitive Sensu client key/values to be redacted
|
18
|
-
from log events and keepalives, eg. "client": { "redact":
|
19
|
-
|
18
|
+
from log events and keepalives, eg. "client": { "redact": [
|
19
|
+
"secret_access_key" ] }.
|
20
|
+
|
21
|
+
You can configure the Sensu client socket (UDP & TCP), bind & port, eg.
|
22
|
+
"client": { "socket": { "bind": "0.0.0.0", "port": 4040 } }.
|
23
|
+
|
24
|
+
You can choose to reconnect to RabbitMQ on initial TCP connection
|
25
|
+
failure, eg. "rabbitmq": { "on_failure": "reconnect" }.
|
20
26
|
|
21
27
|
### Other
|
22
28
|
|
@@ -29,8 +35,15 @@ UDP handler now binds to "0.0.0.0".
|
|
29
35
|
|
30
36
|
Faster JSON parser.
|
31
37
|
|
38
|
+
AMQP connection heartbeats will no longer attempt to use a closed
|
39
|
+
channel.
|
40
|
+
|
32
41
|
Missing AMQP connection heartbeats will result in a reconnect.
|
33
42
|
|
43
|
+
The keepalive & result queues will now auto-delete when there are no
|
44
|
+
active consumers. This change stops the creation of a keepalive/result
|
45
|
+
backlog, stale data that may overwhelm the recovering consumers.
|
46
|
+
|
34
47
|
## 0.10.2 - 2013-07-18
|
35
48
|
|
36
49
|
### Other
|
data/lib/sensu/api.rb
CHANGED
@@ -188,6 +188,33 @@ module Sensu
|
|
188
188
|
body ''
|
189
189
|
end
|
190
190
|
|
191
|
+
def rabbitmq_info(&block)
|
192
|
+
info = {
|
193
|
+
:keepalives => {
|
194
|
+
:messages => nil,
|
195
|
+
:consumers => nil
|
196
|
+
},
|
197
|
+
:results => {
|
198
|
+
:messages => nil,
|
199
|
+
:consumers => nil
|
200
|
+
},
|
201
|
+
:connected => $rabbitmq.connected?
|
202
|
+
}
|
203
|
+
if $rabbitmq.connected?
|
204
|
+
$amq.queue('keepalives', :auto_delete => true).status do |messages, consumers|
|
205
|
+
info[:keepalives][:messages] = messages
|
206
|
+
info[:keepalives][:consumers] = consumers
|
207
|
+
$amq.queue('results', :auto_delete => true).status do |messages, consumers|
|
208
|
+
info[:results][:messages] = messages
|
209
|
+
info[:results][:consumers] = consumers
|
210
|
+
block.call(info)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
else
|
214
|
+
block.call(info)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
191
218
|
def event_hash(event_json, client_name, check_name)
|
192
219
|
Oj.load(event_json).merge(
|
193
220
|
:client => client_name,
|
@@ -220,36 +247,16 @@ module Sensu
|
|
220
247
|
end
|
221
248
|
|
222
249
|
aget '/info' do
|
223
|
-
|
224
|
-
|
225
|
-
:
|
226
|
-
|
227
|
-
:rabbitmq => {
|
228
|
-
:keepalives => {
|
229
|
-
:messages => nil,
|
230
|
-
:consumers => nil
|
231
|
-
},
|
232
|
-
:results => {
|
233
|
-
:messages => nil,
|
234
|
-
:consumers => nil
|
250
|
+
rabbitmq_info do |info|
|
251
|
+
response = {
|
252
|
+
:sensu => {
|
253
|
+
:version => VERSION
|
235
254
|
},
|
236
|
-
:
|
237
|
-
|
238
|
-
|
239
|
-
|
255
|
+
:rabbitmq => info,
|
256
|
+
:redis => {
|
257
|
+
:connected => $redis.connected?
|
258
|
+
}
|
240
259
|
}
|
241
|
-
}
|
242
|
-
if $rabbitmq.connected?
|
243
|
-
$amq.queue('keepalives').status do |messages, consumers|
|
244
|
-
response[:rabbitmq][:keepalives][:messages] = messages
|
245
|
-
response[:rabbitmq][:keepalives][:consumers] = consumers
|
246
|
-
$amq.queue('results').status do |messages, consumers|
|
247
|
-
response[:rabbitmq][:results][:messages] = messages
|
248
|
-
response[:rabbitmq][:results][:consumers] = consumers
|
249
|
-
body Oj.dump(response)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
else
|
253
260
|
body Oj.dump(response)
|
254
261
|
end
|
255
262
|
end
|
@@ -259,22 +266,16 @@ module Sensu
|
|
259
266
|
healthy = Array.new
|
260
267
|
min_consumers = integer_parameter(params[:consumers])
|
261
268
|
max_messages = integer_parameter(params[:messages])
|
262
|
-
|
269
|
+
rabbitmq_info do |info|
|
263
270
|
if min_consumers
|
264
|
-
healthy << (consumers >= min_consumers)
|
271
|
+
healthy << (info[:keepalives][:consumers] >= min_consumers)
|
272
|
+
healthy << (info[:results][:consumers] >= min_consumers)
|
265
273
|
end
|
266
274
|
if max_messages
|
267
|
-
healthy << (messages <= max_messages)
|
268
|
-
|
269
|
-
$amq.queue('results').status do |messages, consumers|
|
270
|
-
if min_consumers
|
271
|
-
healthy << (consumers >= min_consumers)
|
272
|
-
end
|
273
|
-
if max_messages
|
274
|
-
healthy << (messages <= max_messages)
|
275
|
-
end
|
276
|
-
healthy.all? ? no_content! : unavailable!
|
275
|
+
healthy << (info[:keepalives][:messages] <= max_messages)
|
276
|
+
healthy << (info[:results][:messages] <= max_messages)
|
277
277
|
end
|
278
|
+
healthy.all? ? no_content! : unavailable!
|
278
279
|
end
|
279
280
|
else
|
280
281
|
unavailable!
|
data/lib/sensu/client.rb
CHANGED
@@ -229,14 +229,18 @@ module Sensu
|
|
229
229
|
end
|
230
230
|
|
231
231
|
def setup_sockets
|
232
|
-
@
|
233
|
-
|
232
|
+
options = @settings[:client][:socket] || Hash.new
|
233
|
+
options[:bind] ||= '127.0.0.1'
|
234
|
+
options[:port] ||= 3030
|
235
|
+
@logger.debug('binding client tcp and udp sockets', {
|
236
|
+
:options => options
|
237
|
+
})
|
238
|
+
EM::start_server(options[:bind], options[:port], Socket) do |socket|
|
234
239
|
socket.logger = @logger
|
235
240
|
socket.settings = @settings
|
236
241
|
socket.amq = @amq
|
237
242
|
end
|
238
|
-
|
239
|
-
EM::open_datagram_socket('127.0.0.1', 3030, Socket) do |socket|
|
243
|
+
EM::open_datagram_socket(options[:bind], options[:port], Socket) do |socket|
|
240
244
|
socket.logger = @logger
|
241
245
|
socket.settings = @settings
|
242
246
|
socket.amq = @amq
|
data/lib/sensu/constants.rb
CHANGED
data/lib/sensu/rabbitmq.rb
CHANGED
@@ -51,17 +51,22 @@ module Sensu
|
|
51
51
|
error = RabbitMQError.new('cannot connect to rabbitmq')
|
52
52
|
@on_error.call(error)
|
53
53
|
end
|
54
|
-
@connection = AMQP.connect(options, {
|
55
|
-
:on_tcp_connection_failure => on_failure,
|
56
|
-
:on_possible_authentication_failure => on_failure
|
57
|
-
})
|
58
|
-
@connection.logger = Logger.get
|
59
54
|
reconnect = Proc.new do
|
60
55
|
unless @connection.reconnecting?
|
61
56
|
@before_reconnect.call
|
62
57
|
@connection.periodically_reconnect(5)
|
63
58
|
end
|
64
59
|
end
|
60
|
+
if options.is_a?(Hash)
|
61
|
+
if options[:on_failure] == 'reconnect'
|
62
|
+
on_failure = reconnect
|
63
|
+
end
|
64
|
+
end
|
65
|
+
@connection = AMQP.connect(options, {
|
66
|
+
:on_tcp_connection_failure => on_failure,
|
67
|
+
:on_possible_authentication_failure => on_failure
|
68
|
+
})
|
69
|
+
@connection.logger = Logger.get
|
65
70
|
@connection.on_tcp_connection_loss(&reconnect)
|
66
71
|
@connection.on_skipped_heartbeats(&reconnect)
|
67
72
|
@channel = AMQP::Channel.new(@connection)
|
data/lib/sensu/server.rb
CHANGED
@@ -79,10 +79,12 @@ module Sensu
|
|
79
79
|
@amq.prefetch(1)
|
80
80
|
end
|
81
81
|
|
82
|
-
def setup_keepalives
|
82
|
+
def setup_keepalives(&block)
|
83
83
|
@logger.debug('subscribing to keepalives')
|
84
|
-
@keepalive_queue = @amq.queue!('keepalives')
|
85
|
-
@keepalive_queue.bind(@amq.direct('keepalives'))
|
84
|
+
@keepalive_queue = @amq.queue!('keepalives', :auto_delete => true)
|
85
|
+
@keepalive_queue.bind(@amq.direct('keepalives')) do
|
86
|
+
block.call if block
|
87
|
+
end
|
86
88
|
@keepalive_queue.subscribe(:ack => true) do |header, payload|
|
87
89
|
client = Oj.load(payload)
|
88
90
|
@logger.debug('received keepalive', {
|
@@ -96,51 +98,45 @@ module Sensu
|
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
99
|
-
def action_subdued?(
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
conditions.each do |condition|
|
110
|
-
if condition.has_key?(:begin) && condition.has_key?(:end)
|
111
|
-
begin_time = Time.parse(condition[:begin])
|
112
|
-
end_time = Time.parse(condition[:end])
|
113
|
-
if end_time < begin_time
|
114
|
-
if Time.now < end_time
|
115
|
-
begin_time = Time.parse('12:00:00 AM')
|
116
|
-
else
|
117
|
-
end_time = Time.parse('11:59:59 PM')
|
118
|
-
end
|
119
|
-
end
|
120
|
-
if Time.now >= begin_time && Time.now <= end_time
|
121
|
-
subdue = true
|
101
|
+
def action_subdued?(condition)
|
102
|
+
subdued = false
|
103
|
+
if condition.has_key?(:begin) && condition.has_key?(:end)
|
104
|
+
begin_time = Time.parse(condition[:begin])
|
105
|
+
end_time = Time.parse(condition[:end])
|
106
|
+
if end_time < begin_time
|
107
|
+
if Time.now < end_time
|
108
|
+
begin_time = Time.parse('12:00:00 AM')
|
109
|
+
else
|
110
|
+
end_time = Time.parse('11:59:59 PM')
|
122
111
|
end
|
123
112
|
end
|
124
|
-
if
|
125
|
-
|
126
|
-
if days.include?(Time.now.strftime('%A').downcase)
|
127
|
-
subdue = true
|
128
|
-
end
|
113
|
+
if Time.now >= begin_time && Time.now <= end_time
|
114
|
+
subdued = true
|
129
115
|
end
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
116
|
+
end
|
117
|
+
if condition.has_key?(:days)
|
118
|
+
days = condition[:days].map(&:downcase)
|
119
|
+
if days.include?(Time.now.strftime('%A').downcase)
|
120
|
+
subdued = true
|
134
121
|
end
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
subdue = false
|
140
|
-
end
|
122
|
+
end
|
123
|
+
if subdued && condition.has_key?(:exceptions)
|
124
|
+
subdued = condition[:exceptions].none? do |exception|
|
125
|
+
Time.now >= Time.parse(exception[:begin]) && Time.now <= Time.parse(exception[:end])
|
141
126
|
end
|
142
127
|
end
|
143
|
-
|
128
|
+
subdued
|
129
|
+
end
|
130
|
+
|
131
|
+
def handler_subdued?(handler, check)
|
132
|
+
subdued = Array.new
|
133
|
+
if handler[:subdue]
|
134
|
+
subdued << action_subdued?(handler[:subdue])
|
135
|
+
end
|
136
|
+
if check[:subdue] && check[:subdue][:at] != 'publisher'
|
137
|
+
subdued << action_subdued?(check[:subdue])
|
138
|
+
end
|
139
|
+
subdued.any?
|
144
140
|
end
|
145
141
|
|
146
142
|
def filter_attributes_match?(hash_one, hash_two)
|
@@ -208,8 +204,8 @@ module Sensu
|
|
208
204
|
})
|
209
205
|
next
|
210
206
|
end
|
211
|
-
if
|
212
|
-
@logger.info('
|
207
|
+
if handler_subdued?(handler, event[:check])
|
208
|
+
@logger.info('handler is subdued', {
|
213
209
|
:event => event,
|
214
210
|
:handler => handler
|
215
211
|
})
|
@@ -506,10 +502,12 @@ module Sensu
|
|
506
502
|
end
|
507
503
|
end
|
508
504
|
|
509
|
-
def setup_results
|
505
|
+
def setup_results(&block)
|
510
506
|
@logger.debug('subscribing to results')
|
511
|
-
@result_queue = @amq.queue!('results')
|
512
|
-
@result_queue.bind(@amq.direct('results'))
|
507
|
+
@result_queue = @amq.queue!('results', :auto_delete => true)
|
508
|
+
@result_queue.bind(@amq.direct('results')) do
|
509
|
+
block.call if block
|
510
|
+
end
|
513
511
|
@result_queue.subscribe(:ack => true) do |header, payload|
|
514
512
|
result = Oj.load(payload)
|
515
513
|
@logger.debug('received result', {
|
@@ -522,6 +520,14 @@ module Sensu
|
|
522
520
|
end
|
523
521
|
end
|
524
522
|
|
523
|
+
def check_request_subdued?(check)
|
524
|
+
if check[:subdue] && check[:subdue][:at] == 'publisher'
|
525
|
+
action_subdued?(check[:subdue])
|
526
|
+
else
|
527
|
+
false
|
528
|
+
end
|
529
|
+
end
|
530
|
+
|
525
531
|
def publish_check_request(check)
|
526
532
|
payload = {
|
527
533
|
:name => check[:name],
|
@@ -548,7 +554,7 @@ module Sensu
|
|
548
554
|
@master_timers << EM::Timer.new(scheduling_delay) do
|
549
555
|
interval = testing? ? 0.5 : check[:interval]
|
550
556
|
@master_timers << EM::PeriodicTimer.new(interval) do
|
551
|
-
unless
|
557
|
+
unless check_request_subdued?(check)
|
552
558
|
publish_check_request(check)
|
553
559
|
else
|
554
560
|
@logger.info('check request was subdued', {
|
data/lib/sensu/settings.rb
CHANGED
@@ -394,6 +394,21 @@ module Sensu
|
|
394
394
|
invalid('client subscriptions must each be a string')
|
395
395
|
end
|
396
396
|
end
|
397
|
+
if @settings[:client].has_key?(:socket)
|
398
|
+
unless @settings[:client][:socket].is_a?(Hash)
|
399
|
+
invalid('client socket must be a hash')
|
400
|
+
end
|
401
|
+
if @settings[:client][:socket].has_key?(:bind)
|
402
|
+
unless @settings[:client][:socket][:bind].is_a?(String)
|
403
|
+
invalid('client socket bind must be a string')
|
404
|
+
end
|
405
|
+
end
|
406
|
+
if @settings[:client][:socket].has_key?(:port)
|
407
|
+
unless @settings[:client][:socket][:port].is_a?(Integer)
|
408
|
+
invalid('client socket port must be an integer')
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
397
412
|
if @settings[:client].has_key?(:keepalive)
|
398
413
|
unless @settings[:client][:keepalive].is_a?(Hash)
|
399
414
|
invalid('client keepalive must be a hash')
|
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: 2750769037
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 11
|
9
9
|
- 0
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 0.11.0.beta.
|
11
|
+
- 2
|
12
|
+
version: 0.11.0.beta.2
|
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: 2013-
|
21
|
+
date: 2013-09-15 00:00:00 -07:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|