From 65df741de7bdd837dc64f40b1fd3083cc98c9ad3 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Fri, 28 Feb 2014 23:05:20 +0200 Subject: Rescue all StandardError from modules If module crashes with unexpected error class, rescue it, and write it backtrace Also log if unknown model is attempted instead of crash --- lib/oxidized/node.rb | 9 +++++++++ lib/oxidized/nodes.rb | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 6c7b3aa..3027ccd 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -53,6 +53,15 @@ module Oxidized end Log.send(level, '%s raised %s%s with msg "%s"' % [self.ip, err.class, resc, err.message]) return false + rescue => err + file = Oxidized::Config::Crash + '.' + self.ip.to_s + open file, 'w' do |fh| + fh.puts Time.now.utc + fh.puts err.message + ' [' + err.class.to_s + ']' + fh.puts '-' * 50 + fh.puts err.backtrace + end + Log.error '%s raised %s with msg "%s", %s saved' % [self.ip, err.class, err.message, file] end end diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index a6aa2f9..4cdbfbb 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -11,7 +11,13 @@ module Oxidized @source = CFG.source[:default] Oxidized.mgr.source = @source Oxidized.mgr.source[@source].new.load.each do |node| - new.push Node.new node + n = nil + begin + n = Node.new node + rescue LoadError => err + Log.warn 'load error %s with node %s' % [err.message, node] + end + new.push n if n end replace new end -- cgit v1.2.1