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 +7 -2
- data/lib/sensu/client.rb +29 -5
- data/lib/sensu/server.rb +18 -3
- data/sensu.gemspec +1 -1
- metadata +1 -1
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
|
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({
|
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']
|
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
|
-
|
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
|
-
|
50
|
-
|
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({
|
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({
|
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({
|
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({
|
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