sensu 0.8.12 → 0.8.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sensu.rb +1 -1
- data/lib/sensu/api.rb +56 -41
- metadata +3 -3
data/lib/sensu.rb
CHANGED
data/lib/sensu/api.rb
CHANGED
@@ -44,17 +44,17 @@ module Sensu
|
|
44
44
|
|
45
45
|
aget '/clients' do
|
46
46
|
$logger.debug('[clients] -- ' + request.ip + ' -- GET -- request for client list')
|
47
|
-
|
47
|
+
response = Array.new
|
48
48
|
$redis.smembers('clients').callback do |clients|
|
49
49
|
unless clients.empty?
|
50
50
|
clients.each_with_index do |client, index|
|
51
51
|
$redis.get('client:' + client).callback do |client_json|
|
52
|
-
|
53
|
-
body
|
52
|
+
response.push(JSON.parse(client_json))
|
53
|
+
body response.to_json if index == clients.size - 1
|
54
54
|
end
|
55
55
|
end
|
56
56
|
else
|
57
|
-
body
|
57
|
+
body response.to_json
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -73,10 +73,16 @@ module Sensu
|
|
73
73
|
if client_exists
|
74
74
|
$redis.hgetall('events:' + client).callback do |events|
|
75
75
|
events.keys.each do |check_name|
|
76
|
-
check = {
|
76
|
+
check = {
|
77
|
+
:name => check_name,
|
78
|
+
:issued => Time.now.to_i,
|
79
|
+
:status => 0,
|
80
|
+
:output => 'Client is being removed on request of the API',
|
81
|
+
:force_resolve => true
|
82
|
+
}
|
77
83
|
$amq.queue('results').publish({:client => client, :check => check}.to_json)
|
78
84
|
end
|
79
|
-
EM.add_timer(
|
85
|
+
EM.add_timer(8) do
|
80
86
|
$redis.srem('clients', client)
|
81
87
|
$redis.del('events:' + client)
|
82
88
|
$redis.del('client:' + client)
|
@@ -93,21 +99,20 @@ module Sensu
|
|
93
99
|
|
94
100
|
aget '/events' do
|
95
101
|
$logger.debug('[events] -- ' + request.ip + ' -- GET -- request for event list')
|
96
|
-
|
102
|
+
response = Hash.new
|
97
103
|
$redis.smembers('clients').callback do |clients|
|
98
104
|
unless clients.empty?
|
99
105
|
clients.each_with_index do |client, index|
|
100
106
|
$redis.hgetall('events:' + client).callback do |events|
|
101
|
-
|
102
|
-
|
103
|
-
client_events[key] = JSON.parse(value)
|
107
|
+
events.each do |key, value|
|
108
|
+
events[key] = JSON.parse(value)
|
104
109
|
end
|
105
|
-
|
106
|
-
body
|
110
|
+
response[client] = events unless events.empty?
|
111
|
+
body response.to_json if index == clients.size - 1
|
107
112
|
end
|
108
113
|
end
|
109
114
|
else
|
110
|
-
body
|
115
|
+
body response.to_json
|
111
116
|
end
|
112
117
|
end
|
113
118
|
end
|
@@ -115,8 +120,7 @@ module Sensu
|
|
115
120
|
aget '/event/:client/:check' do |client, check|
|
116
121
|
$logger.debug('[event] -- ' + request.ip + ' -- GET -- request for event -- ' + client + ' -- ' + check)
|
117
122
|
$redis.hgetall('events:' + client).callback do |events|
|
118
|
-
|
119
|
-
event = client_events[check]
|
123
|
+
event = events[check]
|
120
124
|
status 404 if event.nil?
|
121
125
|
body event
|
122
126
|
end
|
@@ -162,30 +166,10 @@ module Sensu
|
|
162
166
|
body nil
|
163
167
|
end
|
164
168
|
$redis.set('stash:' + path, stash.to_json).callback do
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
169
|
-
|
170
|
-
apost '/stashes' do
|
171
|
-
$logger.debug('[stashes] -- ' + request.ip + ' -- POST -- request for multiple stashes')
|
172
|
-
begin
|
173
|
-
paths = JSON.parse(request.body.read)
|
174
|
-
rescue JSON::ParserError
|
175
|
-
status 400
|
176
|
-
body nil
|
177
|
-
end
|
178
|
-
stashes = Hash.new
|
179
|
-
if paths.is_a?(Array) && paths.size > 0
|
180
|
-
paths.each_with_index do |path, index|
|
181
|
-
$redis.get('stash:' + path).callback do |stash|
|
182
|
-
stashes[path] = JSON.parse(stash) unless stash.nil?
|
183
|
-
body stashes.to_json if index == paths.size - 1
|
184
|
-
end
|
169
|
+
$redis.sadd('stashes', path).callback do
|
170
|
+
status 201
|
171
|
+
body nil
|
185
172
|
end
|
186
|
-
else
|
187
|
-
status 400
|
188
|
-
body nil
|
189
173
|
end
|
190
174
|
end
|
191
175
|
|
@@ -201,9 +185,11 @@ module Sensu
|
|
201
185
|
$logger.debug('[stash] -- ' + request.ip + ' -- DELETE -- request for stash -- ' + path)
|
202
186
|
$redis.exists('stash:' + path).callback do |stash_exist|
|
203
187
|
if stash_exist
|
204
|
-
$redis.
|
205
|
-
|
206
|
-
|
188
|
+
$redis.srem('stashes', path).callback do
|
189
|
+
$redis.del('stash:' + path).callback do
|
190
|
+
status 204
|
191
|
+
body nil
|
192
|
+
end
|
207
193
|
end
|
208
194
|
else
|
209
195
|
status 404
|
@@ -212,6 +198,35 @@ module Sensu
|
|
212
198
|
end
|
213
199
|
end
|
214
200
|
|
201
|
+
aget '/stashes' do
|
202
|
+
$logger.debug('[stashes] -- ' + request.ip + ' -- GET -- request for list of stashes')
|
203
|
+
$redis.smembers('stashes') do |stashes|
|
204
|
+
body stashes.to_json
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
apost '/stashes' do
|
209
|
+
$logger.debug('[stashes] -- ' + request.ip + ' -- POST -- request for multiple stashes')
|
210
|
+
begin
|
211
|
+
paths = JSON.parse(request.body.read)
|
212
|
+
rescue JSON::ParserError
|
213
|
+
status 400
|
214
|
+
body nil
|
215
|
+
end
|
216
|
+
response = Hash.new
|
217
|
+
if paths.is_a?(Array) && paths.size > 0
|
218
|
+
paths.each_with_index do |path, index|
|
219
|
+
$redis.get('stash:' + path).callback do |stash|
|
220
|
+
response[path] = JSON.parse(stash) unless stash.nil?
|
221
|
+
body response.to_json if index == paths.size - 1
|
222
|
+
end
|
223
|
+
end
|
224
|
+
else
|
225
|
+
status 400
|
226
|
+
body nil
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
215
230
|
def self.test(options={})
|
216
231
|
self.setup(options)
|
217
232
|
$redis.set('client:' + @settings.client.name, @settings.client.to_json).callback do
|
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:
|
4
|
+
hash: 37
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 13
|
10
|
+
version: 0.8.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sean Porter
|