relocate repo files so ND2 is the only code
This commit is contained in:
88
lib/App/Netdisco/SSHCollector/Platform/ACE.pm
Normal file
88
lib/App/Netdisco/SSHCollector/Platform/ACE.pm
Normal file
@@ -0,0 +1,88 @@
|
||||
package App::Netdisco::SSHCollector::Platform::ACE;
|
||||
|
||||
# vim: set expandtab tabstop=8 softtabstop=4 shiftwidth=4:
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::ACE
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from Cisco ACE load balancers. ACEs have multiple
|
||||
virtual contexts with individual ARP tables. Contexts are enumerated
|
||||
with C<show context>, afterwards the commands C<changeto CONTEXTNAME> and
|
||||
C<show arp> must be executed for every context.
|
||||
|
||||
The IOS shell does not permit to combine mulitple commands in a single
|
||||
line, and Net::OpenSSH uses individual connections for individual commands,
|
||||
so we need to use Expect to execute the changeto and show commands in
|
||||
the same context.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Expect;
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>.
|
||||
|
||||
=cut
|
||||
|
||||
sub arpnip{
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
|
||||
my ($pty, $pid) = $ssh->open2pty or die "unable to run remote command";
|
||||
my $expect = Expect->init($pty);
|
||||
|
||||
my ($pos, $error, $match, $before, $after);
|
||||
my $prompt = qr/#/;
|
||||
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
$expect->send("terminal length 0\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(5, -re, $prompt);
|
||||
|
||||
$expect->send("show context | include Name\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(5, -re, $prompt);
|
||||
|
||||
my @ctx;
|
||||
my @arpentries;
|
||||
|
||||
for (split(/\n/, $before)){
|
||||
if (m/Name: (\S+)/){
|
||||
push(@ctx, $1);
|
||||
$expect->send("changeto $1\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(5, -re, $prompt);
|
||||
$expect->send("show arp\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(5, -re, $prompt);
|
||||
for (split(/\n/, $before)){
|
||||
my ($ip, $mac) = split(/\s+/);
|
||||
if ($ip =~ m/(\d{1,3}\.){3}\d{1,3}/ && $mac =~ m/[0-9a-f.]+/i) {
|
||||
push(@arpentries, { ip => $ip, mac => $mac });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$expect->send("exit\n");
|
||||
$expect->soft_close();
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
101
lib/App/Netdisco/SSHCollector/Platform/ASA.pm
Normal file
101
lib/App/Netdisco/SSHCollector/Platform/ASA.pm
Normal file
@@ -0,0 +1,101 @@
|
||||
package App::Netdisco::SSHCollector::Platform::ASA;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::ASA
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from Cisco ASA devices.
|
||||
|
||||
You will need the following configuration for the user to automatically enter
|
||||
C<enable> status after login:
|
||||
|
||||
aaa authorization exec LOCAL auto-enable
|
||||
|
||||
To use an C<enable> password seaparate from the login password, add an
|
||||
C<enable_password> under C<sshcollector> in your configuration file:
|
||||
|
||||
sshcollector:
|
||||
- ip: '192.0.2.1'
|
||||
user: oliver
|
||||
password: letmein
|
||||
enable_password: myenablepass
|
||||
platform: IOS
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Expect;
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>.
|
||||
|
||||
=cut
|
||||
|
||||
sub arpnip {
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
|
||||
my ($pty, $pid) = $ssh->open2pty or die "unable to run remote command";
|
||||
my $expect = Expect->init($pty);
|
||||
|
||||
my ($pos, $error, $match, $before, $after);
|
||||
my $prompt;
|
||||
|
||||
if ($args->{enable_password}) {
|
||||
$prompt = qr/>/;
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
$expect->send("enable\n");
|
||||
|
||||
$prompt = qr/Password:/;
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
$expect->send( $args->{enable_password} ."\n" );
|
||||
}
|
||||
|
||||
$prompt = qr/#/;
|
||||
($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 arp\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(60, -re, $prompt);
|
||||
|
||||
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
|
||||
([0-9a-fA-F]{4}\.[0-9a-fA-F]{4}\.[0-9a-fA-F]{4})/x;
|
||||
|
||||
foreach my $line (@lines) {
|
||||
if ($line =~ $linereg) {
|
||||
my ($ip, $mac) = ($1, $2);
|
||||
push @arpentries, { mac => $mac, ip => $ip };
|
||||
}
|
||||
}
|
||||
|
||||
$expect->send("exit\n");
|
||||
$expect->soft_close();
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
67
lib/App/Netdisco/SSHCollector/Platform/BigIP.pm
Normal file
67
lib/App/Netdisco/SSHCollector/Platform/BigIP.pm
Normal file
@@ -0,0 +1,67 @@
|
||||
package App::Netdisco::SSHCollector::Platform::BigIP;
|
||||
|
||||
# vim: set expandtab tabstop=8 softtabstop=4 shiftwidth=4:
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::BigIP
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from F5 BigIP load balancers. These are Linux boxes,
|
||||
but feature an additional, proprietary IP stack which does not show
|
||||
up in the standard SNMP ipNetToMediaTable.
|
||||
|
||||
These devices also feature a CLI interface similar to IOS, which can
|
||||
either be set as the login shell of the user, or be called from an
|
||||
ordinary shell. This module assumes the former, and if "show net arp"
|
||||
can't be executed, falls back to the latter.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>.
|
||||
|
||||
=cut
|
||||
sub arpnip {
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
|
||||
my @data = $ssh->capture("show net arp");
|
||||
unless (@data){
|
||||
@data = $ssh->capture('tmsh -c "show net arp"');
|
||||
}
|
||||
|
||||
chomp @data;
|
||||
my @arpentries;
|
||||
|
||||
foreach (@data){
|
||||
if (m/\d{1,3}\..*resolved/){
|
||||
my (undef, $ip, $mac) = split(/\s+/);
|
||||
|
||||
# ips can look like 172.19.254.143%10, clean
|
||||
$ip =~ s/%\d+//;
|
||||
|
||||
push(@arpentries, {mac => $mac, ip => $ip});
|
||||
}
|
||||
}
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
142
lib/App/Netdisco/SSHCollector/Platform/CPVSX.pm
Normal file
142
lib/App/Netdisco/SSHCollector/Platform/CPVSX.pm
Normal file
@@ -0,0 +1,142 @@
|
||||
package App::Netdisco::SSHCollector::Platform::CPVSX;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::CPVSX
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from Check Point VSX
|
||||
|
||||
This collector uses "C<arp>" as the command for the arp utility on your
|
||||
system. Clish "C<show arp>" dows not work correctly in versions prior to R77.30.
|
||||
Config example:
|
||||
|
||||
sshcollector:
|
||||
- ip: '192.0.2.1'
|
||||
user: oliver
|
||||
password: letmein
|
||||
expert_password: letmein2
|
||||
platform: CPVSX
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Expect;
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<< { mac => MACADDR, ip => IPADDR } >>.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
||||
sub arpnip {
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
my @arpentries = ();
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
|
||||
my ($pty, $pid) = $ssh->open2pty or die "unable to run remote command";
|
||||
my $expect = Expect->init($pty);
|
||||
|
||||
my ($pos, $error, $match, $before, $after);
|
||||
my $prompt;
|
||||
|
||||
$prompt = qr/>/;
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
# TODO: check CP os/version via "cpstat os" and VSX status via "show vsx"
|
||||
# $expect->send("show vsx\n");
|
||||
# ($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
# debug "$hostlabel $$ show vsx: $before";
|
||||
|
||||
# Enumerate virtual systems
|
||||
# Virtual systems list
|
||||
# VS ID VS NAME
|
||||
# 0 0
|
||||
# 1 BACKUP-VSX_xxxxxx_Context
|
||||
# ...
|
||||
|
||||
$expect->send("show virtual-system all\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
my @vsxentries = ();
|
||||
my @lines = split(m/\n/, $before);
|
||||
|
||||
my $linereg = qr/(\d+)\s+([A-Za-z0-9_-]+)/;
|
||||
foreach my $line (@lines) {
|
||||
if ($line =~ $linereg) {
|
||||
my ($vsid, $vsname) = ($1, $2);
|
||||
push @vsxentries, { vsid => $vsid, vsname=> $vsname };
|
||||
debug "$hostlabel $$ $vsid, $vsname";
|
||||
}
|
||||
}
|
||||
|
||||
# TODO:
|
||||
# Expert mode should be used only for pre-R77.30 versions
|
||||
# For R77.30 and later we can use:
|
||||
# set virtual-system $vsid
|
||||
# show arp dynamic all
|
||||
|
||||
$expect->send("expert\n");
|
||||
|
||||
$prompt = qr/Enter expert password:/;
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
$expect->send( $args->{expert_password} ."\n" );
|
||||
|
||||
$prompt = qr/#/;
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
foreach (@vsxentries) {
|
||||
my $vsid = $_->{vsid};
|
||||
debug "$hostlabel $$ arpnip VSID: $vsid";
|
||||
|
||||
$expect->send("vsenv $vsid\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
$expect->send("arp -n | tail -n +2\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
@lines = split(m/\n/, $before);
|
||||
|
||||
# 192.168.1.1 ether 00:b6:aa:f5:bb:6e C eth1
|
||||
$linereg = qr/([0-9\.]+)\s+ether\s+([a-fA-F0-9:]+)/;
|
||||
|
||||
foreach my $line (@lines) {
|
||||
if ($line =~ $linereg) {
|
||||
my ($ip, $mac) = ($1, $2);
|
||||
push @arpentries, { mac => $mac, ip => $ip };
|
||||
debug "$hostlabel $$ arpnip VSID: $vsid IP: $ip MAC: $mac";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$expect->send("exit\n");
|
||||
|
||||
$prompt = qr/>/;
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(5, -re, $prompt);
|
||||
|
||||
$expect->send("exit\n");
|
||||
|
||||
$expect->soft_close();
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
80
lib/App/Netdisco/SSHCollector/Platform/FreeBSD.pm
Normal file
80
lib/App/Netdisco/SSHCollector/Platform/FreeBSD.pm
Normal file
@@ -0,0 +1,80 @@
|
||||
package App::Netdisco::SSHCollector::Platform::FreeBSD;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::FreeBSD
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from FreeBSD routers.
|
||||
|
||||
This collector uses "C<arp>" as the command for the arp utility on your
|
||||
system. If you wish to specify an absolute path, then add an C<arp_command>
|
||||
item to your configuration:
|
||||
|
||||
sshcollector:
|
||||
- ip: '192.0.2.1'
|
||||
user: oliver
|
||||
password: letmein
|
||||
platform: FreeBSD
|
||||
arp_command: '/usr/sbin/arp'
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Expect;
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>.
|
||||
|
||||
=cut
|
||||
|
||||
sub arpnip {
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
|
||||
my ($pty, $pid) = $ssh->open2pty or die "unable to run remote command";
|
||||
my $expect = Expect->init($pty);
|
||||
|
||||
my ($pos, $error, $match, $before, $after);
|
||||
my $prompt = qr/\$/;
|
||||
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
my $command = ($args->{arp_command} || 'arp');
|
||||
$expect->send("$command -n -a\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(5, -re, $prompt);
|
||||
|
||||
my @arpentries = ();
|
||||
my @lines = split(m/\n/, $before);
|
||||
|
||||
# ? (192.0.2.1) at fe:ed:de:ad:be:ef on igb0_vlan2 expires in 658 seconds [vlan]
|
||||
my $linereg = qr/\s+\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\)\s+at\s+([a-fA-F0-9:]{17})\s+on/;
|
||||
|
||||
foreach my $line (@lines) {
|
||||
if ($line =~ $linereg) {
|
||||
my ($ip, $mac) = ($1, $2);
|
||||
push @arpentries, { mac => $mac, ip => $ip };
|
||||
}
|
||||
}
|
||||
|
||||
$expect->send("exit\n");
|
||||
$expect->soft_close();
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
81
lib/App/Netdisco/SSHCollector/Platform/GAIAEmbedded.pm
Normal file
81
lib/App/Netdisco/SSHCollector/Platform/GAIAEmbedded.pm
Normal file
@@ -0,0 +1,81 @@
|
||||
package App::Netdisco::SSHCollector::Platform::GAIAEmbedded;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::GAIAembedded
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from Checkpoint GAIA embedded Systems
|
||||
To get this Plugin to work you have to add an User like 'netdisco' with
|
||||
'Network admin' right in the GAIA embedded OS
|
||||
|
||||
This collector uses "C<arp>" as the command for the arp utility on your
|
||||
system. If you wish to specify an absolute path, then add an C<arp_command>
|
||||
item to your configuration:
|
||||
|
||||
sshcollector:
|
||||
- ip: '192.0.2.1'
|
||||
user: netdisco
|
||||
password: letmein
|
||||
platform: GAIAEmbedded
|
||||
arp_command: 'arp'
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Expect;
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>.
|
||||
|
||||
=cut
|
||||
|
||||
sub arpnip {
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
|
||||
my ($pty, $pid) = $ssh->open2pty or die "unable to run remote command";
|
||||
my $expect = Expect->init($pty);
|
||||
|
||||
my ($pos, $error, $match, $before, $after);
|
||||
my $prompt = qr/>/;
|
||||
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(30, -re, $prompt);
|
||||
|
||||
my $command = ($args->{arp_command} || 'arp');
|
||||
$expect->send("$command -n \n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(30, -re, $prompt);
|
||||
|
||||
my @arpentries = ();
|
||||
my @lines = split(m/\n/, $before);
|
||||
|
||||
# ? (192.168.17.178) at 5C:F9:DD:71:1F:08 [ether] on LAN1
|
||||
my $linereg = qr/\?\s+\(([0-9\.]+)\)\s+at\s+([a-fA-F0-9:]+)/;
|
||||
foreach my $line (@lines) {
|
||||
if ($line =~ $linereg) {
|
||||
my ($ip, $mac) = ($1, $2);
|
||||
push @arpentries, { mac => $mac, ip => $ip };
|
||||
}
|
||||
}
|
||||
|
||||
$expect->send("exit\n");
|
||||
$expect->soft_close();
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
54
lib/App/Netdisco/SSHCollector/Platform/IOS.pm
Normal file
54
lib/App/Netdisco/SSHCollector/Platform/IOS.pm
Normal file
@@ -0,0 +1,54 @@
|
||||
package App::Netdisco::SSHCollector::Platform::IOS;
|
||||
|
||||
# vim: set expandtab tabstop=8 softtabstop=4 shiftwidth=4:
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::IOS
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from Cisco IOS devices.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>.
|
||||
|
||||
=cut
|
||||
|
||||
sub arpnip {
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
my @data = $ssh->capture("show ip arp");
|
||||
|
||||
chomp @data;
|
||||
my @arpentries;
|
||||
|
||||
# Internet 172.16.20.15 13 0024.b269.867d ARPA FastEthernet0/0.1
|
||||
foreach my $line (@data) {
|
||||
next unless $line =~ m/^Internet/;
|
||||
my @fields = split m/\s+/, $line;
|
||||
|
||||
push @arpentries, { mac => $fields[3], ip => $fields[1] };
|
||||
}
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
57
lib/App/Netdisco/SSHCollector/Platform/IOSXR.pm
Normal file
57
lib/App/Netdisco/SSHCollector/Platform/IOSXR.pm
Normal file
@@ -0,0 +1,57 @@
|
||||
package App::Netdisco::SSHCollector::Platform::IOSXR;
|
||||
|
||||
# vim: set expandtab tabstop=8 softtabstop=4 shiftwidth=4:
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::IOSXR
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from Cisco IOSXR devices.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>.
|
||||
|
||||
=cut
|
||||
|
||||
sub arpnip {
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
my @data = $ssh->capture("show arp vrf all");
|
||||
|
||||
chomp @data;
|
||||
my @arpentries;
|
||||
|
||||
# 0.0.0.0 00:00:00 0000.0000.0000 Dynamic ARPA GigabitEthernet0/0/0/0
|
||||
foreach (@data) {
|
||||
|
||||
my ($ip, $age, $mac, $state, $t, $iface) = split(/\s+/);
|
||||
|
||||
if ($ip =~ m/(\d{1,3}\.){3}\d{1,3}/
|
||||
&& $mac =~ m/([0-9a-f]{4}\.){2}[0-9a-f]{4}/i) {
|
||||
push(@arpentries, { ip => $ip, mac => $mac });
|
||||
}
|
||||
}
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
80
lib/App/Netdisco/SSHCollector/Platform/Linux.pm
Normal file
80
lib/App/Netdisco/SSHCollector/Platform/Linux.pm
Normal file
@@ -0,0 +1,80 @@
|
||||
package App::Netdisco::SSHCollector::Platform::Linux;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::Linux
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from Linux routers
|
||||
|
||||
This collector uses "C<arp>" as the command for the arp utility on your
|
||||
system. If you wish to specify an absolute path, then add an C<arp_command>
|
||||
item to your configuration:
|
||||
|
||||
sshcollector:
|
||||
- ip: '192.0.2.1'
|
||||
user: oliver
|
||||
password: letmein
|
||||
platform: Linux
|
||||
arp_command: '/usr/sbin/arp'
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Expect;
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>.
|
||||
|
||||
=cut
|
||||
|
||||
sub arpnip {
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
|
||||
my ($pty, $pid) = $ssh->open2pty or die "unable to run remote command";
|
||||
my $expect = Expect->init($pty);
|
||||
|
||||
my ($pos, $error, $match, $before, $after);
|
||||
my $prompt = qr/\$/;
|
||||
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
my $command = ($args->{arp_command} || 'arp');
|
||||
$expect->send("$command -n | tail -n +2\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(5, -re, $prompt);
|
||||
|
||||
my @arpentries = ();
|
||||
my @lines = split(m/\n/, $before);
|
||||
|
||||
# 192.168.1.1 ether 00:b6:aa:f5:bb:6e C eth1
|
||||
my $linereg = qr/([0-9\.]+)\s+ether\s+([a-fA-F0-9:]+)/;
|
||||
|
||||
foreach my $line (@lines) {
|
||||
if ($line =~ $linereg) {
|
||||
my ($ip, $mac) = ($1, $2);
|
||||
push @arpentries, { mac => $mac, ip => $ip };
|
||||
}
|
||||
}
|
||||
|
||||
$expect->send("exit\n");
|
||||
$expect->soft_close();
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
65
lib/App/Netdisco/SSHCollector/Platform/PaloAlto.pm
Normal file
65
lib/App/Netdisco/SSHCollector/Platform/PaloAlto.pm
Normal file
@@ -0,0 +1,65 @@
|
||||
package App::Netdisco::SSHCollector::Platform::PaloAlto;
|
||||
|
||||
# vim: set expandtab tabstop=8 softtabstop=4 shiftwidth=4:
|
||||
|
||||
=head1 NAME
|
||||
|
||||
App::Netdisco::SSHCollector::Platform::PaloAlto
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Collect ARP entries from PaloAlto devices.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Dancer ':script';
|
||||
use Expect;
|
||||
use Moo;
|
||||
|
||||
=head1 PUBLIC METHODS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<arpnip($host, $ssh)>
|
||||
|
||||
Retrieve ARP entries from device. C<$host> is the hostname or IP address
|
||||
of the device. C<$ssh> is a Net::OpenSSH connection to the device.
|
||||
|
||||
Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>.
|
||||
|
||||
=cut
|
||||
|
||||
sub arpnip{
|
||||
my ($self, $hostlabel, $ssh, $args) = @_;
|
||||
|
||||
debug "$hostlabel $$ arpnip()";
|
||||
|
||||
my ($pty, $pid) = $ssh->open2pty or die "unable to run remote command";
|
||||
my $expect = Expect->init($pty);
|
||||
my ($pos, $error, $match, $before, $after);
|
||||
my $prompt = qr/> \r?$/;
|
||||
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(20, -re, $prompt);
|
||||
$expect->send("set cli pager off\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
$expect->send("show arp all\n");
|
||||
($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt);
|
||||
|
||||
my @arpentries;
|
||||
for (split(/\r\n/, $before)){
|
||||
next unless $_ =~ m/(\d{1,3}\.){3}\d{1,3}/;
|
||||
my ($tmp, $ip, $mac) = split(/\s+/);
|
||||
if ($ip =~ m/(\d{1,3}\.){3}\d{1,3}/ && $mac =~ m/([0-9a-f]{2}:){5}[0-9a-f]{2}/i) {
|
||||
push(@arpentries, { ip => $ip, mac => $mac });
|
||||
}
|
||||
}
|
||||
$expect->send("exit\n");
|
||||
$expect->soft_close();
|
||||
|
||||
return @arpentries;
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user