1package acos; 2## 3## @PACKAGE@ @VERSION@ 4@copyright@ 5# 6# RANCID - Really Awesome New Cisco confIg Differ 7# 8# a10.pm - A10 rancid procedures 9 10use 5.010; 11use strict 'vars'; 12use warnings; 13no warnings 'uninitialized'; 14require(Exporter); 15our @ISA = qw(Exporter); 16 17use rancid @VERSION@; 18 19@ISA = qw(Exporter rancid main); 20 21# load-time initialization 22sub import { 23 0; 24} 25 26# post-open(collection file) initialization 27sub init { 28 # add content lines and separators 29 ProcessHistory("","","","!RANCID-CONTENT-TYPE: $devtype\n!\n"); 30 31 0; 32} 33 34# main loop of input of device output 35sub inloop { 36 my($INPUT, $OUTPUT) = @_; 37 my($cmd, $rval); 38 39TOP: while(<$INPUT>) { 40 tr/\015//d; 41CMD: if (/[>#]\s?exit$/) { 42 $clean_run = 1; 43 last; 44 } 45 if (/^Error:/) { 46 print STDOUT ("$host a10login error: $_"); 47 print STDERR ("$host a10login error: $_") if ($debug); 48 $clean_run = 0; 49 last; 50 } 51 while (/[>#]\s*($cmds_regexp)\s*$/) { 52 $cmd = $1; 53 if (!defined($prompt)) { 54 $prompt = ($_ =~ /^([^#>]+[#>])/)[0]; 55 $prompt =~ s/([][}{)(+\\])/\\$1/g; 56 print STDERR ("PROMPT MATCH: $prompt\n") if ($debug); 57 } 58 print STDERR ("HIT COMMAND:$_") if ($debug); 59 if (! defined($commands{$cmd})) { 60 print STDERR "$host: found unexpected command - \"$cmd\"\n"; 61 $clean_run = 0; 62 last TOP; 63 } 64 $rval = &{$commands{$cmd}}($INPUT, $OUTPUT, $cmd); 65 delete($commands{$cmd}); 66 if ($rval == -1) { 67 $clean_run = 0; 68 last TOP; 69 } 70 if (defined($prompt)) { 71 if (/$prompt/) { 72 goto CMD; 73 } 74 } 75 } 76 } 77} 78 79sub basicFilter { 80 my($INPUT, $OUTPUT, $cmd, $prefix) = @_; 81 82 while (<$INPUT>) { 83 tr/\015//d; 84 next if (/^\s*$/); 85 next if (/^\s*\^$/); # cli cmd error marker 86 return(1) if (/% unrecognized command/i); # cli cmd error 87 return(1) if (/% incomplete command/i); # cli cmd error 88 last if (/$prompt/); 89 90 s/\s*$/\n/; # trim trailing WS 91 ProcessHistory($prefix,"","","!$prefix: $_"); 92 } 93 ProcessHistory($prefix,"","","!\n"); 94 return(0); 95} 96 97# parses show version 98sub ShowVersion { 99 my($INPUT, $OUTPUT, $cmd) = @_; 100 print STDERR " In ShowVersion: $_" if ($debug); 101 102 while (<$INPUT>) { 103 tr/\015//d; 104 next if /^\s*$/; 105 last if (/$prompt/); 106 107 next if (/Current time is/); 108 next if (/The system has been up/); 109 next if (/Last configuration saved/); 110 next if (/Free Memory/); 111 ProcessHistory("VERSION","","","!VERSION: $_"); 112 } 113 ProcessHistory("VERSION","","","!\n"); 114 return(0); 115} 116 117# parses show admin 118sub ShowAdmin { 119 my($INPUT, $OUTPUT, $cmd) = @_; 120 print STDERR " In ShowAdmin: $_" if ($debug); 121 return basicFilter($INPUT, $OUTPUT, $cmd, "Users"); 122} 123 124sub ShowAflex { 125 my($INPUT, $OUTPUT, $cmd) = @_; 126 print STDERR " In ShowAflex: $_" if ($debug); 127 128 while (<$INPUT>) { 129 tr/\015//d; 130 next if /^\s*$/; 131 last if (/^$prompt/); 132 return(1) if (/% unrecognized command\./i); # not in CGN/LSN image 133 134 s/\s*$/\n/; # trim trailing WS 135 ProcessHistory("AFLEX", "", "", "!AFLEX: $_"); 136 } 137 while (/show aflex (\S+) partition/) { 138 my($name) = $1; 139 my($found_content) = 0; 140 141 ProcessHistory("AFLEX-$name", "", "", "aflex create $name\n"); 142 while (<$INPUT>) { 143 tr/\015//d; 144 last if (/^$prompt/); 145 146 if ($found_content) { 147 ProcessHistory("AFLEX-$name", "", "", "$_"); 148 } elsif (/^Content:/) { 149 $found_content = 1 150 } 151 } 152 if ($found_content) { 153 ProcessHistory("AFLEX-$name", "", "", ".\n"); 154 } 155 } 156 ProcessHistory("ADMIN","","","!\n"); 157 return(0); 158} 159 160# parses show bootimage 161sub ShowBootimage { 162 my($INPUT, $OUTPUT, $cmd) = @_; 163 print STDERR " In ShowBootimage: $_" if ($debug); 164 return basicFilter($INPUT, $OUTPUT, $cmd, "BootImage"); 165} 166 167# parses show license 168sub ShowLicense { 169 my($INPUT, $OUTPUT, $cmd) = @_; 170 print STDERR " In ShowLicense: $_" if ($debug); 171 return basicFilter($INPUT, $OUTPUT, $cmd, "LICENSE"); 172} 173 174# parses show running-config 175sub ShowRunningConfig { 176 my($INPUT, $OUTPUT, $cmd) = @_; 177 my $comment = 0; 178 print STDERR " In ShowRunningConfig: $_" if ($debug); 179 180 while (<$INPUT>) { 181 tr/\015//d; 182 next if (/^\s*$/); 183 next if (/^\s*\^$/); # cli cmd error marker 184 return(1) if (/% unrecognized command/i); # cli cmd error 185 last if (/^$prompt/); 186 return(1) if (/invalid (input|command) detected/i); 187 188 # skip consecutive comment lines 189 if (/^!\s*$/) { 190 next if ($comment); 191 ProcessHistory("CONFIG","","",$_); 192 $comment = 1; 193 next; 194 } 195 $comment = 0; 196 197 next if (/^!(current configuration:|configuration last)/i); 198 next if (/^vcs config-info/); 199 if ((/^(.* password encrypted )\S+(.*)/ || 200 /^(.* secret secret-encrypted )\w+( .*)/) && $filter_pwds >= 1) { 201 ProcessHistory("CONFIG", "", "", "$1<removed>$2\n"); 202 next; 203 } 204 if (/^(snmp-server community \S+ )\S+(.*)/ && $filter_commstr >= 1) { 205 ProcessHistory("CONFIG", "", "", "!$1<removed>$2\n"); 206 next; 207 } 208 ProcessHistory("CONFIG","","","$_"); 209 if (/^end/) { 210 $found_end = 1; 211 } 212 } 213 ProcessHistory("CONFIG","","","\n"); 214 215 return(0); 216} 217 218# parses show vlan 219sub ShowVlan { 220 my($INPUT, $OUTPUT, $cmd) = @_; 221 print STDERR " In ShowVlan: $_" if ($debug); 222 return basicFilter($INPUT, $OUTPUT, $cmd, "VLAN"); 223} 224 2251; 226