| 1 | package App::Netdisco::SSHCollector::Platform::BigIP; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | App::Netdisco::SSHCollector::Platform::BigIP | ||
| 6 | |||
| 7 | =head1 DESCRIPTION | ||
| 8 | |||
| 9 | Collect ARP entries from F5 BigIP load balancers. These are Linux boxes, | ||
| 10 | but feature an additional, proprietary IP stack which does not show | ||
| 11 | up in the standard SNMP ipNetToMediaTable. | ||
| 12 | |||
| 13 | These devices also feature a CLI interface similar to IOS, which can | ||
| 14 | either be set as the login shell of the user, or be called from an | ||
| 15 | ordinary shell. This module assumes the former, and if "show net arp" | ||
| 16 | can't be executed, falls back to the latter. | ||
| 17 | |||
| 18 | =cut | ||
| 19 | |||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | |||
| 23 | use Dancer ':script'; | ||
| 24 | use Moo; | ||
| 25 | |||
| 26 | =head1 PUBLIC METHODS | ||
| 27 | |||
| 28 | =over 4 | ||
| 29 | |||
| 30 | =item B<arpnip($host, $ssh)> | ||
| 31 | |||
| 32 | Retrieve ARP entries from device. C<$host> is the hostname or IP address | ||
| 33 | of the device. C<$ssh> is a Net::OpenSSH connection to the device. | ||
| 34 | |||
| 35 | Returns a list of hashrefs in the format C<{ mac =E<gt> MACADDR, ip =E<gt> IPADDR }>. | ||
| 36 | |||
| 37 | =back | ||
| 38 | |||
| 39 | =cut | ||
| 40 | |||
| 41 | sub arpnip { | ||
| 42 | my ($self, $hostlabel, $ssh, $args) = @_; | ||
| 43 | |||
| 44 | debug "$hostlabel $$ arpnip()"; | ||
| 45 | |||
| 46 | my @data = $ssh->capture("show net arp"); | ||
| 47 | unless (@data){ | ||
| 48 | @data = $ssh->capture('tmsh -c "show net arp"'); | ||
| 49 | } | ||
| 50 | |||
| 51 | chomp @data; | ||
| 52 | my @arpentries; | ||
| 53 | |||
| 54 | foreach (@data){ | ||
| 55 | if (m/\d{1,3}\..*resolved/){ | ||
| 56 | my (undef, $ip, $mac) = split(/\s+/); | ||
| 57 | |||
| 58 | # ips can look like 172.19.254.143%10, clean | ||
| 59 | $ip =~ s/%\d+//; | ||
| 60 | |||
| 61 | push(@arpentries, {mac => $mac, ip => $ip}); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | return @arpentries; | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; |