class Munin2Graphite::Config

Attributes

config[RW]

Public Class Methods

check_config() click to toggle source
# File lib/munin2graphite/config.rb, line 57
def check_config
  fields={:carbon => [:hostname,:port],:graphite => [:endpoint,:prefix,:user,:password],:scheduler => [:metrics_period,:graphs_period]}
  fields.each do |k,v|
    v.each do |inner_field|
      field = "#{k}_#{inner_field}"
      if !@config.params[field] 
        workers.each do |worker|
          raise RequiredFieldMissingException.new("Error, required field not found in config ':#{field}' for worker #{worker}") unless @config.params[worker][field]
        end
        
        raise RequiredFieldMissingException.new("Error, required field not found in config ':#{field}'") if workers.empty?
      end
    end
  end
end
config=(config) click to toggle source
# File lib/munin2graphite/config.rb, line 108
def config=(config)
  @config = config
  check_config
end
config_file=(config_file) click to toggle source
# File lib/munin2graphite/config.rb, line 104
def config_file=(config_file)
  @config_file = config_file
end
config_for_class(klass) click to toggle source

Returns the config for a given class

# File lib/munin2graphite/config.rb, line 15
def config_for_class(klass)
  return @config[klass.to_s.decamelize.to_sym]
end
config_for_worker(worker) click to toggle source

This method will return a config class but for a given worker, so everything will be the same as in the original class but the config changes made in this worker

# File lib/munin2graphite/config.rb, line 27
def config_for_worker(worker)
  return self if worker == "global"
  cloned = self.clone
  cloned.config = @config.clone
  cloned.config.params = @config.params.merge(@config.params[worker])
  return cloned
end
configured?() click to toggle source
# File lib/munin2graphite/config.rb, line 40
def configured?
  return @config_file != nil
end
deconfigure!() click to toggle source
# File lib/munin2graphite/config.rb, line 35
def deconfigure!
  @config = nil
  @config_file = nil
end
log() click to toggle source
# File lib/munin2graphite/config.rb, line 92
def log
  shift_age  = self["log_shift_age"] ? self["log_shift_age"].to_i : 1
  shift_size = self["log_shift_size"].to_i || 100000
  @log ||= if self["log"] == "STDOUT"
             Logger.new(STDOUT, shift_age, shift_size)
           else
             Logger.new(self["log"], shift_age, shift_size)
           end
  @log.level = self["log_level"] == "DEBUG" ? Logger::DEBUG : Logger::INFO
  @log
end
method_missing(method_name,*args) click to toggle source
Calls superclass method
# File lib/munin2graphite/config.rb, line 73
def method_missing(method_name,*args)
  if !@config
    if @config_file
      parse_and_check!
    end
    raise NotConfiguredException.new("Not Configured") unless @config
  end
    
  if method_name == :"[]"
    if @config.params.has_key?(args.first.to_s)
      return @config.params[args.first.to_s]
    end
  end
  if @config.params.respond_to?method_name
    return @config.params.send(method_name,*args)
  end
  super
end
parse_and_check!() click to toggle source
# File lib/munin2graphite/config.rb, line 113
def parse_and_check!
  parse_config
  check_config
end
parse_config() click to toggle source
# File lib/munin2graphite/config.rb, line 44
def parse_config
  begin
    @config = ParseConfig.new(@config_file)
  rescue Errno::ENOENT
    raise ConfigFileNotFoundException.new("Error, trying to open the config file #{@config_file}")
  rescue ArgumentError => exception
    raise MalformedConfigFileException.new("Malformed config file '#{@config_file}' #{exception.message}")
  rescue
    raise "Unknown error when trying to open config file '#{@config_file}'"
  end
  @config
end
workers() click to toggle source
# File lib/munin2graphite/config.rb, line 19
def workers
  return @config.groups + @config.params['workers'].to_a
end