« blib/lib/App/Netdisco/SSHCollector/Platform/ArubaCX.pm
↑ Summary
blib/lib/App/Netdisco/SSHCollector/Platform/FreeBSD.pm »
| 1 | package App::Netdisco::SSHCollector::Platform::ArubaCont; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | App::Netdisco::SSHCollector::Platform::ArubaCont | ||
| 6 | |||
| 7 | =head1 DESCRIPTION | ||
| 8 | |||
| 9 | This module collects ARP entries from Aruba controllers. | ||
| 10 | |||
| 11 | =cut | ||
| 12 | |||
| 13 | use strict; | ||
| 14 | use warnings; | ||
| 15 | |||
| 16 | use Dancer ':script'; | ||
| 17 | use Expect; | ||
| 18 | use Moo; | ||
| 19 | |||
| 20 | =head1 PUBLIC METHODS | ||
| 21 | |||
| 22 | =over 4 | ||
| 23 | |||
| 24 | =item B<arpnip($host, $ssh)> | ||
| 25 | |||
| 26 | Retrieve ARP entries from the Aruba controller. C<$host> is the hostname or IP address | ||
| 27 | of the device. C<$ssh> is a Net::OpenSSH connection to the device. | ||
| 28 | Returns a list of hashrefs in the format C<{ mac => MACADDR, ip => IPADDR }>. | ||
| 29 | |||
| 30 | =back | ||
| 31 | |||
| 32 | =cut | ||
| 33 | |||
| 34 | sub arpnip { | ||
| 35 | my ($self, $hostlabel, $ssh, $args) = @_; | ||
| 36 | |||
| 37 | debug "$hostlabel arpnip() - Starting ARP collection for Aruba Controller"; | ||
| 38 | |||
| 39 | # Open pseudo-terminal | ||
| 40 | my ($pty, $pid) = $ssh->open2pty; | ||
| 41 | unless ($pty) { | ||
| 42 | debug "unable to run remote command [$hostlabel] " . $ssh->error; | ||
| 43 | return (); | ||
| 44 | } | ||
| 45 | |||
| 46 | my $expect = Expect->init($pty); | ||
| 47 | my $prompt = qr/#/; # Adjust to match the Aruba controller prompt | ||
| 48 | |||
| 49 | # Log into the controller and disable paging | ||
| 50 | $expect->expect(10, -re, $prompt); | ||
| 51 | $expect->send("no paging\n"); | ||
| 52 | $expect->expect(10, -re, $prompt); | ||
| 53 | |||
| 54 | # Send 'show arp' command | ||
| 55 | $expect->send("show arp\n"); | ||
| 56 | my ($pos, $error, $match, $before, $after) = $expect->expect(10, -re, $prompt); | ||
| 57 | |||
| 58 | # Parse the ARP output | ||
| 59 | my @data = split "\n", $before; | ||
| 60 | my @arpentries; | ||
| 61 | |||
| 62 | # Example regex matching for controller ARP output | ||
| 63 | foreach my $line (@data) { | ||
| 64 | if ($line =~ /(\d+\.\d+\.\d+\.\d+)\s+([\da-f:]+)\s+(vlan\d+)/) { | ||
| 65 | push @arpentries, { ip => $1, mac => $2, port => $3 }; | ||
| 66 | debug "$hostlabel - Parsed ARP entry: IP=$1, MAC=$2, Port=$3"; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | |||
| 70 | debug "$hostlabel - Parsed " . scalar(@arpentries) . " ARP entries"; | ||
| 71 | return @arpentries; | ||
| 72 | } | ||
| 73 | |||
| 74 | 1; |