Class: SensuGenerator::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu_generator/config.rb

Constant Summary collapse

@@default =
{
  :sensu => {
    :check_default_params => {
      :refresh => 86400,
      :interval => 60,
      :aggregate => true
    },
    :minimal_to_restart => 2,
    :service => "sensu-server",
    :rsync_repo => "sensu-server",
    :supervisor => {:user => "", :password => ""},
  },
  :mode => 'server',
  :server => {
    :addr => '',
    :port => nil
  },
  :result_dir => "work/result",
  :templates_dir => "work/templates",
  :logger => {
    :file => STDOUT,
    :notify_level => "error",
    :log_level => "debug"
  },
  :slack => {
    :url => nil,
    :channel => nil,
    :level => "error"
  },
  :kv_tags_path => "checks",
  # See diplomat documentation to set proper consul parameters
  :consul => {
    :url => "http://consul.service.consul:8500"
  }
}

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Config

Returns a new instance of Config.



42
43
44
# File 'lib/sensu_generator/config.rb', line 42

def initialize(path = nil)
  @config = process(path)
end

Instance Method Details

#file_prefixObject



60
61
62
# File 'lib/sensu_generator/config.rb', line 60

def file_prefix
  @file_prefix ||= get[:mode] == 'server' ? "local_" : "#{Socket.gethostname}_"
end

#getObject



46
47
48
# File 'lib/sensu_generator/config.rb', line 46

def get
  @config
end

#process(path) ⇒ Object



50
51
52
53
# File 'lib/sensu_generator/config.rb', line 50

def process(path)
  custom = path ? JSON(File.read(path), :symbolize_names => true) : {}
  @config = @@default.deep_merge(custom)
end

#result_dirObject

Raises:

  • (GeneratorError)


55
56
57
58
# File 'lib/sensu_generator/config.rb', line 55

def result_dir
  raise(GeneratorError, "Result dir is not defined!") unless get[:result_dir]
  File.expand_path(get[:result_dir])
end