Sha256: 5e1310ddbbb349bf0ba2b0c444779352a220c94c3d3ef649110db70ace027d1b

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'yaml'
require 'pause'
require 'spanx/helper/exit'
require 'spanx/ip_checker'

module Spanx
  class Config < Hash
    include Spanx::Helper::Exit

    attr_accessor :filename

    def initialize(filename)
      super
      @filename = filename
      load_file

      Pause.configure do |pause|
        pause.redis_host = self[:redis][:host]
        pause.redis_port = self[:redis][:port]
        pause.redis_db = self[:redis][:database]

        pause.resolution = self[:collector][:resolution]
        pause.history = self[:collector][:history]
      end

      if self.has_key?(:analyzer) && self[:analyzer].has_key?(:period_checks)
        self[:analyzer][:period_checks].each do |check|
          Spanx::IPChecker.check check[:period_seconds].to_i, check[:max_allowed].to_i, check[:block_ttl].to_i
        end
      end

      self
    end

    private

    def load_file
      begin
        self.merge! ::YAML.load_file(filename)
      rescue Errno::ENOENT
        error_exit_with_msg "Unable to find config_file at #{filename}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spanx-0.1.0 lib/spanx/config.rb