sensu 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sensu/api.rb CHANGED
@@ -71,7 +71,7 @@ module Sensu
71
71
  client_events.each do |key, value|
72
72
  client_events[key] = JSON.parse(value)
73
73
  end
74
- current_events.store(client, client_events) unless client_events.empty?
74
+ current_events[client] = client_events unless client_events.empty?
75
75
  body current_events.to_json if index == clients.size-1
76
76
  end
77
77
  end
@@ -88,7 +88,12 @@ module Sensu
88
88
  unless events_exist == 0
89
89
  conn.redis.hgetall('events:' + client).callback do |events|
90
90
  Hash[*events].keys.each do |check|
91
- conn.amq.queue('results').publish({'check' => check, 'client' => client, 'status' => 0, 'output' => 'client is being removed...'}.to_json)
91
+ conn.amq.queue('results').publish({
92
+ 'check' => check,
93
+ 'client' => client,
94
+ 'status' => 0,
95
+ 'output' => 'client is being removed...'
96
+ }.to_json)
92
97
  end
93
98
  EM.add_timer(10) do
94
99
  conn.redis.srem('clients', client)
data/lib/sensu/client.rb CHANGED
@@ -40,19 +40,43 @@ module Sensu
40
40
  end
41
41
 
42
42
  def execute_check(check)
43
- if @settings['checks'][check['name']]
43
+ if @settings['checks'].has_key?(check['name'])
44
44
  unless @checks_in_progress.include?(check['name'])
45
45
  @checks_in_progress.push(check['name'])
46
+ unmatched_tokens = Array.new
46
47
  command = @settings['checks'][check['name']]['command'].gsub(/:::(.*?):::/) do
47
- @settings['client'][$1.to_s].to_s
48
+ key = $1.to_s
49
+ unmatched_tokens.push(key) unless @settings['client'].has_key?(key)
50
+ @settings['client'][key].to_s
48
51
  end
49
- EM.system('sh', '-c', command + ' 2>&1') do |output, status|
50
- @result_queue.publish({'check' => check['name'], 'client' => @settings['client']['name'], 'status' => status.exitstatus, 'output' => output}.to_json)
52
+ if unmatched_tokens.empty?
53
+ EM.system('sh', '-c', command + ' 2>&1') do |output, status|
54
+ @result_queue.publish({
55
+ 'check' => check['name'],
56
+ 'client' => @settings['client']['name'],
57
+ 'status' => status.exitstatus,
58
+ 'output' => output
59
+ }.to_json)
60
+ @checks_in_progress.delete(check['name'])
61
+ end
62
+ else
63
+ @result_queue.publish({
64
+ 'check' => check['name'],
65
+ 'client' => @settings['client']['name'],
66
+ 'status' => 3,
67
+ 'output' => 'Missing client attributes: ' + unmatched_tokens.join(', ')
68
+ }.to_json)
51
69
  @checks_in_progress.delete(check['name'])
52
70
  end
53
71
  end
54
72
  else
55
- @result_queue.publish({'check' => check['name'], 'client' => @settings['client']['name'], 'status' => 3, 'output' => 'Unknown check'}.to_json)
73
+ @result_queue.publish({
74
+ 'check' => check['name'],
75
+ 'client' => @settings['client']['name'],
76
+ 'status' => 3,
77
+ 'output' => 'Unknown check'
78
+ }.to_json)
79
+ @checks_in_progress.delete(check['name'])
56
80
  end
57
81
  end
58
82
 
data/lib/sensu/server.rb CHANGED
@@ -165,13 +165,28 @@ module Sensu
165
165
  time_since_last_check = Time.now.to_i - client['timestamp']
166
166
  case
167
167
  when time_since_last_check >= 180
168
- result_queue.publish({'check' => 'keepalive', 'client' => client['name'], 'status' => 2, 'output' => 'No keep-alive sent from host in over 180 seconds'}.to_json)
168
+ result_queue.publish({
169
+ 'check' => 'keepalive',
170
+ 'client' => client['name'],
171
+ 'status' => 2,
172
+ 'output' => 'No keep-alive sent from host in over 180 seconds'
173
+ }.to_json)
169
174
  when time_since_last_check >= 120
170
- result_queue.publish({'check' => 'keepalive', 'client' => client['name'], 'status' => 1, 'output' => 'No keep-alive sent from host in over 120 seconds'}.to_json)
175
+ result_queue.publish({
176
+ 'check' => 'keepalive',
177
+ 'client' => client['name'],
178
+ 'status' => 1,
179
+ 'output' => 'No keep-alive sent from host in over 120 seconds'
180
+ }.to_json)
171
181
  else
172
182
  @redis.hexists('events:' + client_id, 'keepalive').callback do |exists|
173
183
  if exists == 1
174
- result_queue.publish({'check' => 'keepalive', 'client' => client['name'], 'status' => 0, 'output' => 'Keep-alive sent from host'}.to_json)
184
+ result_queue.publish({
185
+ 'check' => 'keepalive',
186
+ 'client' => client['name'],
187
+ 'status' => 0,
188
+ 'output' => 'Keep-alive sent from host'
189
+ }.to_json)
175
190
  end
176
191
  end
177
192
  end
data/sensu.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "sensu"
3
- s.version = "0.5.1"
3
+ s.version = "0.5.2"
4
4
  s.authors = ["Sean Porter", "Justin Kolberg"]
5
5
  s.email = ["sean.porter@sonian.net", "justin.kolberg@sonian.net"]
6
6
  s.homepage = "https://github.com/sonian/sensu"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.1
5
+ version: 0.5.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sean Porter