summaryrefslogtreecommitdiff
path: root/lib/oxidized/node.rb
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-05-16 14:38:09 +0300
committerSaku Ytti <saku@ytti.fi>2014-05-16 14:38:09 +0300
commit6cb51eb847e9e0edd18b3a803280ad4e31dc6abe (patch)
tree6e33ba94a66ec022d24ad92fc064a276d8cc9b55 /lib/oxidized/node.rb
parentf81050b7dd9cc6c9a41919f11d716a3ad71de8e9 (diff)
store error node#run raised
Diffstat (limited to 'lib/oxidized/node.rb')
-rw-r--r--lib/oxidized/node.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb
index d7de991..456168b 100644
--- a/lib/oxidized/node.rb
+++ b/lib/oxidized/node.rb
@@ -4,8 +4,8 @@ module Oxidized
class MethodNotFound < OxidizedError; end
class ModelNotFound < OxidizedError; end
class Node
- attr_reader :name, :ip, :model, :input, :output, :group, :auth, :prompt, :vars
- attr_accessor :last, :running, :user, :msg, :from, :stats
+ attr_reader :name, :ip, :model, :input, :output, :group, :auth, :prompt, :vars, :last, :error
+ attr_accessor :running, :user, :msg, :from, :stats
alias :running? :running
def initialize opt
@name = opt[:name]
@@ -24,7 +24,7 @@ module Oxidized
end
def run
- status, config = :fail, nil
+ status, config, @error = :fail, nil, nil
@input.each do |input|
@model.input = input = input.new
if config=run_input(input)
@@ -34,6 +34,7 @@ module Oxidized
status = :no_connection
end
end
+ @model.input = nil
[status, config]
end
@@ -51,6 +52,7 @@ module Oxidized
input.get
end
rescue *rescue_fail.keys => err
+ @error = err
resc = ''
if not level = rescue_fail[err.class]
resc = err.class.ancestors.find{|e|rescue_fail.keys.include? e}
@@ -60,6 +62,7 @@ module Oxidized
Log.send(level, '%s raised %s%s with msg "%s"' % [self.ip, err.class, resc, err.message])
return false
rescue => err
+ @error = err
file = Oxidized::Config::Crash + '.' + self.ip.to_s
open file, 'w' do |fh|
fh.puts Time.now.utc
@@ -93,6 +96,15 @@ module Oxidized
h
end
+ def last= job
+ ostruct = OpenStruct.new
+ ostruct.start = job.start
+ ostruct.end = job.end
+ ostruct.status = job.status
+ ostruct.time = job.time
+ @last = ostruct
+ end
+
def reset
@user = @msg = @from = nil
end