Updated netgear.rb for Netgear GS108Tv3 and other Netgear smart pro switches

Hi,
I had some struggle with backing up the config of Netgear GS108Tv3 switches (especially with the prompt regex and the “terminal length 0” command missing on those devices and so they always got stock at “–More–” asking for user interaction). This updated netgear.rb seems to work. Can somebody revise it and maybe push it to the Oxidized repository? I don’t have git myself.

class Netgear < Oxidized::Model
comment ‘!’
prompt /([a-zA-Z0-9\s+-()]+)((#\s?)|(\s>))/

expect /(\n\s*–More–\s*$)|(^\s*(q)uit$)/m do |data, re|
if data =~ /(\n\s*–More–\s*$)/
send ’ ’
elsif data =~ /(^\s*(q)uit$)/
send ‘q’
end
data.sub re, ‘’
end

cmd :secret do |cfg|
cfg.gsub!(/password (\S+)/, ‘password ’)
cfg.gsub!(/encrypted (\S+)/, ‘encrypted ’)
cfg.gsub!(/snmp community (\S+) (.*)$/, ‘snmp community \2’)
cfg.gsub!(/snmp-server community (\S+)$/, ‘snmp-server community ’)
cfg.gsub!(/snmp-server community (\S+) (\S+) (\S+)/, ‘snmp-server community \1 \2 ’)
cfg
end

cfg :telnet do
username /^(User:|Applying Interface configuration, please wait …)/
password /^Password:/i
end

cfg :telnet, :ssh do
post_login do
if vars(:enable) == true
cmd “enable”
elsif vars(:enable)
cmd “enable”, /[pP]assword:\s?$/
cmd vars(:enable)
end
cmd “terminal length 0” if !vars(:smartpro) || vars(:smartpro) == false
end

if vars(:smartpro) == true
  pre_logout 'exit'
  pre_logout 'exit'
else
  pre_logout 'quit'
  pre_logout 'n'
end

end

cmd :all do |cfg, cmdstring|
new_cfg = comment “COMMAND: #{cmdstring}\n”
new_cfg << cfg.each_line.to_a[1…-2].join
new_cfg.gsub! /(?<!exit\n)^$\n\n\n/m, ‘’ # remove triple-line-breaks from paging but NOT in the config blocks (exit preceded)
new_cfg
end

cmd ‘show version’ do |cfg|
cfg.gsub! /(Current Time.+ )./, ‘\1 ’
cfg.gsub! /(FASTPATH IPv6 Management).
/m, “\1\n”
comment cfg
end

cmd ‘show bootvar’ do |cfg|
cfg.gsub!(/ \x80.*/n, ‘’)
comment cfg
end

cmd ‘show running-config’ do |cfg|
cfg.gsub! /(System Up Time)./, ‘\1 ’
cfg.gsub! /\e[.\e[.K/, ‘’
cfg.gsub! /\cH/, ‘’
cfg.gsub! /(Current SNTP Synchronized Time:).
/, ‘\1 ’
cfg
end
end

We don’t deal with code / development here I’m afraid. You’d need to do this on the oxidized GitHub repo.