sensu-dashboard 0.9.7 → 0.9.8.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sensu-dashboard/app.rb +54 -49
- data/lib/sensu-dashboard/version.rb +1 -1
- data/sensu-dashboard.gemspec +1 -1
- metadata +17 -12
data/lib/sensu-dashboard/app.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'sensu/
|
1
|
+
require 'sensu/base'
|
2
2
|
require 'em-http-request'
|
3
3
|
require 'em-websocket'
|
4
4
|
require 'sinatra/async'
|
@@ -11,7 +11,7 @@ class Dashboard < Sinatra::Base
|
|
11
11
|
EM::run do
|
12
12
|
self.setup(options)
|
13
13
|
self.websocket_server
|
14
|
-
self.run!(:port => $settings
|
14
|
+
self.run!(:port => $settings[:dashboard][:port])
|
15
15
|
|
16
16
|
%w[INT TERM].each do |signal|
|
17
17
|
Signal.trap(signal) do
|
@@ -22,28 +22,22 @@ class Dashboard < Sinatra::Base
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.setup(options={})
|
25
|
-
|
26
|
-
$settings =
|
27
|
-
$logger =
|
28
|
-
unless $settings.
|
29
|
-
raise
|
25
|
+
base = Sensu::Base.new(options)
|
26
|
+
$settings = base.settings
|
27
|
+
$logger = base.logger
|
28
|
+
unless $settings[:dashboard].is_a?(Hash)
|
29
|
+
raise('missing dashboard configuration')
|
30
30
|
end
|
31
|
-
unless $settings
|
32
|
-
raise
|
31
|
+
unless $settings[:dashboard][:port].is_a?(Integer)
|
32
|
+
raise('dashboard must have a port')
|
33
33
|
end
|
34
|
-
unless $settings
|
35
|
-
raise
|
34
|
+
unless $settings[:dashboard][:user].is_a?(String) && $settings[:dashboard][:password].is_a?(String)
|
35
|
+
raise('dashboard must have a user and password')
|
36
36
|
end
|
37
|
-
|
38
|
-
Process.daemonize
|
39
|
-
end
|
40
|
-
if options[:pid_file]
|
41
|
-
Process.write_pid(options[:pid_file])
|
42
|
-
end
|
43
|
-
$api_server = 'http://' + $settings.api.host + ':' + $settings.api.port.to_s
|
37
|
+
$api_url = 'http://' + $settings[:api][:host] + ':' + $settings[:api][:port].to_s
|
44
38
|
$api_options = {}
|
45
|
-
if $settings
|
46
|
-
$api_options.merge!(:head => {
|
39
|
+
if $settings[:api][:user] && $settings[:api][:password]
|
40
|
+
$api_options.merge!(:head => {:authorization => [$settings[:api][:user], $settings[:api][:password]]})
|
47
41
|
end
|
48
42
|
end
|
49
43
|
|
@@ -51,26 +45,38 @@ class Dashboard < Sinatra::Base
|
|
51
45
|
$websocket_connections = []
|
52
46
|
EM::WebSocket.start(:host => '0.0.0.0', :port => 9000) do |websocket|
|
53
47
|
websocket.onopen do
|
54
|
-
$logger.
|
48
|
+
$logger.debug('client connected to websocket')
|
55
49
|
$websocket_connections.push(websocket)
|
56
50
|
end
|
57
51
|
websocket.onclose do
|
58
|
-
$logger.
|
52
|
+
$logger.debug('client disconnected from websocket')
|
59
53
|
$websocket_connections.delete(websocket)
|
60
54
|
end
|
61
55
|
end
|
62
56
|
end
|
63
57
|
|
58
|
+
def request_log(env)
|
59
|
+
$logger.info([env['REQUEST_METHOD'], env['REQUEST_PATH']].join(' '), {
|
60
|
+
:remote_address => env['REMOTE_ADDR'],
|
61
|
+
:user_agent => env['HTTP_USER_AGENT'],
|
62
|
+
:request_method => env['REQUEST_METHOD'],
|
63
|
+
:request_uri => env['REQUEST_URI'],
|
64
|
+
:request_body => env['rack.input'].read
|
65
|
+
})
|
66
|
+
env['rack.input'].rewind
|
67
|
+
end
|
68
|
+
|
64
69
|
set :root, File.dirname(__FILE__)
|
65
70
|
set :static, true
|
66
71
|
set :public_folder, Proc.new { File.join(root, 'public') }
|
67
72
|
|
68
73
|
use Rack::Auth::Basic do |user, password|
|
69
|
-
user == $settings
|
74
|
+
user == $settings[:dashboard][:user] && password == $settings[:dashboard][:password]
|
70
75
|
end
|
71
76
|
|
72
77
|
before do
|
73
78
|
content_type 'application/json'
|
79
|
+
request_log(env)
|
74
80
|
end
|
75
81
|
|
76
82
|
aget '/' do
|
@@ -97,7 +103,6 @@ class Dashboard < Sinatra::Base
|
|
97
103
|
end
|
98
104
|
|
99
105
|
apost '/events.json' do
|
100
|
-
$logger.debug('[events] -- ' + request.ip + ' -- POST -- triggering dashboard refresh')
|
101
106
|
unless $websocket_connections.empty?
|
102
107
|
$websocket_connections.each do |websocket|
|
103
108
|
websocket.send '{"update":"true"}'
|
@@ -108,8 +113,8 @@ class Dashboard < Sinatra::Base
|
|
108
113
|
|
109
114
|
aget '/autocomplete.json' do
|
110
115
|
multi = EM::MultiRequest.new
|
111
|
-
multi.add :events, EM::HttpRequest.new($
|
112
|
-
multi.add :clients, EM::HttpRequest.new($
|
116
|
+
multi.add :events, EM::HttpRequest.new($api_url + '/events').get($api_options)
|
117
|
+
multi.add :clients, EM::HttpRequest.new($api_url + '/clients').get($api_options)
|
113
118
|
|
114
119
|
multi.callback do
|
115
120
|
unless multi.responses[:errback].size > 0
|
@@ -167,9 +172,9 @@ class Dashboard < Sinatra::Base
|
|
167
172
|
|
168
173
|
aget '/clients/autocomplete.json' do
|
169
174
|
begin
|
170
|
-
http = EM::HttpRequest.new($
|
175
|
+
http = EM::HttpRequest.new($api_url + '/clients').get($api_options)
|
171
176
|
rescue => e
|
172
|
-
$logger.warn(e)
|
177
|
+
$logger.warn(e.to_s)
|
173
178
|
status 404
|
174
179
|
body '{"error":"could not retrieve clients from the sensu api"}'
|
175
180
|
end
|
@@ -214,9 +219,9 @@ class Dashboard < Sinatra::Base
|
|
214
219
|
|
215
220
|
aget '/events.json' do
|
216
221
|
begin
|
217
|
-
http = EM::HttpRequest.new($
|
222
|
+
http = EM::HttpRequest.new($api_url + '/events').get($api_options)
|
218
223
|
rescue => e
|
219
|
-
$logger.warn(e)
|
224
|
+
$logger.warn(e.to_s)
|
220
225
|
status 404
|
221
226
|
body '{"error":"could not retrieve events from the sensu api"}'
|
222
227
|
end
|
@@ -244,9 +249,9 @@ class Dashboard < Sinatra::Base
|
|
244
249
|
|
245
250
|
aget '/clients.json' do
|
246
251
|
begin
|
247
|
-
http = EM::HttpRequest.new($
|
252
|
+
http = EM::HttpRequest.new($api_url + '/clients').get($api_options)
|
248
253
|
rescue => e
|
249
|
-
$logger.warn(e)
|
254
|
+
$logger.warn(e.to_s)
|
250
255
|
status 404
|
251
256
|
body '{"error":"could not retrieve clients from the sensu api"}'
|
252
257
|
end
|
@@ -264,9 +269,9 @@ class Dashboard < Sinatra::Base
|
|
264
269
|
|
265
270
|
aget '/client/:id.json' do |id|
|
266
271
|
begin
|
267
|
-
http = EM::HttpRequest.new($
|
272
|
+
http = EM::HttpRequest.new($api_url + '/client/' + id).get($api_options)
|
268
273
|
rescue => e
|
269
|
-
$logger.warn(e)
|
274
|
+
$logger.warn(e.to_s)
|
270
275
|
status 404
|
271
276
|
body '{"error":"could not retrieve client from the sensu api"}'
|
272
277
|
end
|
@@ -284,9 +289,9 @@ class Dashboard < Sinatra::Base
|
|
284
289
|
|
285
290
|
adelete '/client/:id.json' do |id|
|
286
291
|
begin
|
287
|
-
http = EventMachine::HttpRequest.new($
|
292
|
+
http = EventMachine::HttpRequest.new($api_url + '/client/' + id).delete($api_options)
|
288
293
|
rescue => e
|
289
|
-
$logger.warn(e)
|
294
|
+
$logger.warn(e.to_s)
|
290
295
|
status 404
|
291
296
|
body '{"error":"could not delete client from the sensu api"}'
|
292
297
|
end
|
@@ -304,9 +309,9 @@ class Dashboard < Sinatra::Base
|
|
304
309
|
|
305
310
|
aget '/stash/*.json' do |path|
|
306
311
|
begin
|
307
|
-
http = EM::HttpRequest.new($
|
312
|
+
http = EM::HttpRequest.new($api_url + '/stash/' + path).get($api_options)
|
308
313
|
rescue => e
|
309
|
-
$logger.warn(e)
|
314
|
+
$logger.warn(e.to_s)
|
310
315
|
status 404
|
311
316
|
body '{"error":"could not retrieve a stash from the sensu api"}'
|
312
317
|
end
|
@@ -330,9 +335,9 @@ class Dashboard < Sinatra::Base
|
|
330
335
|
'content-type' => 'application/json'
|
331
336
|
}
|
332
337
|
}
|
333
|
-
http = EM::HttpRequest.new($
|
338
|
+
http = EM::HttpRequest.new($api_url + '/stash/' + path).post(request_options.merge($api_options))
|
334
339
|
rescue => e
|
335
|
-
$logger.warn(e)
|
340
|
+
$logger.warn(e.to_s)
|
336
341
|
status 404
|
337
342
|
body '{"error":"could not create a stash with the sensu api"}'
|
338
343
|
end
|
@@ -350,9 +355,9 @@ class Dashboard < Sinatra::Base
|
|
350
355
|
|
351
356
|
adelete '/stash/*.json' do |path|
|
352
357
|
begin
|
353
|
-
http = EM::HttpRequest.new($
|
358
|
+
http = EM::HttpRequest.new($api_url + '/stash/' + path).delete($api_options)
|
354
359
|
rescue => e
|
355
|
-
$logger.warn(e)
|
360
|
+
$logger.warn(e.to_s)
|
356
361
|
status 404
|
357
362
|
body '{"error":"could not delete a stash with the sensu api"}'
|
358
363
|
end
|
@@ -376,9 +381,9 @@ class Dashboard < Sinatra::Base
|
|
376
381
|
'content-type' => 'application/json'
|
377
382
|
}
|
378
383
|
}
|
379
|
-
http = EM::HttpRequest.new($
|
384
|
+
http = EM::HttpRequest.new($api_url + '/event/resolve').post(request_options.merge($api_options))
|
380
385
|
rescue => e
|
381
|
-
$logger.warn(e)
|
386
|
+
$logger.warn(e.to_s)
|
382
387
|
status 404
|
383
388
|
body '{"error":"could not resolve an event with the sensu api"}'
|
384
389
|
end
|
@@ -396,9 +401,9 @@ class Dashboard < Sinatra::Base
|
|
396
401
|
|
397
402
|
aget '/stashes.json' do
|
398
403
|
begin
|
399
|
-
http = EM::HttpRequest.new($
|
404
|
+
http = EM::HttpRequest.new($api_url + '/stashes').get($api_options)
|
400
405
|
rescue => e
|
401
|
-
$logger.warn(e)
|
406
|
+
$logger.warn(e.to_s)
|
402
407
|
status 404
|
403
408
|
body '{"error":"could not retrieve a list of stashes from the sensu api"}'
|
404
409
|
end
|
@@ -422,9 +427,9 @@ class Dashboard < Sinatra::Base
|
|
422
427
|
'content-type' => 'application/json'
|
423
428
|
}
|
424
429
|
}
|
425
|
-
http = EM::HttpRequest.new($
|
430
|
+
http = EM::HttpRequest.new($api_url + '/stashes').post(request_options.merge($api_options))
|
426
431
|
rescue => e
|
427
|
-
$logger.warn(e)
|
432
|
+
$logger.warn(e.to_s)
|
428
433
|
status 404
|
429
434
|
body '{"error":"could not retrieve a list of stashes from the sensu api"}'
|
430
435
|
end
|
@@ -448,5 +453,5 @@ class Dashboard < Sinatra::Base
|
|
448
453
|
end
|
449
454
|
end
|
450
455
|
|
451
|
-
options = Sensu::
|
456
|
+
options = Sensu::CLI.read
|
452
457
|
Dashboard.run(options)
|
data/sensu-dashboard.gemspec
CHANGED
@@ -11,7 +11,7 @@ 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.
|
14
|
+
s.add_dependency("sensu", "~> 0.9.6.beta.3")
|
15
15
|
s.add_dependency("em-http-request", "1.0.1")
|
16
16
|
s.add_dependency("em-websocket")
|
17
17
|
s.add_dependency("sass")
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-dashboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 31098153
|
5
|
+
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
|
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: 2012-
|
20
|
+
date: 2012-05-04 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:
|
31
|
+
hash: 62196229
|
31
32
|
segments:
|
32
33
|
- 0
|
33
34
|
- 9
|
34
|
-
-
|
35
|
-
|
35
|
+
- 6
|
36
|
+
- beta
|
37
|
+
- 3
|
38
|
+
version: 0.9.6.beta.3
|
36
39
|
type: :runtime
|
37
40
|
version_requirements: *id001
|
38
41
|
- !ruby/object:Gem::Dependency
|
@@ -152,12 +155,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
156
|
none: false
|
154
157
|
requirements:
|
155
|
-
- - "
|
158
|
+
- - ">"
|
156
159
|
- !ruby/object:Gem::Version
|
157
|
-
hash:
|
160
|
+
hash: 25
|
158
161
|
segments:
|
159
|
-
-
|
160
|
-
|
162
|
+
- 1
|
163
|
+
- 3
|
164
|
+
- 1
|
165
|
+
version: 1.3.1
|
161
166
|
requirements: []
|
162
167
|
|
163
168
|
rubyforge_project:
|