Class: Oxidized::Node
- Inherits:
-
Object
- Object
- Oxidized::Node
- Defined in:
- lib/oxidized/node.rb,
lib/oxidized/node/stats.rb
Defined Under Namespace
Classes: Stats
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#from ⇒ Object
Returns the value of attribute from.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#last ⇒ Object
Returns the value of attribute last.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#msg ⇒ Object
Returns the value of attribute msg.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#retry ⇒ Object
Returns the value of attribute retry.
-
#running ⇒ Object
(also: #running?)
Returns the value of attribute running.
-
#stats ⇒ Object
Returns the value of attribute stats.
-
#user ⇒ Object
Returns the value of attribute user.
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
-
#initialize(opt) ⇒ Node
constructor
A new instance of Node.
- #reset ⇒ Object
- #run ⇒ Object
- #run_input(input) ⇒ Object
- #serialize ⇒ Object
Constructor Details
#initialize(opt) ⇒ Node
Returns a new instance of Node.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/oxidized/node.rb', line 11 def initialize opt @name = opt[:name] @ip = IPAddr.new(opt[:ip]).to_s rescue nil @ip ||= Resolv.new.getaddress @name @group = opt[:group] @input = resolve_input opt @output = resolve_output opt @model = resolve_model opt @auth = resolve_auth opt @prompt = resolve_prompt opt @vars = opt[:vars] @stats = Stats.new @retry = 0 # model instance needs to access node instance @model.node = self end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def auth @auth end |
#from ⇒ Object
Returns the value of attribute from.
9 10 11 |
# File 'lib/oxidized/node.rb', line 9 def from @from end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def group @group end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def input @input end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def ip @ip end |
#last ⇒ Object
Returns the value of attribute last.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def last @last end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def model @model end |
#msg ⇒ Object
Returns the value of attribute msg.
9 10 11 |
# File 'lib/oxidized/node.rb', line 9 def msg @msg end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def name @name end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def output @output end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def prompt @prompt end |
#retry ⇒ Object
Returns the value of attribute retry.
9 10 11 |
# File 'lib/oxidized/node.rb', line 9 def retry @retry end |
#running ⇒ Object Also known as: running?
Returns the value of attribute running.
9 10 11 |
# File 'lib/oxidized/node.rb', line 9 def running @running end |
#stats ⇒ Object
Returns the value of attribute stats.
9 10 11 |
# File 'lib/oxidized/node.rb', line 9 def stats @stats end |
#user ⇒ Object
Returns the value of attribute user.
9 10 11 |
# File 'lib/oxidized/node.rb', line 9 def user @user end |
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
8 9 10 |
# File 'lib/oxidized/node.rb', line 8 def vars @vars end |
Instance Method Details
#reset ⇒ Object
117 118 119 120 |
# File 'lib/oxidized/node.rb', line 117 def reset @user = @msg = @from = nil @retry = 0 end |
#run ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/oxidized/node.rb', line 29 def run status, config = :fail, nil @input.each do |input| # don't try input if model is missing config block, we may need strong config to class_name map cfg_name = input.to_s.split('::').last.downcase next unless @model.cfg[cfg_name] and not @model.cfg[cfg_name].empty? @model.input = input = input.new if config=run_input(input) status = :success break else status = :no_connection end end @model.input = nil [status, config] end |
#run_input(input) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/oxidized/node.rb', line 47 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 if input.connect self input.get end rescue *rescue_fail.keys => err resc = '' if not level = rescue_fail[err.class] resc = err.class.ancestors.find{|e|rescue_fail.keys.include? e} level = rescue_fail[resc] resc = " (rescued #{resc})" end Log.send(level, '%s raised %s%s with msg "%s"' % [self.ip, err.class, resc, err.]) 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. + ' [' + 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., file] return false end end |
#serialize ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/oxidized/node.rb', line 82 def serialize h = { :name => @name, :full_name => @name, :ip => @ip, :group => @group, :model => @model.class.to_s, :last => nil, :vars => @vars, } h[:full_name] = [@group, @name].join('/') if @group if @last h[:last] = { :start => @last.start, :end => @last.end, :status => @last.status, :time => @last.time, } end h end |