lib/oxidized/model/powerconnect.rb in oxidized-0.25.1 vs lib/oxidized/model/powerconnect.rb in oxidized-0.26.0

- old
+ new

@@ -17,19 +17,19 @@ cfg.gsub! /^(tacacs-server key) \S+/, '\\1 <secret hidden>' cfg end cmd 'show version' do |cfg| - if (@stackable.nil?) - @stackable = true if cfg.match /(U|u)nit\s/ + if @stackable.nil? + @stackable = true if cfg =~ /(U|u)nit\s/ end cfg = cfg.split("\n").reject { |line| line[/Up\sTime/] } comment cfg.join("\n") + "\n" end cmd 'show system' do |cfg| - @model = $1 if cfg.match /Power[C|c]onnect (\d{4})[P|F]?/ + @model = Regexp.last_match(1) if cfg =~ /Power[C|c]onnect (\d{4})[P|F]?/ clean cfg end cmd 'show running-config' do |cfg| cfg.sub(/^(sflow \S+ destination owner \S+ timeout )\d+$/, '! \1<timeout>') @@ -43,32 +43,32 @@ cfg :telnet, :ssh do post_login do if vars(:enable) == true cmd "enable" elsif vars(:enable) - cmd "enable", /^[pP]assword:/ + cmd "enable", /[pP]assword:/ cmd vars(:enable) end end post_login "terminal datadump" post_login "terminal length 0" pre_logout "logout" pre_logout "exit" end - def clean cfg + def clean(cfg) out = [] skip_blocks = 0 cfg.each_line do |line| # If this is a stackable switch we should skip this block of information - if (line.match /Up\sTime|Temperature|Power Suppl(ies|y)|Fans/i and @stackable == true) + if line.match(/Up\sTime|Temperature|Power Suppl(ies|y)|Fans/i) && (@stackable == true) skip_blocks = 1 # Some switches have another empty line. This is identified by this line having a colon - skip_blocks = 2 if line.match /:/ + skip_blocks = 2 if line =~ /:/ end # If we have lines to skip do this until we reach and empty line - if skip_blocks > 0 + if skip_blocks.positive? skip_blocks -= 1 if /\S/ !~ line next end out << line.strip end