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/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 Method Summary collapse

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.



42
43
44
# File 'lib/sensu/settings.rb', line 42

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

.load(options = {}) ⇒ Loader

Load Sensu settings.

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.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sensu/settings.rb', line 13

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
  if @loader.validate.empty?
    @loader.set_env!
  end
  @loader.load_overrides!
  @loader
rescue Loader::Error
  @loader
end