sensu 0.8.10 → 0.8.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sensu (0.8.10)
4
+ sensu (0.8.11)
5
5
  amqp (= 0.7.4)
6
6
  async_sinatra
7
7
  bundler
@@ -10,7 +10,7 @@ PATH
10
10
  hashie
11
11
  json
12
12
  rack (~> 1.3.4)
13
- ruby-redis
13
+ ruby-redis-portertech
14
14
  thin
15
15
  uuidtools
16
16
 
@@ -56,7 +56,7 @@ GEM
56
56
  rspec-expectations (2.6.0)
57
57
  diff-lcs (~> 1.1.2)
58
58
  rspec-mocks (2.6.0)
59
- ruby-redis (0.0.2)
59
+ ruby-redis-portertech (0.0.3)
60
60
  eventmachine
61
61
  sinatra (1.3.1)
62
62
  rack (~> 1.3, >= 1.3.4)
data/lib/sensu.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sensu
2
- VERSION = "0.8.10"
2
+ VERSION = "0.8.11"
3
3
  end
data/lib/sensu/api.rb CHANGED
@@ -133,7 +133,13 @@ module Sensu
133
133
  if event.has_key?('client') && event.has_key?('check')
134
134
  $redis.hgetall('events:' + event['client']).callback do |events|
135
135
  if events.has_key?(event['check'])
136
- check = {:name => event['check'], :issued => Time.now.to_i, :status => 0, :output => 'Resolving on request of the API'}
136
+ check = {
137
+ :name => event['check'],
138
+ :issued => Time.now.to_i,
139
+ :status => 0,
140
+ :output => 'Resolving on request of the API',
141
+ :force_resolve => true
142
+ }
137
143
  $amq.queue('results').publish({:client => event['client'], :check => check}.to_json)
138
144
  status 201
139
145
  else
data/lib/sensu/client.rb CHANGED
@@ -111,6 +111,7 @@ module Sensu
111
111
  def setup_subscriptions
112
112
  @logger.debug('[subscribe] -- setup subscriptions')
113
113
  @check_queue = @amq.queue(UUIDTools::UUID.random_create.to_s, :exclusive => true)
114
+ @settings.client.subscriptions.push('uchiwa')
114
115
  @settings.client.subscriptions.each do |exchange|
115
116
  @logger.debug('[subscribe] -- queue binding to exchange -- ' + exchange)
116
117
  @check_queue.bind(@amq.fanout(exchange))
@@ -118,7 +119,24 @@ module Sensu
118
119
  @check_queue.subscribe do |check_json|
119
120
  check = Hashie::Mash.new(JSON.parse(check_json))
120
121
  @logger.info('[subscribe] -- received check -- ' + check.name)
121
- execute_check(check)
122
+ if check.key?('matching')
123
+ @logger.info('[subscribe] -- check requires matching -- ' + check.name)
124
+ matches = check.matching.all? do |key, value|
125
+ if key == 'subscribes'
126
+ @settings.client.subscriptions.include?(value)
127
+ else
128
+ @settings.client[key] == value
129
+ end
130
+ end
131
+ if matches
132
+ @logger.info('[subscribe] -- client matches -- ' + check.name)
133
+ execute_check(check)
134
+ else
135
+ @logger.info('[subscribe] -- client does not match -- ' + check.name)
136
+ end
137
+ else
138
+ execute_check(check)
139
+ end
122
140
  end
123
141
  end
124
142
 
@@ -149,7 +167,7 @@ module Sensu
149
167
  attr_accessor :logger, :client_name, :result_queue
150
168
 
151
169
  def receive_data(data)
152
- @logger.debug('[socket] -- client connected')
170
+ @logger.debug('[socket] -- received data from client')
153
171
  begin
154
172
  check = Hashie::Mash.new(JSON.parse(data))
155
173
  validates = %w[name status output].all? do |key|
data/lib/sensu/config.rb CHANGED
@@ -46,6 +46,9 @@ module Sensu
46
46
  case type
47
47
  when 'server'
48
48
  has_keys(%w[redis handlers checks])
49
+ unless @settings.handlers.include?('default')
50
+ invalid_config('missing default handler')
51
+ end
49
52
  when 'api'
50
53
  has_keys(%w[redis api])
51
54
  when 'client'
@@ -70,6 +73,16 @@ module Sensu
70
73
  unless details.subscribers.is_a?(Array) && details.subscribers.count > 0
71
74
  invalid_config('missing subscribers for check ' + name)
72
75
  end
76
+ if details.key?('handler')
77
+ unless details.handler.is_a?(String)
78
+ invalid_config('handler must be a string for check ' + name)
79
+ end
80
+ end
81
+ if details.key?('handlers')
82
+ unless details.handlers.is_a?(Array)
83
+ invalid_config('handlers must be an array for check ' + name)
84
+ end
85
+ end
73
86
  end
74
87
  if type
75
88
  @logger.debug('[config] -- configuration valid -- running ' + type)
data/lib/sensu/server.rb CHANGED
@@ -66,27 +66,37 @@ module Sensu
66
66
  end
67
67
 
68
68
  def handle_event(event)
69
- handler = proc do
70
- output = ''
71
- Bundler.with_clean_env do
72
- IO.popen(@settings.handlers[event.check.handler] + ' 2>&1', 'r+') do |io|
73
- io.write(event.to_json)
74
- io.close_write
75
- output = io.read
76
- end
77
- end
78
- output
69
+ handlers = case
70
+ when event.check.key?('handler')
71
+ [event.check.handler]
72
+ when event.check.key?('handlers')
73
+ event.check.handlers
74
+ else
75
+ ['default']
79
76
  end
80
77
  report = proc do |output|
81
78
  output.split(/\n+/).each do |line|
82
79
  @logger.info('[handler] -- ' + line)
83
80
  end
84
81
  end
85
- if @settings.handlers.key?(event.check.handler)
86
- @logger.debug('[event] -- handling event -- ' + [event.check.handler, event.client.name, event.check.name].join(' -- '))
87
- EM.defer(handler, report)
88
- else
89
- @logger.warn('[event] -- handler does not exist -- ' + event.check.handler)
82
+ handlers.each do |handler|
83
+ if @settings.handlers.key?(handler)
84
+ @logger.debug('[event] -- handling event -- ' + [handler, event.client.name, event.check.name].join(' -- '))
85
+ handle = proc do
86
+ output = ''
87
+ Bundler.with_clean_env do
88
+ IO.popen(@settings.handlers[handler] + ' 2>&1', 'r+') do |io|
89
+ io.write(event.to_json)
90
+ io.close_write
91
+ output = io.read
92
+ end
93
+ end
94
+ output
95
+ end
96
+ EM.defer(handle, report)
97
+ else
98
+ @logger.warn('[event] -- handler does not exist -- ' + handler)
99
+ end
90
100
  end
91
101
  end
92
102
 
@@ -96,7 +106,6 @@ module Sensu
96
106
  unless client_json.nil?
97
107
  client = Hashie::Mash.new(JSON.parse(client_json))
98
108
  check = @settings.checks.key?(result.check.name) ? result.check.merge(@settings.checks[result.check.name]) : result.check
99
- check.handler ||= 'default'
100
109
  event = Hashie::Mash.new({
101
110
  :client => client,
102
111
  :check => check,
@@ -138,10 +147,12 @@ module Sensu
138
147
  end
139
148
  if previous_event && check.status == 0
140
149
  unless is_flapping
141
- @redis.hdel('events:' + client.name, check.name).callback do
142
- unless check.internal
143
- event.action = 'resolve'
144
- handle_event(event)
150
+ unless check.auto_resolve == false && !check.force_resolve
151
+ @redis.hdel('events:' + client.name, check.name).callback do
152
+ unless check.internal
153
+ event.action = 'resolve'
154
+ handle_event(event)
155
+ end
145
156
  end
146
157
  end
147
158
  else
@@ -188,16 +199,24 @@ module Sensu
188
199
  exchanges = Hash.new
189
200
  stagger = options[:test] ? 0 : 7
190
201
  @settings.checks.each_with_index do |(name, details), index|
202
+ check = Hashie::Mash.new
203
+ check.name = name
191
204
  unless details.enabled == false
192
205
  EM.add_timer(stagger*index) do
193
- details.subscribers.each do |exchange|
194
- if exchanges[exchange].nil?
195
- exchanges[exchange] = @amq.fanout(exchange)
206
+ details.subscribers.each do |subscriber|
207
+ if subscriber.is_a?(Hash)
208
+ @logger.debug('[publisher] -- check requires matching -- ' + subscriber.to_hash.to_s + ' -- ' + name)
209
+ check.matching = subscriber
210
+ exchange = 'uchiwa'
211
+ else
212
+ exchange = subscriber
196
213
  end
214
+ exchanges[exchange] ||= @amq.fanout(exchange)
197
215
  interval = options[:test] ? 0.5 : details.interval
198
216
  EM.add_periodic_timer(interval) do
217
+ check.issued = Time.now.to_i
199
218
  @logger.info('[publisher] -- publishing check -- ' + name + ' -- ' + exchange)
200
- exchanges[exchange].publish({'name' => name, 'issued' => Time.now.to_i}.to_json)
219
+ exchanges[exchange].publish(check.to_json)
201
220
  end
202
221
  end
203
222
  end
data/sensu.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency("hashie")
20
20
  s.add_dependency("uuidtools")
21
21
  s.add_dependency("cabin", "0.1.7")
22
- s.add_dependency("ruby-redis")
22
+ s.add_dependency("ruby-redis-portertech")
23
23
  s.add_dependency("rack", "~> 1.3.4")
24
24
  s.add_dependency("async_sinatra")
25
25
  s.add_dependency("thin")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 43
4
+ hash: 41
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 10
10
- version: 0.8.10
9
+ - 11
10
+ version: 0.8.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Porter
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-11-18 00:00:00 -08:00
19
+ date: 2011-11-22 00:00:00 -08:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -126,7 +126,7 @@ dependencies:
126
126
  type: :runtime
127
127
  version_requirements: *id007
128
128
  - !ruby/object:Gem::Dependency
129
- name: ruby-redis
129
+ name: ruby-redis-portertech
130
130
  prerelease: false
131
131
  requirement: &id008 !ruby/object:Gem::Requirement
132
132
  none: false