Skip to content

Commit

Permalink
Improve Ubnt serial and SSID detection (#657)
Browse files Browse the repository at this point in the history
* Show SSID names instead of radio ifname on GLPI UI and fix Serial getting on UniFi AP series.
* Enhance UniFi AP support

Co-authored-by: Guillaume Bougard <gbougard@teclib.com>
  • Loading branch information
eduardomozart and g-bougard committed Apr 24, 2024
1 parent ed0c5ad commit 081728c
Showing 1 changed file with 81 additions and 2 deletions.
83 changes: 81 additions & 2 deletions lib/GLPI/Agent/SNMP/MibSupport/Ubnt.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,43 @@ use GLPI::Agent::Tools::SNMP;
use constant ubnt => '.1.3.6.1.4.1.41112';
use constant ubntWlStatApMac => ubnt . '.1.4.5.1.4.1';

# See UBNT-UniFi-MIB

use constant unifiVapEssid => ubnt . '.1.6.1.2.1.6';
use constant unifiVapName => ubnt . '.1.6.1.2.1.7';
use constant unifiApSystemVersion => ubnt . '.1.6.3.6.0';
use constant unifiApSystemModel => ubnt . '.1.6.3.3.0';

our $mibSupport = [
{
name => "ubnt",
oid => ubnt
},
{
name => "ubnt-unifi",
sysobjectid => getRegexpOidMatch(ubnt)
}
];

sub getFirmware {
my ($self) = @_;

return getCanonicalString($self->get(unifiApSystemVersion));
}

sub getModel {
my ($self) = @_;

return getCanonicalString($self->get(unifiApSystemModel));
}

sub getSerial {
my ($self) = @_;

my $serial = getCanonicalMacAddress($self->get(ubntWlStatApMac));
my $device = $self->device
or return;

my $serial = getCanonicalMacAddress($self->get(ubntWlStatApMac)) || $device->{MAC};
$serial =~ s/://g;

return $serial;
Expand All @@ -32,7 +58,60 @@ sub getSerial {
sub getMacAddress {
my ($self) = @_;

return $self->get(ubntWlStatApMac);
return getCanonicalMacAddress($self->get(ubntWlStatApMac));
}

sub run {
my ($self) = @_;

my $device = $self->device
or return;

# Get list of device ports (e.g. raX, raiX etc.)
my $ports = $device->{PORTS}->{PORT};

# Get list of SSID
my $unifiVapEssidValues = $self->walk(unifiVapEssid) || {};
# Get list of Radios (e.g. ra0, rai0 etc.)
my $unifiVapNameValues = $self->walk(unifiVapName) || {};
# The list of Radios is co-related to the list of SSIDs
# $unifiVapNameValues->{0} = ra0
# $unifiVapEssidValues->{0} = <SSID>

foreach my $port (keys(%$ports)) {
# For each device Radio port (raX, raiX etc.)
# If you have more than one SSID there will also be more raX, raiX for each SSID.
my $ifdescr = $device->{PORTS}->{PORT}->{$port}->{IFDESCR};
next unless defined($ifdescr) && $ifdescr =~ /^ra/;

# Replaces the port iftype from "Ethernet" (6) to "WiFi" (71)
if ($device->{PORTS}->{PORT}->{$port}->{IFTYPE} && $device->{PORTS}->{PORT}->{$port}->{IFTYPE} == 6) {
$device->{PORTS}->{PORT}->{$port}->{IFTYPE} = 71;
}

foreach my $index (keys(%$unifiVapNameValues)) {
# Compares the device's current radio port name to the AP's radio list (e.g. raX eq raX)
if ($ifdescr eq $unifiVapNameValues->{$index}) {
# Defines the port alias with the name of the radio (e.g. raX)
$device->{PORTS}->{PORT}->{$port}->{IFALIAS} = $ifdescr;
# Replaces the radio port name with its respective <SSID>
my $ifname = getCanonicalString($unifiVapEssidValues->{$index});

unless (empty($ifname)) {
# raX and raiX are the network interfaces for the 2.4GHz and 5GHz radios respectively
if ($ifdescr =~ m/^ra\d+$/) {
$ifname .= " (2.4GHz)";
} elsif ($ifdescr =~ m/^rai\d+$/) {
$ifname .= " (5GHz)";
}

$device->{PORTS}->{PORT}->{$port}->{IFNAME} = $ifname;
}

last;
}
}
}
}

1;
Expand Down

0 comments on commit 081728c

Please sign in to comment.