summaryrefslogtreecommitdiff
path: root/lib/oxidized/node.rb
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-02-10 12:26:59 +0200
committerSaku Ytti <saku@ytti.fi>2014-02-10 12:26:59 +0200
commit227ea783d3598c2bd974cdaf4aac8c255870e264 (patch)
treeac3af5a9473fb06bda8bbbb6a30c01c453f0dfe8 /lib/oxidized/node.rb
parent92fbaa712c99ae5b523be0ebbc46fca9cdddef4e (diff)
Handle exceptions with different log levels
Diffstat (limited to 'lib/oxidized/node.rb')
-rw-r--r--lib/oxidized/node.rb25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb
index b7dc134..5f09096 100644
--- a/lib/oxidized/node.rb
+++ b/lib/oxidized/node.rb
@@ -21,9 +21,8 @@ module Oxidized
status, config = :fail, nil
@input.each do |input|
@model.input = input = input.new
- if connect input
- config = input.get
- status = :success if config
+ if config=run_input(input)
+ status = :success
break
else
status = :no_connection
@@ -32,12 +31,22 @@ module Oxidized
[status, config]
end
- def connect input
- rescue_fail = input.class::RescueFail + input.class.superclass::RescueFail
+ def run_input input
+ rescue_fail = {}
+ [input.class::RescueFail, input.class.superclass::RescueFail].each do |hash|
+ hash.each do |level,errors|
+ errors.each do |err|
+ rescue_fail[err] = level
+ end
+ end
+ end
begin
- input.connect self
- rescue *rescue_fail => err
- Log.warn '%s raised %s with msg "%s"' % [self.ip, err.class, err.message]
+ if input.connect self
+ input.get
+ end
+ rescue *rescue_fail.keys.flatten => err
+ level = rescue_fail[err.class]
+ Log.send(level, '%s raised %s with msg "%s"' % [self.ip, err.class, err.message])
return false
end
end