Module: Sensu::Settings

Defined in:
lib/sensu/settings.rb,
lib/sensu/settings/rules.rb,
lib/sensu/settings/loader.rb,
lib/sensu/settings/constants.rb,
lib/sensu/settings/validator.rb,
lib/sensu/settings/validators.rb,
lib/sensu/settings/validators/api.rb,
lib/sensu/settings/validators/check.rb,
lib/sensu/settings/validators/sensu.rb,
lib/sensu/settings/validators/client.rb,
lib/sensu/settings/validators/filter.rb,
lib/sensu/settings/validators/tessen.rb,
lib/sensu/settings/validators/handler.rb,
lib/sensu/settings/validators/mutator.rb,
lib/sensu/settings/validators/extension.rb,
lib/sensu/settings/validators/transport.rb,
lib/sensu/settings/validators/time_window.rb

Defined Under Namespace

Modules: Rules, Validators Classes: Loader, Validator

Constant Summary collapse

CATEGORIES =
[:checks, :filters, :mutators, :handlers, :extensions]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loaderObject

Returns the value of attribute loader


6
7
8
# File 'lib/sensu/settings.rb', line 6

def loader
  @loader
end

Class Method Details

.get(options = {}) ⇒ Loader

Retrieve the current loaded settings loader or load one up if there isn't one. Note: We may need to add a mutex for thread safety.

Parameters:

  • options (Hash) (defaults to: {})

    to pass to load().

Returns:

  • (Loader)

    instance of a loaded loader.


47
48
49
# File 'lib/sensu/settings.rb', line 47

def get(options={})
  @loader || @loader = load(options)
end

.load(options = {}) ⇒ Loader

Load Sensu settings.

Settings are loaded in following order, prior to validation:

  1. Environment Variables

  2. JSON files on disk

  3. Automaticly detected overrides (e.g. hostname, IP address)

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :config_file (String)

    to load.

  • :config_dir (String)

    to load.

  • :config_dirs (Array)

    to load.

Returns:

  • (Loader)

    a loaded instance of Loader.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sensu/settings.rb', line 20

def load(options={})
  loader = Loader.new
  loader.load_env
  if options[:config_file]
    loader.load_file(options[:config_file], false)
  end
  if options[:config_dir]
    loader.load_directory(options[:config_dir])
  end
  if options[:config_dirs]
    options[:config_dirs].each do |directory|
      loader.load_directory(directory)
    end
  end
  loader.load_overrides!
  loader.validate
  loader
rescue Loader::Error
  loader
end