diff options
author | Jari Salo <jari.salo@tdc.fi> | 2014-08-25 16:54:35 +0300 |
---|---|---|
committer | Jari Salo <jari.salo@tdc.fi> | 2014-08-25 17:17:20 +0300 |
commit | cae7076eeed2b3b5fcfecffde17bcb85d8013af2 (patch) | |
tree | 9daef15e75884bce0a6c9b287aacb2ee33364de8 | |
parent | 5662795ca35444a3e48eea3c2d8020d63502da84 (diff) |
Match IP address explicitly
- New method node_want?
- Don't match node to node[:name] if node[:name] is an ip address.
Otherwise we might match to wrong ip address.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/oxidized/nodes.rb | 20 |
2 files changed, 15 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4660af5..d6eb83a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - FEATURE: Cisco SMB (Nikola series VxWorks) model by @thetamind - FEATURE: Extreme Networks XOS model (access by sjm) - FEATURE: Brocade NOS (Network Operating System) (access by sjm) +- BUGFIX: Match exactly to node[:name] if node[name] is an ip address. # 0.2.3 - BUGFIX: rescue @ssh.close when far end closes disgracefully (ALU ISAM) diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index 6f30af4..227f656 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -9,16 +9,11 @@ module Oxidized def load node_want=nil with_lock do new = [] - node_want_ip = (IPAddr.new(node_want) rescue false) if node_want @source = CFG.source.default Oxidized.mgr.add_source @source Oxidized.mgr.source[@source].new.load.each do |node| - # we want to load specific node(s), not all of them - if node_want - next unless node_want_ip == node[:ip] or node_want.match(node[:name]) - end - + next unless node_want? node_want, node begin _node = Node.new node new.push _node @@ -33,6 +28,19 @@ module Oxidized end end + def node_want? node_want, node + node_want_ip = (IPAddr.new(node_want) rescue false) + name_is_ip = (IPAddr.new(node[:name]) rescue false) + if name_is_ip and node_want_ip == node[:name] + true + elsif node[:ip] and node_want_ip == node[:ip] + true + elsif node_want.match node[:name] + true unless name_is_ip + end + end + + def list with_lock do map { |e| e.serialize } |