lib/bmc-daemon-lib/conf.rb in bmc-daemon-lib-0.3.4 vs lib/bmc-daemon-lib/conf.rb in bmc-daemon-lib-0.3.6

- old
+ new

@@ -1,8 +1,6 @@ # FIXME: files named with hyphens will not be found by Chamber for now -require "chamber" - module BmcDaemonLib # Class exceptions class ConfigInitiRequired < StandardError; end class ConfigMissingParameter < StandardError; end class ConfigOtherError < StandardError; end @@ -78,22 +76,24 @@ # Set up encodings Encoding.default_internal = "utf-8" Encoding.default_external = "utf-8" - # Init New Relic - prepare_newrelic self[:newrelic] + # Init New Relic, Rollbar + prepare_newrelic if self.feature?(:newrelic) + prepare_rollbar if self.feature?(:rollbar) # Try to access any key to force parsing of the files self[:dummy] rescue Psych::SyntaxError => e fail ConfigParseError, e.message rescue StandardError => e fail ConfigOtherError, "#{e.message} \n #{e.backtrace.to_yaml}" end + # Reload files def self.reload! ensure_init load_files end @@ -124,13 +124,22 @@ # Build logfile_path File.expand_path specific.to_s, path.to_s end - def self.newrelic_enabled? + def self.feature? name ensure_init - !! (self[:newrelic] && self[:newrelic][:license]) + + # Guess if the specific feature si available + case name + when :newrelic + self.at(:newrelic, :license) + when :rollbar + self.at(:rollbar, :token) + else + false + end end # Defaults generators def self.generate what ensure_init @@ -171,13 +180,13 @@ def self.add_config path @files << File.expand_path(path) if path && File.readable?(path) end - def self.prepare_newrelic section - # Disable NewRelic if no config present - return unless self.newrelic_enabled? + def self.prepare_newrelic + # Require lib + section = self[:newrelic] # Enable GC profiler GC::Profiler.enable # Set logfile, license, monitor mode @@ -196,9 +205,36 @@ end ENV["NEW_RELIC_APP_NAME"] = section[:app_name].to_s # Enable module ENV["NEWRELIC_AGENT_ENABLED"] = "true" + end + + def self.prepare_rollbar + # # Disable if no config present + # return unless self.feature?(:rollbar) + section = self[:rollbar] + + # Configure + Rollbar.configure do |config| + config.enabled = true + config.access_token = section[:token].to_s + config.code_version = @app_version + + #config.logger + config.environment = @app_env + + # Report asynchronously + config.use_async = true + # Here we'll disable in 'test': + # if Rails.env.test? || Rails.env.development? + # config.enabled = false + # end + #logfile_path(:newrelic) + end + + # Notify startup + Rollbar.info("#{@app_name} #{@app_ver} [#{@host}]") end private def self.ensure_init