@@ -13,17 +13,43 @@ use GLPI::Agent::Tools::SNMP;
13
13
use constant ubnt => ' .1.3.6.1.4.1.41112' ;
14
14
use constant ubntWlStatApMac => ubnt . ' .1.4.5.1.4.1' ;
15
15
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
+
16
23
our $mibSupport = [
17
24
{
18
25
name => " ubnt" ,
19
26
oid => ubnt
27
+ },
28
+ {
29
+ name => " ubnt-unifi" ,
30
+ sysobjectid => getRegexpOidMatch(ubnt)
20
31
}
21
32
];
22
33
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
+
23
46
sub getSerial {
24
47
my ($self ) = @_ ;
25
48
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 };
27
53
$serial =~ s / :// g ;
28
54
29
55
return $serial ;
@@ -32,7 +58,60 @@ sub getSerial {
32
58
sub getMacAddress {
33
59
my ($self ) = @_ ;
34
60
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
+ }
36
115
}
37
116
38
117
1;
0 commit comments