class RARE < Oxidized::Model
prompt /([\w.@()-]+[#>]\s?)$/
#prompt /^([\w.@()-]+[#>]\s?)$/
comment '! '
cmd :all do |cfg|
# cfg.gsub! /\cH+\s{8}/, '' # example how to handle pager cfg.gsub! /\cH+/, '' # example how to handle pager get rid of errors for commands that don't work on some devices
cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
cfg.cut_both
end
cmd :secret do |cfg|
cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>'
cfg.gsub! /^(snmp-server host \S+( vrf \S+)?( version (1|2c|3))?)\s+\S+((\s+\S*)*)\s*/, '\\1 <secret hidden> \\5'
cfg.gsub! /^(username .+ (password|secret) \d) .+/, '\\1 <secret hidden>'
cfg.gsub! /^(enable (password|secret)( level \d+)? \d) .+/, '\\1 <secret hidden>'
cfg.gsub! /^(\s+(?:password|secret)) (?:\d )?\S+/, '\\1 <secret hidden>'
cfg.gsub! /^(.*wpa-psk ascii \d) (\S+)/, '\\1 <secret hidden>'
cfg.gsub! /^(.*key 7) (\d.+)/, '\\1 <secret hidden>'
cfg.gsub! /^(tacacs-server (.+ )?key) .+/, '\\1 <secret hidden>'
cfg.gsub! /^(crypto isakmp key) (\S+) (.*)/, '\\1 <secret hidden> \\3'
cfg.gsub! /^(\s+ip ospf message-digest-key \d+ md5) .+/, '\\1 <secret hidden>'
cfg.gsub! /^(\s+ip ospf authentication-key) .+/, '\\1 <secret hidden>'
cfg.gsub! /^(\s+neighbor \S+ password) .+/, '\\1 <secret hidden>'
cfg.gsub! /^(\s+vrrp \d+ authentication text) .+/, '\\1 <secret hidden>'
cfg.gsub! /^(\s+standby \d+ authentication) .{1,8}$/, '\\1 <secret hidden>'
cfg.gsub! /^(\s+standby \d+ authentication md5 key-string) .+?( timeout \d+)?$/, '\\1 <secret hidden> \\2'
cfg.gsub! /^(\s+key-string) .+/, '\\1 <secret hidden>'
cfg.gsub! /^((tacacs|radius) server [^\n]+\n(\s+[^\n]+\n)*\s+key) [^\n]+$/m, '\1 <secret hidden>'
cfg
end
cmd 'show platform' do |cfg|
comment "TEST: show platform"
comments = []
comments << cfg.lines.first
lines = cfg.lines
lines.each_with_index do |line, i|
if line !~ /^mem:|^uptime:/
comments << line.strip!
end
end
comments << "\n"
comment comments.join "\n"
end
cmd 'show interfaces description' do |cfg|
comment cfg
end
cmd 'show running-config' do |cfg|
cfg = cfg.each_line.to_a[3..-1]
cfg = cfg.reject { |line| line.match /^ntp clock-period / }.join
cfg.gsub! /^Current configuration : [^\n]*\n/, ''
cfg.gsub! /^ tunnel mpls traffic-eng bandwidth[^\n]*\n*(
(?: [^\n]*\n*)*
tunnel mpls traffic-eng auto-bw)/mx, '\1'
cfg
end
cfg :telnet do
username /^Username:/i
password /^Password:/i
end
cfg :telnet, :ssh do
# preferred way to handle additional passwords
post_login do
if vars(:enable) == true
cmd "enable"
elsif vars(:enable)
cmd "enable", /^[pP]assword:/
cmd vars(:enable)
end
end
post_login 'terminal length 0'
post_login 'terminal width 0'
pre_logout 'exit'
end
end |