Class: Oxidized::Node
- Inherits:
-
Object
- Object
- Oxidized::Node
- Includes:
- SemanticLogger::Loggable
- Defined in:
- lib/oxidized/node.rb,
lib/oxidized/node/stats.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#email ⇒ Object
Returns the value of attribute email.
-
#err_reason ⇒ Object
Returns the value of attribute err_reason.
-
#err_type ⇒ Object
Returns the value of attribute err_type.
-
#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.
-
#nexted ⇒ Object
(also: #nexted?)
Returns the value of attribute nexted.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
-
#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.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#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
opt is a hash with the node parameters given in the source (:name, :group, :ip…).
- #modified ⇒ Object
- #reset ⇒ Object
- #run ⇒ Object
- #run_input(input) ⇒ Object
- #serialize ⇒ Object
Constructor Details
#initialize(opt) ⇒ Node
opt is a hash with the node parameters given in the source (:name, :group, :ip…)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/oxidized/node.rb', line 16 def initialize(opt) logger.debug 'resolving DNS for %s...' % opt[:name] # remove the prefix if an IP Address is provided with one as IPAddr converts it to a network address. ip_addr, = opt[:ip].to_s.split("/") logger.debug 'IPADDR %s' % ip_addr.to_s @name = opt[:name] @ip = IPAddr.new(ip_addr).to_s rescue nil @ip ||= Resolv.new.getaddress(@name) if Oxidized.config.resolve_dns? @ip ||= @name @group = opt[:group] @model = resolve_model opt @input = resolve_input opt @output = resolve_output opt @auth = resolve_auth opt @prompt = resolve_prompt opt @timeout = resolve_timeout opt @vars = opt[:vars] || {} @stats = Stats.new @retry = 0 @repo = resolve_repo opt @err_type = nil @err_reason = nil @nexted = false # model instance needs to access node instance @model.node = self end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def auth @auth end |
#email ⇒ Object
Returns the value of attribute email.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def email @email end |
#err_reason ⇒ Object
Returns the value of attribute err_reason.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def err_reason @err_reason end |
#err_type ⇒ Object
Returns the value of attribute err_type.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def err_type @err_type end |
#from ⇒ Object
Returns the value of attribute from.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def from @from end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def group @group end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def input @input end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def ip @ip end |
#last ⇒ Object
Returns the value of attribute last.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def last @last end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def model @model end |
#msg ⇒ Object
Returns the value of attribute msg.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def msg @msg end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def name @name end |
#nexted ⇒ Object Also known as: nexted?
Returns the value of attribute nexted.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def nexted @nexted end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def output @output end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def prompt @prompt end |
#repo ⇒ Object (readonly)
Returns the value of attribute repo.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def repo @repo end |
#retry ⇒ Object
Returns the value of attribute retry.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def retry @retry end |
#running ⇒ Object Also known as: running?
Returns the value of attribute running.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def running @running end |
#stats ⇒ Object
Returns the value of attribute stats.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def stats @stats end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def timeout @timeout end |
#user ⇒ Object
Returns the value of attribute user.
11 12 13 |
# File 'lib/oxidized/node.rb', line 11 def user @user end |
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
10 11 12 |
# File 'lib/oxidized/node.rb', line 10 def vars @vars end |
Instance Method Details
#modified ⇒ Object
152 153 154 |
# File 'lib/oxidized/node.rb', line 152 def modified @stats.update_mtime end |
#reset ⇒ Object
147 148 149 150 |
# File 'lib/oxidized/node.rb', line 147 def reset @user = @email = @msg = @from = nil @retry = 0 end |
#run ⇒ Object
44 45 46 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 |
# File 'lib/oxidized/node.rb', line 44 def run status = :fail config = Oxidized::Model::Outputs.new input_sequence = @model.class.input_sequence(@input) input_sequence.each do |sequence| status = :fail sequence_config = nil sequence.each do |input| @model.input = input = input.new if (sequence_config = run_input(input)) logger.debug "#{input.class.name} ran for #{name} successfully" status = :success break else logger.debug "#{input.class.name} failed for #{name}" status = :no_connection end end if status == :success config.merge! sequence_config else config = nil break end end @model.input = nil [status, config] end |
#run_input(input) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/oxidized/node.rb', line 75 def run_input(input) rescue_fail = input.class.rescue_fail begin input.connect(self) && input.get rescue *rescue_fail.keys => err resc = '' unless (level = rescue_fail[err.class]) resc = err.class.ancestors.find { |e| rescue_fail.has_key?(e) } level = rescue_fail[resc] resc = " (rescued #{resc})" end logger.send(level, '%s raised %s%s with msg "%s"' % [ip, err.class, resc, err.]) @err_type = err.class.to_s @err_reason = err..to_s false rescue StandardError => e # Send a message in debug mode in case we are not able to create a crashfile logger.error "#{ip} raised #{e.class} with msg #{e.}, creating crashfile" unless Oxidized.config.crash.directory? logger.error "Cannot create crashfile for exception", e return false end crashdir = Oxidized.config.crash.directory crashfile = Oxidized.config.crash.hostnames? ? name : ip.to_s FileUtils.mkdir_p(crashdir) unless File.directory?(crashdir) File.open File.join(crashdir, crashfile), 'w' do |fh| fh.puts Time.now.utc fh.puts e. + ' [' + e.class.to_s + ']' fh.puts '-' * 50 fh.puts e.backtrace end logger.error '%s raised %s with msg "%s", %s saved' % [ip, e.class, e., crashfile] @err_type = e.class.to_s @err_reason = e..to_s false end end |
#serialize ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/oxidized/node.rb', line 115 def serialize h = { name: @name, full_name: @name, ip: @ip, group: @group, model: @model.class.to_s, last: nil, vars: @vars, mtime: @stats.mtime } 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 |