bury all dead whitespace, better off to just do it in one command. i wonder why ss...
[torrus-plus.git] / src / lib / Torrus / DevDiscover / Apple_AE.pm
blob49fc427d88bf83408d62101f9513732f5e18f584
2 # Copyright (C) 2007 Jon Nistor
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 # Jon Nistor <nistor at snickers.org>
20 # Apple Airport Extreme Discovery Module
22 # NOTE: Options for this module:
23 # Apple_AE::disable-clients
25 package Torrus::DevDiscover::Apple_AE;
27 use strict;
28 use warnings;
30 use Torrus::Log;
32 our $VERSION = 1.0;
35 $Torrus::DevDiscover::registry{'Apple_AE'} = {
36 'sequence' => 500,
37 'checkdevtype' => \&checkdevtype,
38 'discover' => \&discover,
39 'buildConfig' => \&buildConfig
43 our %oiddef =
45 # Apple Airport Extreme
46 'airportObject' => '1.3.6.1.4.1.63.501',
47 'baseStation3' => '1.3.6.1.4.1.63.501.3',
49 # Airport Information
50 'sysConfName' => '1.3.6.1.4.1.63.501.3.1.1.0',
51 'sysConfContact' => '1.3.6.1.4.1.63.501.3.1.2.0',
52 'sysConfLocation' => '1.3.6.1.4.1.63.501.3.1.3.0',
53 'sysConfFirmwareVersion' => '1.3.6.1.4.1.63.501.3.1.5.0',
55 'wirelessNumber' => '1.3.6.1.4.1.63.501.3.2.1.0',
56 'wirelessPhysAddress' => '1.3.6.1.4.1.63.501.3.2.2.1.1'
60 sub checkdevtype
62 my $dd = shift;
63 my $devdetails = shift;
65 # PROG: Standard sysObject does not work on Airport devices
66 # So we will match on the specific OID
67 if( not $dd->checkSnmpOID('sysConfName') )
69 return 0;
72 $devdetails->setCap('interfaceIndexingPersistent');
74 return 1;
78 sub discover
80 my $dd = shift;
81 my $devdetails = shift;
83 my $session = $dd->session();
84 my $data = $devdetails->data();
86 # NOTE: Comments and Serial number of device
87 my $chassisInfo =
88 $dd->retrieveSnmpOIDs( 'sysConfName', 'sysConfLocation',
89 'sysConfFirmwareVersion' );
91 if( defined( $chassisInfo ) )
93 if( not $chassisInfo->{'sysConfLocation'} )
95 $chassisInfo->{'sysConfLocation'} = "unknown";
98 $data->{'param'}{'comment'} = "Apple Airport Extreme, " .
99 "Fw#: " . $chassisInfo->{'sysConfFirmwareVersion'} . ", " .
100 $chassisInfo->{'sysConfName'} . " located at " .
101 $chassisInfo->{'sysConfLocation'};
102 } else {
103 $data->{'param'}{'comment'} = "Apple Airport Extreme";
107 # PROG: Find wireless clients
108 if( $devdetails->paramDisabled('Apple_AE::disable-clients') )
110 my $numWireless = $dd->retrieveSnmpOIDs('wirelessNumber');
112 my $tableClients =
113 $session->get_table( -baseoid =>
114 $dd->oiddef('wirelessPhysAddress') );
115 $devdetails->storeSnmpVars( $tableClients );
117 if( $tableClients && ($numWireless->{'wirelessNumber'} > 0) )
119 # PROG: setCap that we actually have clients ...
120 $devdetails->setCap('AE_clients');
122 for my $wClient ( $devdetails->getSnmpIndices
123 ($dd->oiddef('wirelessPhysAddress')) )
125 my $wMAC = $devdetails->snmpVar(
126 $dd->oiddef('wirelessPhysAddress') . "." . $wClient);
128 # Construct data
129 $data->{'Apple_AE'}{'wClients'}{$wClient} = undef;
130 $data->{'Apple_AE'}{'wClients'}{$wClient}{'wMAC'} = $wMAC;
132 Debug("Apple_AE:: Client $wMAC / $wClient");
137 return 1;
141 sub buildConfig
143 my $devdetails = shift;
144 my $cb = shift;
145 my $devNode = shift;
146 my $data = $devdetails->data();
149 # Wireless Client information
150 if( $devdetails->hasCap('AE_clients') )
152 my $nodeTop =
153 $cb->addSubtree( $devNode, 'Wireless_Clients', undef,
154 [ 'Apple_AE::ae-wireless-clients-subtree'] );
156 for my $wClient ( keys %{$data->{'Apple_AE'}{'wClients'}} )
158 my $airport = $data->{'Apple_AE'}{'wClients'}{$wClient};
159 my $wMAC = $airport->{'wMAC'};
160 my $wMACfix = $wMAC;
161 $wMACfix =~ s/:/_/g;
163 my $nodeWireless =
164 $cb->addSubtree( $nodeTop, $wMACfix,
165 { 'wireless-mac' => $wMAC,
166 'wireless-macFix' => $wMACfix,
167 'wireless-macOid' => $wClient },
168 [ 'Apple_AE::ae-wireless-clients-leaf' ] );
172 # PROG: Adding global statistics
173 $cb->addTemplateApplication( $devNode, 'Apple_AE::ae-global-stats');
175 return;
181 # Local Variables:
182 # mode: perl
183 # indent-tabs-mode: nil
184 # perl-indent-level: 4
185 # End: