From 25a8d7005e79af21529212d5bc20c5a07dc6e316 Mon Sep 17 00:00:00 2001 From: Richard Mayhew Date: Fri, 3 Feb 2017 21:48:55 +0200 Subject: feature: support IP Addressed provided with a netmask --- lib/oxidized/node.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/oxidized') diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index b13ce0e..60b335f 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -10,8 +10,12 @@ module Oxidized alias :running? :running def initialize opt Oxidized.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_address = opt[:ip] + ip_addr,ip_net = ip_address.to_s.split("/") + Oxidized.logger.debug 'IPADDR %s' % ip_addr.to_s @name = opt[:name] - @ip = IPAddr.new(opt[:ip]).to_s rescue nil + @ip = IPAddr.new(ip_addr).to_s rescue nil @ip ||= Resolv.new.getaddress @name @group = opt[:group] @input = resolve_input opt -- cgit v1.2.1 From 152763ea997b6dc54b79921fa424436b331694b2 Mon Sep 17 00:00:00 2001 From: Richard Mayhew Date: Fri, 3 Feb 2017 22:05:07 +0200 Subject: Updated split to be more efficient, thanks ytti! --- lib/oxidized/node.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/oxidized') diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 60b335f..6f89b56 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -11,8 +11,7 @@ module Oxidized def initialize opt Oxidized.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_address = opt[:ip] - ip_addr,ip_net = ip_address.to_s.split("/") + ip_addr, _ = opt[:ip].to_s.split("/") Oxidized.logger.debug 'IPADDR %s' % ip_addr.to_s @name = opt[:name] @ip = IPAddr.new(ip_addr).to_s rescue nil -- cgit v1.2.1