I was able to get a working solution for our Aruba controllers with the help of this thread and figured I would post for anyone wanting to do the same. It works with a custom alert and a perl cron script that runs every day. We have been using this setup for about 2 years and it works great. Also no manual maintenance when changing names, adding aps, removing aps etc.
Librenms Alert:
SELECT distinct mac_addr, deleted, name FROM access_points WHERE (access_points.device_id = ?) && (access_points.deleted = ‘1’ )
Librenms Template:
<b>{{ $alert->title }}<br>
<br>
Ap Information</b>:<br>
@foreach ($alert->faults as $key => $value)
AP Name: {{ $alert->faults[$key]['name'] }} <br>
AP Mac: {{ $alert->faults[$key]['mac_addr'] }} <br>
@if ($alert->state == 0) Down since: {{ $alert->elapsed }} @endif
@endforeach
<br>
<b>Controller information</b>:<br>
Severity: {{ $alert->severity }}<br>
Timestamp: {{ $alert->timestamp }}<br>
Unique-ID: {{ $alert->uid }}<br>
Device ID: {{ $alert->device_id }}<br>
Hostname of the Device: {{ $alert->hostname }}<br>
sysName of the Device: {{ $alert->sysName }}<br>
sysDescr of the Device: {{ $alert->sysDescr }}<br>
sysContact of the Device: {{ $alert->sysContact }}<br>
This perl script runs every day and maintains the access_points database.
crontab: 0 12 * * * /root/sync_aruba_aps_to_librenms.pl >> /root/sync_aruba_aps_to_librenms.pl.cron.log 2>&1
Script ( Add host,password and controller prompt ):
#!/usr/bin/perl
use strict;
use warnings;
use Net::SSH::Expect;
use DBD::mysql;
print localtime . " Sync started.\n";
my $expected_low_ap_count = 175; # If there are lower than n AP's that get pulled from the controller the script will die.
my $ssh = Net::SSH::Expect->new (
host => '',
password=> '',
user => 'admin',
raw_pty => 1,
);
my $Prompt = qr/\(EXPECTED_PROMPT\) \*#/;
my $login_output = $ssh->login();
if ($login_output !~ $Prompt) {
die localtime . " Login has failed. Login output was $login_output";
}
$ssh->send("no paging");
$ssh->waitfor($Prompt, 2) or die localtime . " Failed to set no paging";
$ssh->send("show ap database long");
print localtime . " Logged into controller, requesting ap database.\n";
my $active_aps;
while ( defined (my $line = $ssh->read_line()) ) {
# If there is a mac on the line I assume its an AP listing
if ($line !~ /([0-9A-Fa-f]{2}[:]?){5}([0-9A-Fa-f]{2})/ ) { next }
my @data = split('\s+',$line);
if ($data[4] ne 'Up') {
splice @data, 5,0,undef;
}
if ($data[6] ne 'S') {
splice @data, 6,0,undef;
}
if (! $data[9]) { die localtime . " Could not get mac address"; }
if (! $data[0]) { die localtime . " Could not get name"; }
my $h = {
mac => $data[9],
name => $data[0],
master_ip => $data[7],
standby_ip => $data[8],
status => $data[4]
};
push @{$active_aps}, $h;
}
if ( !$active_aps ) {
die localtime . " Unable to grab aps from the controller. Bad output, cannot parse.\n";
}
if ( scalar @{$active_aps} < $expected_low_ap_count ) {
die localtime . " " . scalar @{$active_aps} . " were pulled from the controller, a low of $expected_low_ap_count is set.\n";
}
print localtime . " Pulled " . scalar @{$active_aps} . " AP's from the controller to sync.\n";
my $sql_not_in_mac_str = '(' . join(',',map{ "'" . $_->{mac} . "'"} @{$active_aps} ) . ')';
my $sql_not_in_name_str = '(' . join(',',map{ "'" . $_->{name} . "'"} @{$active_aps} ) . ')';
my @deletes;
foreach my $ap (@{$active_aps}) {
if ($ap->{status} eq 'Up') {
push @deletes, " ( name = '" . $ap->{name} . "' and deleted = '1' )"
}
}
my $sql_not_in_name_cont_str = join(' or ', @deletes );
my $dbh = DBI->connect("DBI:mysql:database=librenms;host=localhost",undef, undef, {'RaiseError' => 1});
# these two are for removing old access points
my $sth = $dbh->prepare("delete from access_points where mac_addr not in $sql_not_in_mac_str");
$sth->execute() or die localtime . " cannot execute not in mac query";
$sth = $dbh->prepare("delete from access_points where name not in $sql_not_in_name_str");
$sth->execute() or die localtime . " cannot execute not in name sql";
# deletes aps that are set to down in database but up in controller, this can happen with an ap swapped controllers or an ssid is gone.
$sth = $dbh->prepare("delete from access_points where $sql_not_in_name_cont_str");
$sth->execute() or die localtime . " cannot execute not in name sql";
print localtime . " Database queries successful.\n";