import torrus 1.0.9
[freeside.git] / torrus / perllib / Torrus / DevDiscover / Apple_AE.pm
1 #
2 #  Copyright (C) 2007  Jon Nistor
3 #
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.
8 #
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.
13 #
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.
17
18 # $Id: Apple_AE.pm,v 1.1 2010-12-27 00:03:55 ivan Exp $
19 # Jon Nistor <nistor at snickers.org>
20
21 # Apple Airport Extreme Discovery Module
22 #
23 # NOTE: Options for this module:
24 #       Apple_AE::disable-clients
25
26 package Torrus::DevDiscover::Apple_AE;
27
28 use strict;
29 use Torrus::Log;
30
31
32 $Torrus::DevDiscover::registry{'Apple_AE'} = {
33     'sequence'     => 500,
34     'checkdevtype' => \&checkdevtype,
35     'discover'     => \&discover,
36     'buildConfig'  => \&buildConfig
37 };
38
39
40 our %oiddef =
41     (
42      # Apple Airport Extreme
43      'airportObject'        => '1.3.6.1.4.1.63.501',
44      'baseStation3'         => '1.3.6.1.4.1.63.501.3',
45
46      # Airport Information
47      'sysConfName'            => '1.3.6.1.4.1.63.501.3.1.1.0',
48      'sysConfContact'         => '1.3.6.1.4.1.63.501.3.1.2.0',
49      'sysConfLocation'        => '1.3.6.1.4.1.63.501.3.1.3.0',
50      'sysConfFirmwareVersion' => '1.3.6.1.4.1.63.501.3.1.5.0',
51
52      'wirelessNumber'         => '1.3.6.1.4.1.63.501.3.2.1.0',
53      'wirelessPhysAddress'    => '1.3.6.1.4.1.63.501.3.2.2.1.1'
54     );
55
56
57 sub checkdevtype
58 {
59     my $dd = shift;
60     my $devdetails = shift;
61
62     # PROG: Standard sysObject does not work on Airport devices
63     #       So we will match on the specific OID
64     if( not $dd->checkSnmpOID('sysConfName') )
65     {
66         return 0;
67     }
68
69     $devdetails->setCap('interfaceIndexingPersistent');
70
71     return 1;
72 }
73
74
75 sub discover
76 {
77     my $dd = shift;
78     my $devdetails = shift;
79
80     my $session = $dd->session();
81     my $data = $devdetails->data();
82
83     # NOTE: Comments and Serial number of device
84     my $chassisInfo =
85         $dd->retrieveSnmpOIDs( 'sysConfName', 'sysConfLocation',
86                                'sysConfFirmwareVersion' );
87
88     if( defined( $chassisInfo ) )
89     {
90         if( not $chassisInfo->{'sysConfLocation'} )
91         {
92             $chassisInfo->{'sysConfLocation'} = "unknown";
93         }
94
95         $data->{'param'}{'comment'} = "Apple Airport Extreme, " .
96             "Fw#: " . $chassisInfo->{'sysConfFirmwareVersion'} . ", " .
97             $chassisInfo->{'sysConfName'} . " located at " .
98             $chassisInfo->{'sysConfLocation'};
99     } else {
100         $data->{'param'}{'comment'} = "Apple Airport Extreme";
101     }
102
103
104     # PROG: Find wireless clients
105     if( $devdetails->param('Apple_AE::disable-clients') ne 'yes' )
106     {
107         my $numWireless = $dd->retrieveSnmpOIDs('wirelessNumber');
108
109         my $tableClients =
110             $session->get_table( -baseoid =>
111                                  $dd->oiddef('wirelessPhysAddress') );
112         $devdetails->storeSnmpVars( $tableClients );
113
114         if( $tableClients && ($numWireless->{'wirelessNumber'} > 0) )
115         {
116             # PROG: setCap that we actually have clients ...
117             $devdetails->setCap('AE_clients');
118
119             foreach my $wClient ( $devdetails->getSnmpIndices
120                                   ($dd->oiddef('wirelessPhysAddress')) )
121             {
122                 my $wMAC = $devdetails->snmpVar(
123                     $dd->oiddef('wirelessPhysAddress') . "." . $wClient);
124
125                 # Construct data
126                 $data->{'Apple_AE'}{'wClients'}{$wClient} = undef;
127                 $data->{'Apple_AE'}{'wClients'}{$wClient}{'wMAC'} = $wMAC;
128
129                 Debug("Apple_AE::  Client $wMAC / $wClient");
130             }
131         } 
132     }
133
134     return 1;
135 }
136
137
138 sub buildConfig
139 {
140     my $devdetails = shift;
141     my $cb = shift;
142     my $devNode = shift;
143     my $data = $devdetails->data();
144
145
146     # Wireless Client information
147     if( $devdetails->hasCap('AE_clients') )
148     {
149         my $nodeTop =
150             $cb->addSubtree( $devNode, 'Wireless_Clients', undef,
151                              [ 'Apple_AE::ae-wireless-clients-subtree'] );
152
153         foreach my $wClient ( keys %{$data->{'Apple_AE'}{'wClients'}} )
154         {
155             my $airport = $data->{'Apple_AE'}{'wClients'}{$wClient};
156             my $wMAC    = $airport->{'wMAC'};
157             my $wMACfix = $wMAC;
158             $wMACfix =~ s/:/_/g;
159
160             my $nodeWireless =
161                 $cb->addSubtree( $nodeTop, $wMACfix,
162                                  { 'wireless-mac'    => $wMAC,
163                                    'wireless-macFix' => $wMACfix,
164                                    'wireless-macOid' => $wClient },
165                                  [ 'Apple_AE::ae-wireless-clients-leaf' ] );
166         }
167     }
168
169     # PROG: Adding global statistics
170     $cb->addTemplateApplication( $devNode, 'Apple_AE::ae-global-stats');
171 }
172
173
174 1;
175
176 # Local Variables:
177 # mode: perl
178 # indent-tabs-mode: nil
179 # perl-indent-level: 4
180 # End: