Discussion:
[rancid] Ignore differences in certain lines?
Aaron Wasserott
2014-07-24 12:22:47 UTC
Permalink
Trying to capture 'show interface status' output from Cisco IOS switches, but ignore the output for diff purposes. Is that possible? I guess it would have to be part of the mailer function to not send output for certain lines.

I copied the ShowVLAN sub-routine because it already appends ! in front of the lines, so they are not considered config lines. But right now I can't even get the output captured.

This is the new sub I am using:


# This routine parses "show interface status"
sub ShowIntStat {
print STDERR " In ShowIntStat: $_" if ($debug);

#($_ = <INPUT>, return(1)) if (!$DO_SHOW_INT_STAT);

while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(1) if /Ambiguous command/i;
# newer releases (~12.1(9)) place the vlan config in the normal
# configuration (write term).
#return(1) if ($type =~ /^(3550|4500)$/);
#return(1) if ($type !~ /^(2900XL|3500XL|6000)$/);
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
if (/^(<-+ More -+>)/) {
my($len) = length($1);
s/^$1\s{$len}//;
}

ProcessHistory("COMMENTS","keysort","IO","!INT: $_");
}
ProcessHistory("COMMENTS","keysort","IO","!\n");
return(0);
}
Alan McKinnon
2014-07-24 15:30:07 UTC
Permalink
Trying to capture ‘show interface status’ output from Cisco IOS
switches, but ignore the output for diff purposes. Is that possible? I
guess it would have to be part of the mailer function to not send output
for certain lines.
I copied the ShowVLAN sub-routine because it already appends ! in front
of the lines, so they are not considered config lines. But right now I
can’t even get the output captured.
# This routine parses "show interface status"
sub ShowIntStat {
print STDERR " In ShowIntStat: $_" if ($debug);
#($_ = <INPUT>, return(1)) if (!$DO_SHOW_INT_STAT);
while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(1) if /Ambiguous command/i;
# newer releases (~12.1(9)) place the vlan config in the normal
# configuration (write term).
#return(1) if ($type =~ /^(3550|4500)$/);
#return(1) if ($type !~ /^(2900XL|3500XL|6000)$/);
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
if (/^(<-+ More -+>)/) {
my($len) = length($1);
s/^$1\s{$len}//;
}
ProcessHistory("COMMENTS","keysort","IO","!INT: $_");
}
ProcessHistory("COMMENTS","keysort","IO","!\n");
return(0);
}
Did you add corresponding entries to @command in the rancid script to
match your new sub? Just follow the existing pattern, it's obvious how
it must work.
--
Alan McKinnon
***@gmail.com
Aaron Wasserott
2014-07-24 15:48:35 UTC
Permalink
Post by Aaron Wasserott
Trying to capture 'show interface status' output from Cisco IOS
switches, but ignore the output for diff purposes. Is that possible? I
guess it would have to be part of the mailer function to not send
output for certain lines.
I copied the ShowVLAN sub-routine because it already appends ! in
front of the lines, so they are not considered config lines. But right
now I can't even get the output captured.
# This routine parses "show interface status"
sub ShowIntStat {
print STDERR " In ShowIntStat: $_" if ($debug);
#($_ = <INPUT>, return(1)) if (!$DO_SHOW_INT_STAT);
while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(1) if /Ambiguous command/i;
# newer releases (~12.1(9)) place the vlan config in the normal
# configuration (write term).
#return(1) if ($type =~ /^(3550|4500)$/);
#return(1) if ($type !~ /^(2900XL|3500XL|6000)$/);
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
if (/^(<-+ More -+>)/) {
my($len) = length($1);
s/^$1\s{$len}//;
}
ProcessHistory("COMMENTS","keysort","IO","!INT: $_");
}
ProcessHistory("COMMENTS","keysort","IO","!\n");
return(0);
}
Yep I added this line to the commandtable in the rancid file.

{'show interface status' => 'ShowIntStat'},

It is picking it up, because if I rename the my sub-routine I see an error in the logs. So something inside the sub-routine is not parsing output right.

I'll play around with it some more.

Thanks,

-Aaron
Alan McKinnon
2014-07-24 18:19:52 UTC
Permalink
Post by Aaron Wasserott
Post by Aaron Wasserott
Trying to capture 'show interface status' output from Cisco IOS
switches, but ignore the output for diff purposes. Is that possible? I
guess it would have to be part of the mailer function to not send
output for certain lines.
I copied the ShowVLAN sub-routine because it already appends ! in
front of the lines, so they are not considered config lines. But right
now I can't even get the output captured.
# This routine parses "show interface status"
sub ShowIntStat {
print STDERR " In ShowIntStat: $_" if ($debug);
#($_ = <INPUT>, return(1)) if (!$DO_SHOW_INT_STAT);
while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(1) if /Ambiguous command/i;
# newer releases (~12.1(9)) place the vlan config in the normal
# configuration (write term).
#return(1) if ($type =~ /^(3550|4500)$/);
#return(1) if ($type !~ /^(2900XL|3500XL|6000)$/);
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
if (/^(<-+ More -+>)/) {
my($len) = length($1);
s/^$1\s{$len}//;
}
ProcessHistory("COMMENTS","keysort","IO","!INT: $_");
}
ProcessHistory("COMMENTS","keysort","IO","!\n");
return(0);
}
Yep I added this line to the commandtable in the rancid file.
{'show interface status' => 'ShowIntStat'},
that's correct, it's also the only extra step you need to do. The call
Post by Aaron Wasserott
It is picking it up, because if I rename the my sub-routine I see an error in the logs. So something inside the sub-routine is not parsing output right.
I'll play around with it some more.
It's such a simple sub it's hard to see where it could do wrong.
If the ProcessHistory in the while loop is called, it will most
certainly record and output each line. So I can only assume the sub
exists early, or the switch output is odd somehow confusing the while.

My first crude debug steps would be to add a print statement just before
that ProcessHistory and run the script manually:

rancid -d <switch name from router.db>
and check you get as many prints on the console as there are lines in
"show interface status"

Then closely examine the switches output of "show interface status". The
form is simple:

- presence of the prompt signals end of output and the sub exits
- any line containing only whitespace and a carat is skipped
- any line containing the $cmd is skipped
Post by Aaron Wasserott
Thanks,
-Aaron
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo/rancid-discuss
--
Alan McKinnon
***@gmail.com
Aaron Wasserott
2014-07-24 18:38:07 UTC
Permalink
I got it to work, at least capturing additional input. The main thing I did to fix it was -not- put my new command at the bottom of the list. I kept getting this error:

Completed device.company.com: End of run not found

Then after moving my new command up in the commandtable array it worked fine.

Any thoughts/ideas on how to not email out based on changes to certain output?

Thanks,

-Aaron

-----Original Message-----
From: Rancid-discuss [mailto:rancid-discuss-***@shrubbery.net] On Behalf Of Aaron Wasserott
Sent: Thursday, July 24, 2014 9:49 AM
To: rancid-***@shrubbery.net
Subject: Re: [rancid] Ignore differences in certain lines?
Post by Aaron Wasserott
Trying to capture 'show interface status' output from Cisco IOS
switches, but ignore the output for diff purposes. Is that possible?
I guess it would have to be part of the mailer function to not send
output for certain lines.
I copied the ShowVLAN sub-routine because it already appends ! in
front of the lines, so they are not considered config lines. But
right now I can't even get the output captured.
# This routine parses "show interface status"
sub ShowIntStat {
print STDERR " In ShowIntStat: $_" if ($debug);
#($_ = <INPUT>, return(1)) if (!$DO_SHOW_INT_STAT);
while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(1) if /Ambiguous command/i;
# newer releases (~12.1(9)) place the vlan config in the normal
# configuration (write term).
#return(1) if ($type =~ /^(3550|4500)$/);
#return(1) if ($type !~ /^(2900XL|3500XL|6000)$/);
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
if (/^(<-+ More -+>)/) {
my($len) = length($1);
s/^$1\s{$len}//;
}
ProcessHistory("COMMENTS","keysort","IO","!INT: $_");
}
ProcessHistory("COMMENTS","keysort","IO","!\n");
return(0);
}
Yep I added this line to the commandtable in the rancid file.

{'show interface status' => 'ShowIntStat'},

It is picking it up, because if I rename the my sub-routine I see an error in the logs. So something inside the sub-routine is not parsing output right.

I'll play around with it some more.

Thanks,

-Aaron
Alan McKinnon
2014-07-24 20:38:01 UTC
Permalink
Post by Aaron Wasserott
Completed device.company.com: End of run not found
Then after moving my new command up in the commandtable array it worked fine.
Any thoughts/ideas on how to not email out based on changes to certain output?
I doubt that is possible without major surgery to the code. Two things
happen:

Files are booked into cvs/svn and that is an atomic process. CVS has to
work like that, it is almost useless otherwise.
If CVS recorded a diff, the diff is sent out as a mail.

You'll notice that CVS has no way to tag a changed line as somehow to be
recorded but not acted upon, so your only option is to hack rancid to
grab the output to be mailed and pass it through yet another perl text
parser (which you must maintain yourself)

It's so much easier to just have the rancid parser output the exact
information that you want to see. Rapidly changing data like current
state of an interface is better tracked through other monitoring tools.
Rancid is very bad at tracking state, but very very good at tracking the
changes people made on the cli (and providing restorable backups)
Post by Aaron Wasserott
Thanks,
-Aaron
-----Original Message-----
Sent: Thursday, July 24, 2014 9:49 AM
Subject: Re: [rancid] Ignore differences in certain lines?
Post by Aaron Wasserott
Trying to capture 'show interface status' output from Cisco IOS
switches, but ignore the output for diff purposes. Is that possible?
I guess it would have to be part of the mailer function to not send
output for certain lines.
I copied the ShowVLAN sub-routine because it already appends ! in
front of the lines, so they are not considered config lines. But
right now I can't even get the output captured.
# This routine parses "show interface status"
sub ShowIntStat {
print STDERR " In ShowIntStat: $_" if ($debug);
#($_ = <INPUT>, return(1)) if (!$DO_SHOW_INT_STAT);
while (<INPUT>) {
tr/\015//d;
last if (/^$prompt/);
next if (/^(\s*|\s*$cmd\s*)$/);
return(1) if /^\s*\^\s*$/;
return(1) if /Line has invalid autocommand /;
return(1) if /(Invalid input detected|Type help or )/;
return(1) if /Ambiguous command/i;
# newer releases (~12.1(9)) place the vlan config in the normal
# configuration (write term).
#return(1) if ($type =~ /^(3550|4500)$/);
#return(1) if ($type !~ /^(2900XL|3500XL|6000)$/);
return(-1) if (/command authorization failed/i);
# the pager can not be disabled per-session on the PIX
if (/^(<-+ More -+>)/) {
my($len) = length($1);
s/^$1\s{$len}//;
}
ProcessHistory("COMMENTS","keysort","IO","!INT: $_");
}
ProcessHistory("COMMENTS","keysort","IO","!\n");
return(0);
}
Yep I added this line to the commandtable in the rancid file.
{'show interface status' => 'ShowIntStat'},
It is picking it up, because if I rename the my sub-routine I see an error in the logs. So something inside the sub-routine is not parsing output right.
I'll play around with it some more.
Thanks,
-Aaron
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo/rancid-discuss
_______________________________________________
Rancid-discuss mailing list
http://www.shrubbery.net/mailman/listinfo/rancid-discuss
--
Alan McKinnon
***@gmail.com
Loading...