sensu 0.11.0.beta.2 → 0.11.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -9,6 +9,9 @@ are an experimental feature and not widely used.
9
9
  Sensu settings are now part of the extension API & are no longer passed
10
10
  as an argument to run.
11
11
 
12
+ TCP handlers no longer have a socket timeout, instead they have a
13
+ handler timeout for consistency.
14
+
12
15
  ### Features
13
16
 
14
17
  You can specify the Sensu log severity level using the -L (--log_level)
@@ -24,6 +27,8 @@ You can configure the Sensu client socket (UDP & TCP), bind & port, eg.
24
27
  You can choose to reconnect to RabbitMQ on initial TCP connection
25
28
  failure, eg. "rabbitmq": { "on_failure": "reconnect" }.
26
29
 
30
+ Handlers & mutators can now have a timeout, in seconds.
31
+
27
32
  ### Other
28
33
 
29
34
  Sensu passes a dup of event data to mutator & handler extensions to
@@ -44,6 +49,8 @@ The keepalive & result queues will now auto-delete when there are no
44
49
  active consumers. This change stops the creation of a keepalive/result
45
50
  backlog, stale data that may overwhelm the recovering consumers.
46
51
 
52
+ Improved Sensu client socket check validation.
53
+
47
54
  ## 0.10.2 - 2013-07-18
48
55
 
49
56
  ### Other
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  unless defined?(Sensu::VERSION)
3
- VERSION = '0.11.0.beta.2'
3
+ VERSION = '0.11.0.beta.3'
4
4
 
5
5
  LOG_LEVELS = [:debug, :info, :warn, :error, :fatal]
6
6
 
data/lib/sensu/io.rb CHANGED
@@ -44,6 +44,25 @@ module Sensu
44
44
  end
45
45
  end
46
46
 
47
+ def async_popen(command, data=nil, timeout=nil, &block)
48
+ execute = Proc.new do
49
+ begin
50
+ popen(command, 'r+', timeout) do |child|
51
+ unless data.nil?
52
+ child.write(data.to_s)
53
+ end
54
+ child.close_write
55
+ end
56
+ rescue => error
57
+ [error.to_s, 2]
58
+ end
59
+ end
60
+ complete = Proc.new do |output, status|
61
+ block.call(output, status) if block
62
+ end
63
+ EM::defer(execute, complete)
64
+ end
65
+
47
66
  private
48
67
 
49
68
  def kill_process_group(group_id)
data/lib/sensu/server.rb CHANGED
@@ -237,55 +237,23 @@ module Sensu
237
237
  end
238
238
  end
239
239
 
240
- def execute_command(command, data=nil, on_error=nil, &block)
241
- on_error ||= Proc.new do |error|
242
- @logger.error('failed to execute command', {
243
- :command => command,
244
- :data => data,
245
- :error => error.to_s
246
- })
247
- end
248
- execute = Proc.new do
249
- begin
250
- output, status = IO.popen(command, 'r+') do |child|
251
- unless data.nil?
252
- child.write(data.to_s)
253
- end
254
- child.close_write
255
- end
256
- [true, output, status]
257
- rescue => error
258
- on_error.call(error)
259
- [false, nil, nil]
260
- end
261
- end
262
- complete = Proc.new do |success, output, status|
263
- if success
264
- block.call(output, status)
265
- end
266
- end
267
- EM::defer(execute, complete)
268
- end
269
-
270
240
  def mutate_event_data(mutator_name, event, &block)
271
241
  case
272
242
  when mutator_name.nil?
273
243
  block.call(Oj.dump(event))
274
244
  when @settings.mutator_exists?(mutator_name)
275
245
  mutator = @settings[:mutators][mutator_name]
276
- on_error = Proc.new do |error|
277
- @logger.error('mutator error', {
278
- :event => event,
279
- :mutator => mutator,
280
- :error => error.to_s
281
- })
282
- @handlers_in_progress_count -= 1
283
- end
284
- execute_command(mutator[:command], Oj.dump(event), on_error) do |output, status|
246
+ IO.async_popen(mutator[:command], Oj.dump(event), mutator[:timeout]) do |output, status|
285
247
  if status == 0
286
248
  block.call(output)
287
249
  else
288
- on_error.call('non-zero exit status (' + status.to_s + '): ' + output)
250
+ @logger.error('mutator error', {
251
+ :event => event,
252
+ :mutator => mutator,
253
+ :output => output,
254
+ :status => status
255
+ })
256
+ @handlers_in_progress_count -= 1
289
257
  end
290
258
  end
291
259
  when @extensions.mutator_exists?(mutator_name)
@@ -294,10 +262,11 @@ module Sensu
294
262
  if status == 0
295
263
  block.call(output)
296
264
  else
297
- @logger.error('mutator error', {
265
+ @logger.error('mutator extension error', {
298
266
  :event => event,
299
267
  :extension => extension.definition,
300
- :error => 'non-zero exit status (' + status.to_s + '): ' + output
268
+ :output => output,
269
+ :status => status
301
270
  })
302
271
  @handlers_in_progress_count -= 1
303
272
  end
@@ -330,9 +299,12 @@ module Sensu
330
299
  mutate_event_data(handler[:mutator], event) do |event_data|
331
300
  case handler[:type]
332
301
  when 'pipe'
333
- execute_command(handler[:command], event_data, on_error) do |output, status|
334
- output.split(/\n+/).each do |line|
335
- @logger.info(line)
302
+ IO.async_popen(handler[:command], event_data, handler[:timeout]) do |output, status|
303
+ output.each_line do |line|
304
+ @logger.info('handler output', {
305
+ :handler => handler,
306
+ :output => line
307
+ })
336
308
  end
337
309
  @handlers_in_progress_count -= 1
338
310
  end
@@ -343,7 +315,7 @@ module Sensu
343
315
  @handlers_in_progress_count -= 1
344
316
  end
345
317
  socket.on_error = on_error
346
- timeout = handler[:socket][:timeout] || 10
318
+ timeout = handler[:timeout] || 10
347
319
  socket.pending_connect_timeout = timeout
348
320
  socket.comm_inactivity_timeout = timeout
349
321
  socket.send_data(event_data.to_s)
@@ -374,8 +346,11 @@ module Sensu
374
346
  @handlers_in_progress_count -= 1
375
347
  when 'extension'
376
348
  handler.safe_run(event_data) do |output, status|
377
- output.split(/\n+/).each do |line|
378
- @logger.info(line)
349
+ output.each_line do |line|
350
+ @logger.info('handler extension output', {
351
+ :extension => handler.definition,
352
+ :output => line
353
+ })
379
354
  end
380
355
  @handlers_in_progress_count -= 1
381
356
  end
@@ -272,6 +272,11 @@ module Sensu
272
272
  unless mutator[:command].is_a?(String)
273
273
  invalid_mutator(mutator, 'mutator is missing command')
274
274
  end
275
+ if mutator.has_key?(:timeout)
276
+ unless mutator[:timeout].is_a?(Numeric)
277
+ invalid_mutator(mutator, 'mutator timeout must be numeric')
278
+ end
279
+ end
275
280
  end
276
281
 
277
282
  def validate_filter(filter)
@@ -304,11 +309,6 @@ module Sensu
304
309
  unless handler[:socket][:port].is_a?(Integer)
305
310
  invalid_handler(handler, 'handler is missing socket port')
306
311
  end
307
- if handler[:socket].has_key?(:timeout)
308
- unless handler[:socket][:timeout].is_a?(Integer)
309
- invalid_handler(handler, 'handler socket timeout must be an integer')
310
- end
311
- end
312
312
  when 'amqp'
313
313
  unless handler[:exchange].is_a?(Hash)
314
314
  invalid_handler(handler, 'handler is missing exchange hash')
@@ -336,6 +336,11 @@ module Sensu
336
336
  else
337
337
  invalid_handler(handler, 'unknown handler type')
338
338
  end
339
+ if handler.has_key?(:timeout)
340
+ unless handler[:timeout].is_a?(Numeric)
341
+ invalid_handler(handler, 'handler timeout must be numeric')
342
+ end
343
+ end
339
344
  if handler.has_key?(:filter)
340
345
  unless handler[:filter].is_a?(String)
341
346
  invalid_handler(handler, 'handler filter must be a string')
data/lib/sensu/socket.rb CHANGED
@@ -21,12 +21,14 @@ module Sensu
21
21
  })
22
22
  begin
23
23
  check = Oj.load(data)
24
- validates = [:name, :output].all? do |key|
25
- check[key].is_a?(String)
26
- end
27
24
  check[:issued] = Time.now.to_i
28
25
  check[:status] ||= 0
29
- if validates && check[:status].is_a?(Integer)
26
+ validates = [
27
+ check[:name] =~ /^[\w\.-]+$/,
28
+ check[:output].is_a?(String),
29
+ check[:status].is_a?(Integer)
30
+ ].all?
31
+ if validates
30
32
  payload = {
31
33
  :client => @settings[:client][:name],
32
34
  :check => check
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: 2750769037
4
+ hash: 1103939663
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 11
9
9
  - 0
10
10
  - beta
11
- - 2
12
- version: 0.11.0.beta.2
11
+ - 3
12
+ version: 0.11.0.beta.3
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-09-15 00:00:00 -07:00
21
+ date: 2013-09-20 00:00:00 -07:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency