sensu 0.9.6 → 0.9.7.beta

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## 0.9.7 - TBD
2
+
3
+ ### Features
4
+
5
+ Event data mutators, manipulate event data and its format prior to
6
+ sending to a handler.
7
+
8
+ ### Non-backwards compatible changes
9
+
10
+ AMQP handlers can no longer use `"send_only_check_output": true`, but
11
+ instead have access to the built-in mutators `"mutator": "only_check_output"` and
12
+ `"mutator": "only_check_output_split"`.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # Sensu
2
+ A monitoring framework that aims to be simple, malleable, and scalable.
3
+
4
+ ![sensu](https://raw.github.com/sensu/sensu/master/sensu-logo.png)
5
+
6
+ ![travis](https://secure.travis-ci.org/sensu/sensu.png)
7
+
8
+ ## Documentation
9
+ Please refer to the [Sensu Wiki](https://github.com/sensu/sensu/wiki).
10
+
11
+ ## License
12
+ Sensu is released under the [MIT license](https://raw.github.com/sensu/sensu/master/MIT-LICENSE.txt).
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  unless defined?(Sensu::VERSION)
3
- VERSION = '0.9.6'
3
+ VERSION = '0.9.7.beta'
4
4
  end
5
5
 
6
6
  unless defined?(Sensu::DEFAULT_OPTIONS)
data/lib/sensu/server.rb CHANGED
@@ -154,6 +154,55 @@ module Sensu
154
154
  end
155
155
  end
156
156
 
157
+ def mutate_event_data(handler, event)
158
+ if handler.has_key?(:mutator)
159
+ mutated = nil
160
+ case handler[:mutator]
161
+ when /^only_check_output/
162
+ if handler[:type] == 'amqp' && handler[:mutator] =~ /split$/
163
+ mutated = Array.new
164
+ event[:check][:output].split(/\n+/).each do |line|
165
+ mutated.push(line)
166
+ end
167
+ else
168
+ mutated = event[:check][:output]
169
+ end
170
+ else
171
+ if @settings.mutator_exists?(handler[:mutator])
172
+ mutator = @settings[:mutators][handler[:mutator]]
173
+ begin
174
+ IO.popen(mutator[:command], 'r+') do |io|
175
+ io.write(event.to_json)
176
+ io.close_write
177
+ mutated = io.read
178
+ end
179
+ unless $?.exitstatus == 0
180
+ @logger.warn('mutator had a non-zero exit status', {
181
+ :event => event,
182
+ :mutator => mutator
183
+ })
184
+ end
185
+ rescue => error
186
+ @logger.error('mutator error', {
187
+ :event => event,
188
+ :mutator => mutator,
189
+ :error => error.to_s
190
+ })
191
+ end
192
+ else
193
+ @logger.error('unknown mutator', {
194
+ :mutator => {
195
+ :name => handler[:mutator]
196
+ }
197
+ })
198
+ end
199
+ end
200
+ mutated
201
+ else
202
+ event.to_json
203
+ end
204
+ end
205
+
157
206
  def handle_event(event)
158
207
  unless check_subdued?(event[:check], :handler)
159
208
  handlers = check_handlers(event[:check])
@@ -167,27 +216,18 @@ module Sensu
167
216
  when 'pipe'
168
217
  execute = Proc.new do
169
218
  begin
170
- IO.popen(handler[:command] + ' 2>&1', 'r+') do |io|
171
- io.write(event.to_json)
172
- io.close_write
173
- io.read.split(/\n+/).each do |line|
174
- @logger.info(line)
219
+ mutated_event_data = mutate_event_data(handler, event)
220
+ unless mutated_event_data.nil? || mutated_event_data.empty?
221
+ IO.popen(handler[:command] + ' 2>&1', 'r+') do |io|
222
+ io.write(mutated_event_data)
223
+ io.close_write
224
+ io.read.split(/\n+/).each do |line|
225
+ @logger.info(line)
226
+ end
175
227
  end
176
228
  end
177
- rescue Errno::ENOENT => error
178
- @logger.error('handler does not exist', {
179
- :event => event,
180
- :handler => handler,
181
- :error => error.to_s
182
- })
183
- rescue Errno::EPIPE => error
184
- @logger.error('broken pipe', {
185
- :event => event,
186
- :handler => handler,
187
- :error => error.to_s
188
- })
189
229
  rescue => error
190
- @logger.error('unexpected error', {
230
+ @logger.error('handler error', {
191
231
  :event => event,
192
232
  :handler => handler,
193
233
  :error => error.to_s
@@ -208,24 +248,18 @@ module Sensu
208
248
  :event => event,
209
249
  :exchange => handler[:exchange]
210
250
  })
211
- payloads = Array.new
212
- if handler[:send_only_check_output]
213
- if handler[:split_check_output]
214
- event[:check][:output].split(/\n+/).each do |line|
215
- payloads.push(line)
216
- end
217
- else
218
- payloads.push(event[:check][:output])
219
- end
220
- else
221
- payloads.push(event.to_json)
251
+ payloads = Proc.new do
252
+ Array(mutate_event_data(handler, event))
222
253
  end
223
- payloads.each do |payload|
224
- unless payload.empty?
225
- @amq.method(exchange_type).call(exchange_name, exchange_options).publish(payload)
254
+ publish = Proc.new do |payloads|
255
+ payloads.each do |payload|
256
+ unless payload.empty?
257
+ @amq.method(exchange_type).call(exchange_name, exchange_options).publish(payload)
258
+ end
226
259
  end
260
+ @handlers_in_progress -= 1
227
261
  end
228
- @handlers_in_progress -= 1
262
+ EM::defer(payloads, publish)
229
263
  when 'set'
230
264
  @logger.error('handler sets cannot be nested', {
231
265
  :handler => handler
@@ -5,7 +5,9 @@ module Sensu
5
5
  def initialize
6
6
  @logger = Cabin::Channel.get
7
7
  @settings = Hash.new
8
- @settings[:checks] = Hash.new
8
+ [:checks, :handlers, :mutators].each do |key|
9
+ @settings[key] = Hash.new
10
+ end
9
11
  @indifferent_access = false
10
12
  @loaded_env = false
11
13
  @loaded_files = Array.new
@@ -87,26 +89,18 @@ module Sensu
87
89
  ENV['SENSU_CONFIG_FILES'] = @loaded_files.join(':')
88
90
  end
89
91
 
90
- def checks
91
- @settings[:checks].map do |check_name, check_details|
92
- check_details.merge(:name => check_name.to_s)
92
+ [:checks, :handlers, :mutators].each do |key|
93
+ define_method(key) do
94
+ @settings[key].map do |name, details|
95
+ details.merge(:name => name.to_s)
96
+ end
93
97
  end
94
- end
95
98
 
96
- def handlers
97
- @settings[:handlers].map do |handler_name, handler_details|
98
- handler_details.merge(:name => handler_name.to_s)
99
+ define_method((key.to_s.chop + '_exists?').to_sym) do |name|
100
+ @settings[key].has_key?(name.to_sym)
99
101
  end
100
102
  end
101
103
 
102
- def check_exists?(check_name)
103
- @settings[:checks].has_key?(check_name.to_sym)
104
- end
105
-
106
- def handler_exists?(handler_name)
107
- @settings[:handlers].has_key?(handler_name.to_sym)
108
- end
109
-
110
104
  def validate
111
105
  @logger.debug('validating settings')
112
106
  validate_checks
@@ -322,7 +316,7 @@ module Sensu
322
316
 
323
317
  def validate_server
324
318
  unless @settings[:handlers].is_a?(Hash)
325
- invalid('missing handlers configuration')
319
+ invalid('handlers must be a hash')
326
320
  end
327
321
  unless @settings[:handlers].include?(:default)
328
322
  invalid('missing default handler')
@@ -370,6 +364,16 @@ module Sensu
370
364
  })
371
365
  end
372
366
  end
367
+ unless @settings[:mutators].is_a?(Hash)
368
+ invalid('mutators must be a hash')
369
+ end
370
+ mutators.each do |mutator|
371
+ unless mutator[:command].is_a?(String)
372
+ invalid('mutator is missing command', {
373
+ :mutator => mutator
374
+ })
375
+ end
376
+ end
373
377
  end
374
378
  end
375
379
  end
data/sensu.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency('em-spec')
25
25
  s.add_development_dependency('em-http-request')
26
26
 
27
- s.files = Dir.glob('{bin,lib}/**/*') + %w[sensu.gemspec README.org MIT-LICENSE.txt]
27
+ s.files = Dir.glob('{bin,lib}/**/*') + %w[sensu.gemspec README.md CHANGELOG.md MIT-LICENSE.txt]
28
28
  s.executables = Dir.glob('bin/**/*').map { |file| File.basename(file) }
29
29
  s.require_paths = ['lib']
30
30
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
5
- prerelease: false
4
+ hash: 31098133
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 6
10
- version: 0.9.6
9
+ - 7
10
+ - beta
11
+ version: 0.9.7.beta
11
12
  platform: ruby
12
13
  authors:
13
14
  - Sean Porter
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2012-07-09 00:00:00 -07:00
20
+ date: 2012-07-18 00:00:00 -07:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -200,7 +201,8 @@ files:
200
201
  - lib/sensu/socket.rb
201
202
  - lib/sensu.rb
202
203
  - sensu.gemspec
203
- - README.org
204
+ - README.md
205
+ - CHANGELOG.md
204
206
  - MIT-LICENSE.txt
205
207
  has_rdoc: true
206
208
  homepage: https://github.com/sensu/sensu
@@ -223,12 +225,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
223
225
  required_rubygems_version: !ruby/object:Gem::Requirement
224
226
  none: false
225
227
  requirements:
226
- - - ">="
228
+ - - ">"
227
229
  - !ruby/object:Gem::Version
228
- hash: 3
230
+ hash: 25
229
231
  segments:
230
- - 0
231
- version: "0"
232
+ - 1
233
+ - 3
234
+ - 1
235
+ version: 1.3.1
232
236
  requirements: []
233
237
 
234
238
  rubyforge_project:
data/README.org DELETED
@@ -1,12 +0,0 @@
1
- * Sensu
2
- A monitoring framework that aims to be simple, malleable, and scalable.
3
-
4
- [[https://github.com/sensu/sensu/raw/master/sensu-logo.png]]
5
-
6
- [[https://secure.travis-ci.org/sensu/sensu.png]]
7
-
8
- [[https://gemnasium.com/portertech/sensu.png]]
9
- ** Documentation
10
- Please refer to the [[https://github.com/sensu/sensu/wiki][Sensu Wiki]].
11
- ** License
12
- Sensu is released under the [[https://github.com/sensu/sensu/blob/master/MIT-LICENSE.txt][MIT license]].