lib/perus/pinger/pinger.rb in perus-0.1.2 vs lib/perus/pinger/pinger.rb in perus-0.1.3
- old
+ new
@@ -49,12 +49,12 @@
def initialize(options_path = DEFAULT_PINGER_OPTIONS_PATH)
Pinger.options.load(options_path, DEFAULT_PINGER_OPTIONS)
# cache urls on initialisation since the urls depend on values known
# at startup and that won't change over the object lifetime
- config_path = URI("/systems/#{Pinger.options.system_id}/config")
- pinger_path = URI("/systems/#{Pinger.options.system_id}/ping")
+ config_path = URI("systems/#{Pinger.options.system_id}/config")
+ pinger_path = URI("systems/#{Pinger.options.system_id}/ping")
server_uri = URI(Pinger.options.server)
@config_url = (server_uri + config_path).to_s
@pinger_url = (server_uri + pinger_path).to_s
@@ -90,24 +90,24 @@
if ::Perus::Pinger.const_defined?(config['type'])
metric = ::Perus::Pinger.const_get(config['type'])
@metric_errors[metric.name] ||= []
@metrics << metric.new(config['options'])
else
- @metric_errors[config['type']] = e.inspect
+ @metric_errors[config['type']] = format_exception(e)
end
rescue => e
- @metric_errors[metric.name] << e.inspect
+ @metric_errors[metric.name] << format_exception(e)
end
end
json['actions'].each do |config|
begin
command = ::Perus::Pinger.const_get(config['type'])
@actions << command.new(config['options'], config['id'])
rescue => e
if config['id']
- @action_results[config['id']] = e.inspect
+ @action_results[config['id']] = format_exception(e)
else
puts 'Error - action does not have an associated id'
p config
end
end
@@ -115,17 +115,25 @@
end
#----------------------
# run
#----------------------
+ def format_exception(e)
+ if e.backtrace.empty?
+ e.inspect
+ else
+ "#{e.inspect}\n#{e.backtrace.first}"
+ end
+ end
+
def run_metrics
@metrics.each do |metric|
begin
result = metric.run
@metric_results.merge!(result)
rescue => e
- @metric_errors[metric.class.name] << e.inspect
+ @metric_errors[metric.class.name] << format_exception(e)
end
end
end
def run_actions
@@ -139,11 +147,11 @@
end
@action_results[action.id] = result
rescue => e
- @action_results[action.id] = e.inspect
+ @action_results[action.id] = format_exception(e)
end
end
end
#----------------------
@@ -177,11 +185,11 @@
begin
RestClient.post(@pinger_url, payload)
rescue => e
puts 'Ping failed with exception'
- puts e.inspect
+ puts format_exception(e)
end
end
#----------------------
# cleanup
@@ -190,28 +198,28 @@
@metrics.each do |metric|
begin
metric.cleanup
rescue => e
puts 'Error running metric cleanup'
- puts e.inspect
+ puts format_exception(e)
end
end
@actions.each do |action|
begin
action.cleanup
rescue => e
puts 'Error running action cleanup'
- puts e.inspect
+ puts format_exception(e)
end
end
@late_actions.each do |code|
begin
code.call
rescue => e
puts 'Error running late action'
- puts e.inspect
+ puts format_exception(e)
end
end
end
end
end