From f81050b7dd9cc6c9a41919f11d716a3ad71de8e9 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Wed, 7 May 2014 15:04:28 +0300 Subject: Save stats/last status during Nodes#load We probably should just axe Node#last, as Node#stats contains all it does and more. However it would need changing web views and I'm too lazy for that right now. Perhaps Nodes/Node also needs some unique ID so two instances of Nodes can be compared exactly. Right now copying the old stats relies on name being identical, but can we trust name to be unique? Even with groups support? --- lib/oxidized/nodes.rb | 21 ++++++++++++++++++++- oxidized.gemspec | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index 46630b8..2ea1891 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -32,7 +32,7 @@ module Oxidized Log.error "node %s is not resolvable, raised %s with message '%s'" % [node, err.class, err.message] end end - replace new + size == 0 ? replace(new) : update_nodes(new) end end @@ -124,5 +124,24 @@ module Oxidized Nodes.new :nodes => select { |node| not node.running? } end + # walks list of new nodes, if old node contains same name, adds last and + # stats information from old to new. + # + # @todo can we trust name to be unique identifier, what about when groups are used? + # @param [Array] nodes Array of nodes used to replace+update old + def update_nodes nodes + old = self.dup + replace(nodes) + each do |node| + begin + if i = old.find_node_index(node.name) + node.stats = old[i].stats + node.last = old[i].last + end + rescue Oxidized::NodeNotFound + end + end + end + end end diff --git a/oxidized.gemspec b/oxidized.gemspec index 7e89ad7..86ef906 100644 --- a/oxidized.gemspec +++ b/oxidized.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'oxidized' - s.version = '0.0.57' + s.version = '0.0.58' s.platform = Gem::Platform::RUBY s.authors = [ 'Saku Ytti' ] s.email = %w( saku@ytti.fi ) -- cgit v1.2.1