@@ -13,17 +13,43 @@ use GLPI::Agent::Tools::SNMP;
1313use constant ubnt => ' .1.3.6.1.4.1.41112' ;
1414use constant ubntWlStatApMac => ubnt . ' .1.4.5.1.4.1' ;
1515
16+ # See UBNT-UniFi-MIB
17+
18+ use constant unifiVapEssid => ubnt . ' .1.6.1.2.1.6' ;
19+ use constant unifiVapName => ubnt . ' .1.6.1.2.1.7' ;
20+ use constant unifiApSystemVersion => ubnt . ' .1.6.3.6.0' ;
21+ use constant unifiApSystemModel => ubnt . ' .1.6.3.3.0' ;
22+
1623our $mibSupport = [
1724 {
1825 name => " ubnt" ,
1926 oid => ubnt
27+ },
28+ {
29+ name => " ubnt-unifi" ,
30+ sysobjectid => getRegexpOidMatch(ubnt)
2031 }
2132];
2233
34+ sub getFirmware {
35+ my ($self ) = @_ ;
36+
37+ return getCanonicalString($self -> get(unifiApSystemVersion));
38+ }
39+
40+ sub getModel {
41+ my ($self ) = @_ ;
42+
43+ return getCanonicalString($self -> get(unifiApSystemModel));
44+ }
45+
2346sub getSerial {
2447 my ($self ) = @_ ;
2548
26- my $serial = getCanonicalMacAddress($self -> get(ubntWlStatApMac));
49+ my $device = $self -> device
50+ or return ;
51+
52+ my $serial = getCanonicalMacAddress($self -> get(ubntWlStatApMac)) || $device -> {MAC };
2753 $serial =~ s / :// g ;
2854
2955 return $serial ;
@@ -32,7 +58,60 @@ sub getSerial {
3258sub getMacAddress {
3359 my ($self ) = @_ ;
3460
35- return $self -> get(ubntWlStatApMac);
61+ return getCanonicalMacAddress($self -> get(ubntWlStatApMac));
62+ }
63+
64+ sub run {
65+ my ($self ) = @_ ;
66+
67+ my $device = $self -> device
68+ or return ;
69+
70+ # Get list of device ports (e.g. raX, raiX etc.)
71+ my $ports = $device -> {PORTS }-> {PORT };
72+
73+ # Get list of SSID
74+ my $unifiVapEssidValues = $self -> walk(unifiVapEssid) || {};
75+ # Get list of Radios (e.g. ra0, rai0 etc.)
76+ my $unifiVapNameValues = $self -> walk(unifiVapName) || {};
77+ # The list of Radios is co-related to the list of SSIDs
78+ # $unifiVapNameValues->{0} = ra0
79+ # $unifiVapEssidValues->{0} = <SSID>
80+
81+ foreach my $port (keys (%$ports )) {
82+ # For each device Radio port (raX, raiX etc.)
83+ # If you have more than one SSID there will also be more raX, raiX for each SSID.
84+ my $ifdescr = $device -> {PORTS }-> {PORT }-> {$port }-> {IFDESCR };
85+ next unless defined ($ifdescr ) && $ifdescr =~ / ^ra/ ;
86+
87+ # Replaces the port iftype from "Ethernet" (6) to "WiFi" (71)
88+ if ($device -> {PORTS }-> {PORT }-> {$port }-> {IFTYPE } && $device -> {PORTS }-> {PORT }-> {$port }-> {IFTYPE } == 6) {
89+ $device -> {PORTS }-> {PORT }-> {$port }-> {IFTYPE } = 71;
90+ }
91+
92+ foreach my $index (keys (%$unifiVapNameValues )) {
93+ # Compares the device's current radio port name to the AP's radio list (e.g. raX eq raX)
94+ if ($ifdescr eq $unifiVapNameValues -> {$index }) {
95+ # Defines the port alias with the name of the radio (e.g. raX)
96+ $device -> {PORTS }-> {PORT }-> {$port }-> {IFALIAS } = $ifdescr ;
97+ # Replaces the radio port name with its respective <SSID>
98+ my $ifname = getCanonicalString($unifiVapEssidValues -> {$index });
99+
100+ unless (empty($ifname )) {
101+ # raX and raiX are the network interfaces for the 2.4GHz and 5GHz radios respectively
102+ if ($ifdescr =~ m / ^ra\d +$ / ) {
103+ $ifname .= " (2.4GHz)" ;
104+ } elsif ($ifdescr =~ m / ^rai\d +$ / ) {
105+ $ifname .= " (5GHz)" ;
106+ }
107+
108+ $device -> {PORTS }-> {PORT }-> {$port }-> {IFNAME } = $ifname ;
109+ }
110+
111+ last ;
112+ }
113+ }
114+ }
36115}
37116
381171;
0 commit comments