bin/riemann-babbler in riemann-babbler-0.6.2 vs bin/riemann-babbler in riemann-babbler-0.6.3

- old
+ new

@@ -8,10 +8,11 @@ require 'resolv' require 'sequel' require File.expand_path('../../lib/riemann/version', __FILE__) require File.expand_path('../../lib/deep_merge', __FILE__) +require File.expand_path('../../lib/start_helpers', __FILE__) require File.expand_path('../../lib/riemann/babbler/plugin', __FILE__) opts = Trollop::options do version "Riemann babbler #{Riemann::Babbler::VERSION}" banner <<-EOS @@ -26,79 +27,10 @@ end # logger logger = Logger.new(STDOUT) -# merge configs -config_file = if File.exist?( opts[:config] ) - YAML.load_file( opts[:config] ).to_hash -else - logger.error "Can't load config file #{opts[:config]}" - Hash.new -end - -config_default = YAML.load_file( File.expand_path('../../config.yml', __FILE__) ) - -config = config_default.deep_merge( config_file ) -configatron.configure_from_hash config - -# set logger lvl -case configatron.logger.level - when "INFO" - logger.level = Logger::INFO - when "WARN" - logger.level = Logger::WARN - when "ERROR" - logger.level = Logger::ERROR - when "FATAL" - logger.level = Logger::FATAL - when "UNKNOWN" - logger.level = Logger::UNKNOWN - else - logger.level = Logger::DEBUG -end - - -# get plugins -plugins = [] -default_plugins_dir = File.expand_path('../../lib/riemann/babbler/plugins/', __FILE__) -Dir.glob( default_plugins_dir + "/*.rb" ) do |file| - plugins << file -end - -unless configatron.plugins.dirs.nil? - configatron.plugins.dirs.each do |dir| - next unless Dir.exist? dir - Dir.glob( dir + "/*.rb" ) do |file| - plugins << file - end - end -end - -unless configatron.plugins.files.nil? - configatron.plugins.files.each do |file| - plugins << file - end -end - -# set riemann client -riemann_ip = Resolv.new.getaddress(configatron.riemann.host) -riemann = Riemann::Client.new( - :host => riemann_ip, - :port => configatron.riemann.port -) -riemann = ( configatron.riemann.proto == 'tcp' ) ? riemann.tcp : riemann - -# start plugins -plugins.each { |plugin| require plugin } - -plugin_threads = Riemann::Babbler.registered_plugins.map do |plugin| - Thread.new { - plugin.new( configatron, logger, riemann ).run - } -end - -Signal.trap "TERM" do # перехватываем сообщение (на будущее) - plugin_threads.each( &:kill ) -end - -plugin_threads.each( &:join ) +merge_config(logger, opts, configatron) +set_logger_lvl(logger, configatron) +load_plugins(configatron) +riemann = get_riemann(configatron) +start_plugins( Riemann::Babbler.registered_plugins, riemann, logger, configatron )