Discussion:
[rancid] wrong code with "Last configuration change at...."
Iñaki Martinez Diez
2009-09-25 13:38:27 UTC
Permalink
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.
A***@HydroOne.com
2009-09-25 14:54:31 UTC
Permalink
Thanks. Works great !!! was looking for this for a longtime.

-----Original Message-----
From: rancid-discuss-***@shrubbery.net [mailto:rancid-discuss-***@shrubbery.net] On Behalf Of Iñaki Martinez Diez
Sent: Friday, September 25, 2009 9:38 AM
To: rancid-***@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.
Frank Bulk
2009-09-26 00:36:26 UTC
Permalink
I presume you delete line 1525 (from the original code snippet)?

Frank

-----Original Message-----
From: rancid-discuss-***@shrubbery.net
[mailto:rancid-discuss-***@shrubbery.net] On Behalf Of Iñaki Martinez
Diez
Sent: Friday, September 25, 2009 8:38 AM
To: rancid-***@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.
Mathiruban Rajagopal
2009-11-16 14:06:06 UTC
Permalink
Hi,

Which file I have to edit?
I am not getting the last config change for cisco routers.

Mathy.
Post by Iñaki Martinez Diez
Hi,
! 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
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
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
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
Loading...