[rancid] Re: wrong code with "Last configuration change at...."

Frank Bulk frnkblk at iname.com
Sat Sep 26 00:36:26 UTC 2009


I presume you delete line 1525 (from the original code snippet)?

Frank

-----Original Message-----
From: rancid-discuss-bounces at shrubbery.net
[mailto:rancid-discuss-bounces at shrubbery.net] On Behalf Of Iñaki Martinez
Diez
Sent: Friday, September 25, 2009 8:38 AM
To: rancid-discuss at shrubbery.net
Subject: [rancid] wrong code with "Last configuration change at...."

Hi,

 I want to log the lines:

 ! Last configuration change at 12:50:31 GMT Fri Sep 25 2009 by xxxxx
 ! NVRAM config last updated at 08:35:27 GMT Fri Sep 25 2009 by xxxxx


 But this code is wrong:

1488 # This routine processes a "write term"
1489 sub WriteTerm {
1490     print STDERR "    In WriteTerm: $_" if ($debug);
1491     my($lineauto,$comment,$linecnt) = (0,0,0);
1492
1493     while (<INPUT>) {
1494         tr/\015//d;
1495         last if (/^$prompt/);
1496         return(1) if /Line has invalid autocommand /;
1497         return(1) if (/(Invalid input detected|Type help or )/i);
1498         return(0) if ($found_end);              # Only do this 
routine once
1499         return(-1) if (/command authorization failed/i);
1500         # the pager can not be disabled per-session on the PIX
1501         if (/^(<-+ More -+>)/) {
1502             my($len) = length($1);
1503             s/^$1\s{$len}//;
1504         }
1505
1506         /Non-Volatile memory is in use/  && return(-1); # NvRAM is 
locked
1507         $linecnt++;
1508         $lineauto = 0 if (/^[^ ]/);
1509         # skip the crap
1510         if (/^(##+$|(Building|Current) configuration)/i) {
1511             while (<INPUT>) {
1512                 next if (/^Current configuration\s*:/i);
1513                 next if (/^:/);
1514                 next if (/^([%!].*|\s*)$/);
1515                 next if (/^ip add.*ipv4:/);     # band-aid for 3620 
12.0S
1516                 last;
1517             }
1518             if (defined($config_register)) {
1519                 ProcessHistory("","","","!\nconfig-register 
$config_register\n");
1520             }
1521             tr/\015//d;
1522         }
1523         # some versions have other crap mixed in with the bits in the
1524         # block above
1525         /^! (Last configuration|NVRAM config last)/ && next;
1526

 Although i commented the line 1525 the lines above are NEVER logged 
because the "while" loop in the line 1511 ignore and the two lines are 
never processed by line 1525, so i made this changes:

1488 # This routine processes a "write term"
1489 sub WriteTerm {
1490     print STDERR "    In WriteTerm: $_" if ($debug);
1491     my($lineauto,$comment,$linecnt) = (0,0,0);
1492
1493     while (<INPUT>) {
1494     tr/\015//d;
1495     last if (/^$prompt/);
1496     return(1) if /Line has invalid autocommand /;
1497     return(1) if (/(Invalid input detected|Type help or )/i);
1498     return(0) if ($found_end);      # Only do this routine once
1499     return(-1) if (/command authorization failed/i);
1500     # the pager can not be disabled per-session on the PIX
1501     if (/^(<-+ More -+>)/) {
1502         my($len) = length($1);
1503         s/^$1\s{$len}//;
1504     }
1505
1506     /Non-Volatile memory is in use/  && return(-1); # NvRAM is locked
1507     $linecnt++;
1508     $lineauto = 0 if (/^[^ ]/);
1509     # skip the crap
1510     if (/^(##+$|(Building|Current) configuration)/i) {
1511         while (<INPUT>) {
1512         if (/^! (Last configuration|NVRAM config last)/) {
1513             ProcessHistory("","","",$_);
1514             next;
1515         }
1516         next if (/^Current configuration\s*:/i);
1517         next if (/^:/);
1518         next if (/^([%!].*|\s*)$/);
1519         next if (/^ip add.*ipv4:/); # band-aid for 3620 12.0S
1520         last;
1521         }
1522         if (defined($config_register)) {
1523         ProcessHistory("","","","!\nconfig-register 
$config_register\n");
1524         }
1525         tr/\015//d;
1526     }
1527     # some versions have other crap mixed in with the bits in the
1528     # block above
1529

 So now the two lines are logged and emailed.

 I hope this can help somebody.


_______________________________________________
Rancid-discuss mailing list
Rancid-discuss at shrubbery.net
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss



More information about the Rancid-discuss mailing list