Class: Sensu::API
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Sensu::API
show all
- Extended by:
- Daemon
- Defined in:
- lib/sensu/api.rb
Instance Attribute Summary
Attributes included from Daemon
#state
Class Method Summary
collapse
Methods included from Daemon
initialize, load_extensions, load_settings, log_concerns, pause, resume, setup_logger, setup_process, setup_redis, setup_signal_traps, setup_transport, start, stop
Methods included from Utilities
#deep_merge, #random_uuid, #redact_sensitive, #retry_until_true, #testing?
Class Method Details
.bootstrap(options) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/sensu/api.rb', line 38
def bootstrap(options)
setup_logger(options)
set :logger, @logger
load_settings(options)
set :checks, @settings[:checks]
set :all_checks, @settings.checks
if @settings[:api][:user] && @settings[:api][:password]
use Rack::Auth::Basic do |user, password|
user == @settings[:api][:user] && password == @settings[:api][:password]
end
end
on_reactor_run
self
end
|
.on_reactor_run ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/sensu/api.rb', line 29
def on_reactor_run
EM::next_tick do
setup_redis
set :redis, @redis
setup_transport
set :transport, @transport
end
end
|
.run(options = {}) ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/sensu/api.rb', line 20
def run(options={})
bootstrap(options)
setup_process(options)
EM::run do
start
setup_signal_traps
end
end
|
.start ⇒ Object
70
71
72
73
|
# File 'lib/sensu/api.rb', line 70
def start
start_server
super
end
|
.start_server ⇒ Object
53
54
55
56
57
58
|
# File 'lib/sensu/api.rb', line 53
def start_server
Thin::Logging.silent = true
bind = @settings[:api][:bind] || '0.0.0.0'
@thin = Thin::Server.new(bind, @settings[:api][:port], self)
@thin.start
end
|
.stop ⇒ Object
75
76
77
78
79
80
81
82
|
# File 'lib/sensu/api.rb', line 75
def stop
@logger.warn('stopping')
stop_server do
@redis.close
@transport.close
super
end
end
|
.stop_server(&block) ⇒ Object
60
61
62
63
64
65
66
67
68
|
# File 'lib/sensu/api.rb', line 60
def stop_server(&block)
@thin.stop
retry_until_true do
unless @thin.running?
block.call
true
end
end
end
|
.test(options = {}) ⇒ Object
84
85
86
87
|
# File 'lib/sensu/api.rb', line 84
def test(options={})
bootstrap(options)
start
end
|