diff --git a/Netdisco/Changes b/Netdisco/Changes index 08e47c9f..6bbef9e9 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -1,3 +1,9 @@ +2.031012 - 2015-02-28 + + [ENHANCEMENTS] + + * Linux (arp) support in netdisco-sshcollector (M. Sheinberg) + 2.031011 - 2015-02-27 [BUG FIXES] diff --git a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/ACE.pm b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/ACE.pm index 3b047b03..0f862815 100644 --- a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/ACE.pm +++ b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/ACE.pm @@ -36,7 +36,7 @@ use Moo; 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 an array of hashrefs in the format { mac => MACADDR, ip => IPADDR }. +Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>. =cut diff --git a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/ASA.pm b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/ASA.pm index 3dd94a2c..cd9695d9 100644 --- a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/ASA.pm +++ b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/ASA.pm @@ -42,7 +42,7 @@ use Moo; 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 an array of hashrefs in the format { mac => MACADDR, ip => IPADDR }. +Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>. =cut diff --git a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/BigIP.pm b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/BigIP.pm index 9dd47e5f..4b98f35c 100644 --- a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/BigIP.pm +++ b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/BigIP.pm @@ -34,7 +34,7 @@ use Moo; 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 an array of hashrefs in the format { mac => MACADDR, ip => IPADDR }. +Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>. =cut sub arpnip { diff --git a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/IOS.pm b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/IOS.pm index 774f9294..c78a182e 100644 --- a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/IOS.pm +++ b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/IOS.pm @@ -27,7 +27,7 @@ use Moo; 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 an array of hashrefs in the format { mac => MACADDR, ip => IPADDR }. +Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>. =cut diff --git a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/IOSXR.pm b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/IOSXR.pm index 48a2ca11..6282e7b8 100644 --- a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/IOSXR.pm +++ b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/IOSXR.pm @@ -27,7 +27,7 @@ use Moo; 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 an array of hashrefs in the format { mac => MACADDR, ip => IPADDR }. +Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>. =cut diff --git a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/Linux.pm b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/Linux.pm new file mode 100644 index 00000000..c29af438 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/Linux.pm @@ -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" as the command for the arp utility on your +system. If you wish to specify an absolute path, then add an C +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 + +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-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; diff --git a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/PaloAlto.pm b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/PaloAlto.pm index e8e78d3a..ae599edb 100644 --- a/Netdisco/lib/App/Netdisco/SSHCollector/Platform/PaloAlto.pm +++ b/Netdisco/lib/App/Netdisco/SSHCollector/Platform/PaloAlto.pm @@ -28,7 +28,7 @@ use Moo; 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 an array of hashrefs in the format { mac => MACADDR, ip => IPADDR }. +Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>. =cut