Merge ASA.PM patch by stromsoe (#494}

* Embedded # characters in the output for show names cause sshcollector not to collect any ARP entries on the ASA platform, since the $prompt variable matches in the middle of the output. Fix is to modify $prompt to match end-of-line.
 * Changing the terminal pager length should be done before sending show names instead of after.
 * Matching on IP address to see if a name needs to be mapped should include start and end field markers, in the event that the name returned from "show arp" embeds an IP address (eg, "abc1.2.3.4xyz")
This commit is contained in:
Christian Ramseyer
2019-01-29 23:40:43 +01:00
parent 914e484b33
commit dc9feb747f

View File

@@ -75,21 +75,21 @@ sub arpnip {
$expect->send( $args->{enable_password} ."\n" );
}
$prompt = qr/#/;
$prompt = qr/#\s*$/;
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
$expect->send("terminal pager 2147483647\n");
($pos, $error, $match, $before, $after) = $expect->expect(5, -re, $prompt);
$expect->send("show names\n");
($pos, $error, $match, $before, $after) = $expect->expect(60, -re, $prompt);
my @names = split(m/\n/, $before);
$expect->send("terminal pager 2147483647\n");
($pos, $error, $match, $before, $after) = $expect->expect(5, -re, $prompt);
$expect->send("show arp\n");
($pos, $error, $match, $before, $after) = $expect->expect(60, -re, $prompt);
my @lines = split(m/\n/, $before);
my @arpentries = ();
my @lines = split(m/\n/, $before);
# ifname 192.0.2.1 0011.2233.4455 123
my $linereg = qr/[A-z0-9\-\.]+\s([A-z0-9\-\.]+)\s
@@ -98,7 +98,7 @@ sub arpnip {
foreach my $line (@lines) {
if ($line =~ $linereg) {
my ($ip, $mac) = ($1, $2);
if ($ip !~ m/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/) {
if ($ip !~ m/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
foreach my $name (@names) {
if ($name =~ qr/name\s([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\s([\w-]*)/x) {
if ($ip eq $2) {
@@ -107,7 +107,7 @@ sub arpnip {
}
}
}
if ($ip =~ m/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/) {
if ($ip =~ m/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/) {
push @arpentries, { mac => $mac, ip => $ip };
}
}