sensu-dashboard 0.9.7.beta → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,6 +41,10 @@ class Dashboard < Sinatra::Base
41
41
  Process.write_pid(options[:pid_file])
42
42
  end
43
43
  $api_server = 'http://' + $settings.api.host + ':' + $settings.api.port.to_s
44
+ $api_options = {}
45
+ if $settings.api.user && $settings.api.password
46
+ $api_options.merge!(:head => {'authorization' => [$settings.api.user, $settings.api.password]})
47
+ end
44
48
  end
45
49
 
46
50
  def self.websocket_server
@@ -104,31 +108,14 @@ class Dashboard < Sinatra::Base
104
108
 
105
109
  aget '/autocomplete.json' do
106
110
  multi = EM::MultiRequest.new
107
-
108
- requests = [
109
- $api_server + '/events',
110
- $api_server + '/clients'
111
- ]
112
-
113
- requests.each do |url|
114
- multi.add EM::HttpRequest.new(url).get
115
- end
111
+ multi.add :events, EM::HttpRequest.new($api_server + '/events').get($api_options)
112
+ multi.add :clients, EM::HttpRequest.new($api_server + '/clients').get($api_options)
116
113
 
117
114
  multi.callback do
118
- events = {}
119
- clients = []
120
-
121
- multi.responses[:succeeded].each do |request|
122
- body = JSON.parse(request.response)
123
- case body
124
- when Hash
125
- events = body
126
- when Array
127
- clients = body
128
- end
129
- end
115
+ unless multi.responses[:errback].size > 0
116
+ events = JSON.parse(multi.responses[:callback][:events].response)
117
+ clients = JSON.parse(multi.responses[:callback][:clients].response)
130
118
 
131
- if events && clients
132
119
  autocomplete = []
133
120
  statuses = {:warning => [], :critical => [], :unknown => []}
134
121
  subscriptions = {}
@@ -137,23 +124,21 @@ class Dashboard < Sinatra::Base
137
124
  # searching by client
138
125
  clients.each do |client|
139
126
  client_name = client['name']
140
- if events.include?(client_name)
141
- autocomplete.push({:value => [client_name], :type => 'client', :name => client_name})
142
- client['subscriptions'].each do |subscription|
143
- subscriptions[subscription] ||= []
144
- subscriptions[subscription].push(client_name)
145
- end
146
- events[client_name].each do |check, event|
147
- case event['status']
148
- when 1
149
- statuses[:warning].push(event['status'])
150
- when 2
151
- statuses[:critical].push(event['status'])
152
- else
153
- statuses[:unknown].push(event['status'])
154
- end
155
- checks.push(check)
127
+ autocomplete.push({:value => [client_name], :type => 'client', :name => client_name})
128
+ client['subscriptions'].each do |subscription|
129
+ subscriptions[subscription] ||= []
130
+ subscriptions[subscription].push(client_name)
131
+ end
132
+ events.each do |event|
133
+ case event['status']
134
+ when 1
135
+ statuses[:warning].push(event['status'])
136
+ when 2
137
+ statuses[:critical].push(event['status'])
138
+ else
139
+ statuses[:unknown].push(event['status'])
156
140
  end
141
+ checks.push(event['check'])
157
142
  end
158
143
  end
159
144
 
@@ -181,29 +166,22 @@ class Dashboard < Sinatra::Base
181
166
  end
182
167
 
183
168
  aget '/clients/autocomplete.json' do
184
- multi = EM::MultiRequest.new
185
-
186
- requests = [
187
- $api_server + '/clients'
188
- ]
189
-
190
- requests.each do |url|
191
- multi.add EM::HttpRequest.new(url).get
169
+ begin
170
+ http = EM::HttpRequest.new($api_server + '/clients').get($api_options)
171
+ rescue => e
172
+ $logger.warn(e)
173
+ status 404
174
+ body '{"error":"could not retrieve clients from the sensu api"}'
192
175
  end
193
176
 
194
- multi.callback do
195
- events = {}
196
- clients = []
197
-
198
- multi.responses[:succeeded].each do |request|
199
- body = JSON.parse(request.response)
200
- case body
201
- when Array
202
- clients = body
203
- end
204
- end
177
+ http.errback do
178
+ status 404
179
+ body '{"error":"could not retrieve clients from the sensu api"}'
180
+ end
205
181
 
206
- if clients
182
+ http.callback do
183
+ if http.response_header.status == 200
184
+ clients = JSON.parse(http.response)
207
185
  autocomplete = []
208
186
  subscriptions = {}
209
187
 
@@ -236,9 +214,9 @@ class Dashboard < Sinatra::Base
236
214
 
237
215
  aget '/events.json' do
238
216
  begin
239
- http = EM::HttpRequest.new($api_server + '/events').get
217
+ http = EM::HttpRequest.new($api_server + '/events').get($api_options)
240
218
  rescue => e
241
- $logger.warning(e)
219
+ $logger.warn(e)
242
220
  status 404
243
221
  body '{"error":"could not retrieve events from the sensu api"}'
244
222
  end
@@ -249,16 +227,26 @@ class Dashboard < Sinatra::Base
249
227
  end
250
228
 
251
229
  http.callback do
230
+ events = Hash.new
231
+ if http.response_header.status == 200
232
+ api_events = JSON.parse(http.response)
233
+ api_events.each do |event|
234
+ client = event.delete('client')
235
+ check = event.delete('check')
236
+ events[client] ||= Hash.new
237
+ events[client][check] = event
238
+ end
239
+ end
252
240
  status http.response_header.status
253
- body http.response
241
+ body events.to_json
254
242
  end
255
243
  end
256
244
 
257
245
  aget '/clients.json' do
258
246
  begin
259
- http = EM::HttpRequest.new($api_server + '/clients').get
247
+ http = EM::HttpRequest.new($api_server + '/clients').get($api_options)
260
248
  rescue => e
261
- $logger.warning(e)
249
+ $logger.warn(e)
262
250
  status 404
263
251
  body '{"error":"could not retrieve clients from the sensu api"}'
264
252
  end
@@ -276,9 +264,9 @@ class Dashboard < Sinatra::Base
276
264
 
277
265
  aget '/client/:id.json' do |id|
278
266
  begin
279
- http = EM::HttpRequest.new($api_server + '/client/' + id).get
267
+ http = EM::HttpRequest.new($api_server + '/client/' + id).get($api_options)
280
268
  rescue => e
281
- $logger.warning(e)
269
+ $logger.warn(e)
282
270
  status 404
283
271
  body '{"error":"could not retrieve client from the sensu api"}'
284
272
  end
@@ -296,9 +284,9 @@ class Dashboard < Sinatra::Base
296
284
 
297
285
  adelete '/client/:id.json' do |id|
298
286
  begin
299
- http = EventMachine::HttpRequest.new($api_server + '/client/' + id).delete
287
+ http = EventMachine::HttpRequest.new($api_server + '/client/' + id).delete($api_options)
300
288
  rescue => e
301
- $logger.warning(e)
289
+ $logger.warn(e)
302
290
  status 404
303
291
  body '{"error":"could not delete client from the sensu api"}'
304
292
  end
@@ -316,9 +304,9 @@ class Dashboard < Sinatra::Base
316
304
 
317
305
  aget '/stash/*.json' do |path|
318
306
  begin
319
- http = EM::HttpRequest.new($api_server + '/stash/' + path).get
307
+ http = EM::HttpRequest.new($api_server + '/stash/' + path).get($api_options)
320
308
  rescue => e
321
- $logger.warning(e)
309
+ $logger.warn(e)
322
310
  status 404
323
311
  body '{"error":"could not retrieve a stash from the sensu api"}'
324
312
  end
@@ -342,9 +330,9 @@ class Dashboard < Sinatra::Base
342
330
  'content-type' => 'application/json'
343
331
  }
344
332
  }
345
- http = EM::HttpRequest.new($api_server + '/stash/' + path).post request_options
333
+ http = EM::HttpRequest.new($api_server + '/stash/' + path).post(request_options.merge($api_options))
346
334
  rescue => e
347
- $logger.warning(e)
335
+ $logger.warn(e)
348
336
  status 404
349
337
  body '{"error":"could not create a stash with the sensu api"}'
350
338
  end
@@ -362,9 +350,9 @@ class Dashboard < Sinatra::Base
362
350
 
363
351
  adelete '/stash/*.json' do |path|
364
352
  begin
365
- http = EM::HttpRequest.new($api_server + '/stash/' + path).delete
353
+ http = EM::HttpRequest.new($api_server + '/stash/' + path).delete($api_options)
366
354
  rescue => e
367
- $logger.warning(e)
355
+ $logger.warn(e)
368
356
  status 404
369
357
  body '{"error":"could not delete a stash with the sensu api"}'
370
358
  end
@@ -388,9 +376,9 @@ class Dashboard < Sinatra::Base
388
376
  'content-type' => 'application/json'
389
377
  }
390
378
  }
391
- http = EM::HttpRequest.new($api_server + '/event/resolve').post request_options
379
+ http = EM::HttpRequest.new($api_server + '/event/resolve').post(request_options.merge($api_options))
392
380
  rescue => e
393
- $logger.warning(e)
381
+ $logger.warn(e)
394
382
  status 404
395
383
  body '{"error":"could not resolve an event with the sensu api"}'
396
384
  end
@@ -408,9 +396,9 @@ class Dashboard < Sinatra::Base
408
396
 
409
397
  aget '/stashes.json' do
410
398
  begin
411
- http = EM::HttpRequest.new($api_server + '/stashes').get
399
+ http = EM::HttpRequest.new($api_server + '/stashes').get($api_options)
412
400
  rescue => e
413
- $logger.warning(e)
401
+ $logger.warn(e)
414
402
  status 404
415
403
  body '{"error":"could not retrieve a list of stashes from the sensu api"}'
416
404
  end
@@ -434,9 +422,9 @@ class Dashboard < Sinatra::Base
434
422
  'content-type' => 'application/json'
435
423
  }
436
424
  }
437
- http = EM::HttpRequest.new($api_server + '/stashes').post request_options
425
+ http = EM::HttpRequest.new($api_server + '/stashes').post(request_options.merge($api_options))
438
426
  rescue => e
439
- $logger.warning(e)
427
+ $logger.warn(e)
440
428
  status 404
441
429
  body '{"error":"could not retrieve a list of stashes from the sensu api"}'
442
430
  end
@@ -454,7 +442,7 @@ class Dashboard < Sinatra::Base
454
442
 
455
443
  def self.stop(signal)
456
444
  $logger.warn('[stop] -- stopping sensu dashboard -- ' + signal)
457
- EM::Timer.new(1) do
445
+ EM::PeriodicTimer.new(0.25) do
458
446
  EM::stop_event_loop
459
447
  end
460
448
  end
@@ -1,5 +1,5 @@
1
1
  module Sensu
2
2
  module Dashboard
3
- VERSION = "0.9.7.beta"
3
+ VERSION = "0.9.7"
4
4
  end
5
5
  end
@@ -46,6 +46,10 @@
46
46
  <link rel="stylesheet" href="css/sonian.css">
47
47
  <link rel="stylesheet" href="css/autoSuggest.css">
48
48
 
49
+ <!-- Favicon: Set the sensu fan image from github as the favicon -->
50
+ <link rel="icon" href="/favicon.ico" type="image/x-icon">
51
+ <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
52
+
49
53
  <!-- all our JS is at the bottom of the page, except for Modernizr. -->
50
54
  <script src="js/modernizr-1.7.min.js"></script>
51
55
 
@@ -11,8 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.summary = %q{A web interface for sensu, a publish/subscribe server monitoring framework}
12
12
  s.description = %q{Display current events and clients in sensu via a simple web interface}
13
13
 
14
- s.add_dependency("sensu", "~> 0.9.1")
15
- s.add_dependency("em-http-request", "0.3.0")
14
+ s.add_dependency("sensu", "~> 0.9.5")
15
+ s.add_dependency("em-http-request", "1.0.1")
16
16
  s.add_dependency("em-websocket")
17
17
  s.add_dependency("sass")
18
18
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-dashboard
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31098133
5
- prerelease: true
4
+ hash: 53
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 7
10
- - beta
11
- version: 0.9.7.beta
10
+ version: 0.9.7
12
11
  platform: ruby
13
12
  authors:
14
13
  - Justin Kolberg
@@ -17,7 +16,7 @@ autorequire:
17
16
  bindir: bin
18
17
  cert_chain: []
19
18
 
20
- date: 2012-02-20 00:00:00 -08:00
19
+ date: 2012-03-28 00:00:00 -07:00
21
20
  default_executable:
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency
@@ -28,12 +27,12 @@ dependencies:
28
27
  requirements:
29
28
  - - ~>
30
29
  - !ruby/object:Gem::Version
31
- hash: 57
30
+ hash: 49
32
31
  segments:
33
32
  - 0
34
33
  - 9
35
- - 1
36
- version: 0.9.1
34
+ - 5
35
+ version: 0.9.5
37
36
  type: :runtime
38
37
  version_requirements: *id001
39
38
  - !ruby/object:Gem::Dependency
@@ -44,12 +43,12 @@ dependencies:
44
43
  requirements:
45
44
  - - "="
46
45
  - !ruby/object:Gem::Version
47
- hash: 19
46
+ hash: 21
48
47
  segments:
48
+ - 1
49
49
  - 0
50
- - 3
51
- - 0
52
- version: 0.3.0
50
+ - 1
51
+ version: 1.0.1
53
52
  type: :runtime
54
53
  version_requirements: *id002
55
54
  - !ruby/object:Gem::Dependency
@@ -100,6 +99,7 @@ files:
100
99
  - lib/sensu-dashboard/app.rb
101
100
  - lib/sensu-dashboard/public/css/autoSuggest.css
102
101
  - lib/sensu-dashboard/public/css/style.css
102
+ - lib/sensu-dashboard/public/favicon.ico
103
103
  - lib/sensu-dashboard/public/img/cross.png
104
104
  - lib/sensu-dashboard/public/img/footer_bg.png
105
105
  - lib/sensu-dashboard/public/img/header_bg.png
@@ -152,14 +152,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
155
- - - ">"
155
+ - - ">="
156
156
  - !ruby/object:Gem::Version
157
- hash: 25
157
+ hash: 3
158
158
  segments:
159
- - 1
160
- - 3
161
- - 1
162
- version: 1.3.1
159
+ - 0
160
+ version: "0"
163
161
  requirements: []
164
162
 
165
163
  rubyforge_project: