Class: Sensu::API

Inherits:
Sinatra::Base
  • Object
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
52
53
# File 'lib/sensu/api.rb', line 38

def bootstrap(options)
  setup_logger(options)
  set :logger, @logger
  load_settings(options)
  set :api, @settings[:api]
  set :checks, @settings[:checks]
  set :all_checks, @settings.checks
  set :cors, @settings[:cors] || {
    'Origin' => '*',
    'Methods' => 'GET, POST, PUT, DELETE, OPTIONS',
    'Credentials' => 'true',
    'Headers' => 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
  }
  on_reactor_run
  self
end

.on_reactor_runObject



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

.startObject



72
73
74
75
# File 'lib/sensu/api.rb', line 72

def start
  start_server
  super
end

.start_serverObject



55
56
57
58
59
60
# File 'lib/sensu/api.rb', line 55

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

.stopObject



77
78
79
80
81
82
83
84
# File 'lib/sensu/api.rb', line 77

def stop
  @logger.warn('stopping')
  stop_server do
    @redis.close
    @transport.close
    super
  end
end

.stop_server(&block) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/sensu/api.rb', line 62

def stop_server(&block)
  @thin.stop
  retry_until_true do
    unless @thin.running?
      block.call
      true
    end
  end
end

.test(options = {}) ⇒ Object



86
87
88
89
# File 'lib/sensu/api.rb', line 86

def test(options={})
  bootstrap(options)
  start
end