Class: Hostmon::Config

Inherits:
Object
  • Object
show all
Includes:
Models
Defined in:
lib/hostmon/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hostmon/config.rb', line 10

def initialize
  port = 9292
  @conf_file = "./config.yml"

  optparse = OptionParser.new do |o|
    o.on("-f", "--config-file FILE",
      "location of the config directory (default .)") do |arg|
      @conf_file = arg
    end
    o.on("-p", "--port PORT", "port to bind to (default 9292)") do |arg|
      port = arg.to_i
    end
  end

  optparse.parse!
  reload!
  @global_config[:port] = port
end

Instance Attribute Details

#amqp_configObject (readonly)

Returns the value of attribute amqp_config.



7
8
9
# File 'lib/hostmon/config.rb', line 7

def amqp_config
  @amqp_config
end

#bugzilla_configObject (readonly)

Returns the value of attribute bugzilla_config.



8
9
10
# File 'lib/hostmon/config.rb', line 8

def bugzilla_config
  @bugzilla_config
end

#conf_fileObject (readonly)

Returns the value of attribute conf_file.



7
8
9
# File 'lib/hostmon/config.rb', line 7

def conf_file
  @conf_file
end

#global_configObject (readonly)

Returns the value of attribute global_config.



7
8
9
# File 'lib/hostmon/config.rb', line 7

def global_config
  @global_config
end

#report_dirObject (readonly)

Returns the value of attribute report_dir.



7
8
9
# File 'lib/hostmon/config.rb', line 7

def report_dir
  @report_dir
end

Instance Method Details

#reload!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hostmon/config.rb', line 29

def reload!
  raw = File.read(@conf_file)
  raise "failed to load #{@conf_file}" unless yaml = YAML.load(raw)

  @global_config = yaml[:main]
  @bugzilla_config = yaml[:bugzilla] || false
  @amqp_config = yaml[:amqp] || {}
  # do some sanity checking of other configuration parameters
  [:report_dir].each do |c|
    if not @global_config[c]
      raise "Missing config name '#{c.to_s}'"
    end
  end

  @global_config[:saved_reports] ||= 1
  @report_dir = @global_config[:report_dir]
end