sensu-dashboard-sonian 0.9.6 → 0.9.8.beta

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
@@ -186,7 +186,7 @@ function fetchEvents() {
186
186
 
187
187
  $.getJSON('/client/'+selectedEvent['client']+'.json', function(data) {
188
188
  var client = data;
189
- client['subscriptions'] = client['subscriptions'].join(', ');
189
+ client['subscriptions'] = client['subscriptions'].sort().join(', ');
190
190
  $('#clientDetailsRowTemplate').tmpl(client).appendTo('div#event_details_modal > div#client_data');
191
191
  $('div#event_details_modal > div#client_data > h1').click(function() {
192
192
  $(this).select();
@@ -246,7 +246,7 @@ function fetchClients() {
246
246
  continue;
247
247
  }
248
248
 
249
- client['subscriptions'] = client['subscriptions'].join(', ');
249
+ client['subscriptions'] = client['subscriptions'].sort().join(', ');
250
250
  m_clients.push(client);
251
251
  }
252
252
 
@@ -1,5 +1,5 @@
1
1
  module Sensu
2
2
  module Dashboard
3
- VERSION = "0.9.6"
3
+ VERSION = "0.9.8.beta"
4
4
  end
5
5
  end
@@ -53,7 +53,7 @@ $("#remove_client").click(function() {
53
53
  });
54
54
  });
55
55
 
56
- $("input[type=text]").autoSuggest("http://" + location.hostname + ":" + location.port + "/clients/autocomplete.json", {
56
+ $("input[type=text]").autoSuggest(location.protocol + "//" + location.hostname + ":" + location.port + "/clients/autocomplete.json", {
57
57
  startText: "Enter keywords to filter by",
58
58
  selectedItemProp: "name",
59
59
  searchObjProps: "name",
@@ -171,7 +171,7 @@ $("#resolve_event").click(function() {
171
171
  });
172
172
  });
173
173
 
174
- $("input[type=text]").autoSuggest("http://" + location.hostname + ":" + location.port + "/autocomplete.json", {
174
+ $("input[type=text]").autoSuggest(location.protocol + "//" + location.hostname + ":" + location.port + "/autocomplete.json", {
175
175
  startText: "Enter keywords to filter by",
176
176
  selectedItemProp: "name",
177
177
  searchObjProps: "name",
@@ -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. Please use the sensu-dashboard gem as this gem is for Sonian use only.}
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.beta.4")
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,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-dashboard-sonian
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
5
- prerelease: false
4
+ hash: 31098153
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 6
10
- version: 0.9.6
9
+ - 8
10
+ - beta
11
+ version: 0.9.8.beta
11
12
  platform: ruby
12
13
  authors:
13
14
  - Justin Kolberg
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2011-12-28 00:00:00 -08:00
20
+ date: 2012-03-27 00:00:00 -07:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -27,12 +28,14 @@ dependencies:
27
28
  requirements:
28
29
  - - ~>
29
30
  - !ruby/object:Gem::Version
30
- hash: 57
31
+ hash: 62196243
31
32
  segments:
32
33
  - 0
33
34
  - 9
34
- - 1
35
- version: 0.9.1
35
+ - 5
36
+ - beta
37
+ - 4
38
+ version: 0.9.5.beta.4
36
39
  type: :runtime
37
40
  version_requirements: *id001
38
41
  - !ruby/object:Gem::Dependency
@@ -43,12 +46,12 @@ dependencies:
43
46
  requirements:
44
47
  - - "="
45
48
  - !ruby/object:Gem::Version
46
- hash: 19
49
+ hash: 21
47
50
  segments:
51
+ - 1
48
52
  - 0
49
- - 3
50
- - 0
51
- version: 0.3.0
53
+ - 1
54
+ version: 1.0.1
52
55
  type: :runtime
53
56
  version_requirements: *id002
54
57
  - !ruby/object:Gem::Dependency
@@ -99,6 +102,7 @@ files:
99
102
  - lib/sensu-dashboard/app.rb
100
103
  - lib/sensu-dashboard/public/css/autoSuggest.css
101
104
  - lib/sensu-dashboard/public/css/style.css
105
+ - lib/sensu-dashboard/public/favicon.ico
102
106
  - lib/sensu-dashboard/public/img/cross.png
103
107
  - lib/sensu-dashboard/public/img/footer_bg.png
104
108
  - lib/sensu-dashboard/public/img/header_bg.png
@@ -151,12 +155,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
155
  required_rubygems_version: !ruby/object:Gem::Requirement
152
156
  none: false
153
157
  requirements:
154
- - - ">="
158
+ - - ">"
155
159
  - !ruby/object:Gem::Version
156
- hash: 3
160
+ hash: 25
157
161
  segments:
158
- - 0
159
- version: "0"
162
+ - 1
163
+ - 3
164
+ - 1
165
+ version: 1.3.1
160
166
  requirements: []
161
167
 
162
168
  rubyforge_project: