per-agent configuration of batch processors, #71837
[freeside.git] / torrus / perllib / Torrus / DevDiscover / Xylan.pm
1 #  Copyright (C) 2002  Stanislav Sinyagin
2 #
3 #  This program is free software; you can redistribute it and/or modify
4 #  it under the terms of the GNU General Public License as published by
5 #  the Free Software Foundation; either version 2 of the License, or
6 #  (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software
15 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16
17 # $Id: Xylan.pm,v 1.1 2010-12-27 00:03:50 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # Xylan (Alcatel) switch discovery.
21
22 # Tested with:
23 #
24 # Xylan OmniSwitch 9x
25 # Xylan OmniStack 5024
26 # Switch software: X/OS 4.3.3
27 #
28 # Virtual ports are not processed yet
29
30
31 package Torrus::DevDiscover::Xylan;
32
33 use strict;
34 use Torrus::Log;
35
36
37 $Torrus::DevDiscover::registry{'Xylan'} = {
38     'sequence'     => 500,
39     'checkdevtype' => \&checkdevtype,
40     'discover'     => \&discover,
41     'buildConfig'  => \&buildConfig
42     };
43
44
45 our %oiddef =
46     (
47      # XYLAN-BASE-MIB
48      'xylanSwitchDevice'           => '1.3.6.1.4.1.800.3.1.1',
49      # PORT-MIB::phyPortTable
50      'xylanPhyPortTable'           => '1.3.6.1.4.1.800.2.3.3.1',
51      # PORT-MIB::phyPortDescription
52      'xylanPhyPortDescription'     => '1.3.6.1.4.1.800.2.3.3.1.1.4',
53      # PORT-MIB::phyPortToInterface
54      'xylanPhyPortToInterface'     => '1.3.6.1.4.1.800.2.3.3.1.1.19'
55      );
56
57 # Not all interfaces are normally needed to monitor.
58 # You may override the interface filtering in devdiscover-siteconfig.pl:
59 # redefine $Torrus::DevDiscover::Xylan::interfaceFilter
60 # or define $Torrus::DevDiscover::Xylan::interfaceFilterOverlay
61
62 our $interfaceFilter;
63 our $interfaceFilterOverlay;
64 my %xylInterfaceFilter;
65
66 if( not defined( $interfaceFilter ) )
67 {
68     $interfaceFilter = \%xylInterfaceFilter;
69 }
70
71
72 # Key is some unique symbolic name, does not mean anything
73 # ifType is the number to match the interface type
74 # ifDescr is the regexp to match the interface description
75 %xylInterfaceFilter =
76     (
77      'vnN' => {
78          'ifType'  => 53                     # propVirtual
79          },
80      'loN' => {
81          'ifType'  => 24                     # softwareLoopback
82          }
83      );
84
85 sub checkdevtype
86 {
87     my $dd = shift;
88     my $devdetails = shift;
89
90     if( not $dd->oidBaseMatch
91         ( 'xylanSwitchDevice',
92           $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) )
93     {
94         return 0;
95     }
96
97     &Torrus::DevDiscover::RFC2863_IF_MIB::addInterfaceFilter
98         ($devdetails, $interfaceFilter);
99
100     if( defined( $interfaceFilterOverlay ) )
101     {
102         &Torrus::DevDiscover::RFC2863_IF_MIB::addInterfaceFilter
103             ($devdetails, $interfaceFilterOverlay);
104     }
105
106     $devdetails->setCap('interfaceIndexingPersistent');
107
108     return 1;
109 }
110
111
112 sub discover
113 {
114     my $dd = shift;
115     my $devdetails = shift;
116
117     my $data = $devdetails->data();
118     my $session = $dd->session();
119
120     $data->{'nameref'}{'ifNick'}        = 'xylanInterfaceNick';
121     $data->{'nameref'}{'ifSubtreeName'} = 'xylanInterfaceNick';
122     $data->{'nameref'}{'ifComment'}     = 'xylanInterfaceComment';
123     $data->{'nameref'}{'ifReferenceName'}   = 'xylanInterfaceHumanName';
124     
125     my $phyPortTable =
126         $session->get_table( -baseoid => $dd->oiddef('xylanPhyPortTable') );
127
128     if( not defined $phyPortTable )
129     {
130         Error('Error retrieving PORT-MIB::phyPortTable from Xylan device');
131         return 0;
132     }
133
134     $devdetails->storeSnmpVars( $phyPortTable );
135
136     foreach my $slotDotPort
137         ( $devdetails->
138           getSnmpIndices( $dd->oiddef('xylanPhyPortDescription') ) )
139     {
140         my ( $slot, $port ) = split( '\.', $slotDotPort );
141
142         my $ifIndex =
143             $devdetails->snmpVar($dd->oiddef('xylanPhyPortToInterface') .
144                                  '.' . $slotDotPort);
145         my $interface = $data->{'interfaces'}{$ifIndex};
146
147         if( defined $interface )
148         {
149             $interface->{'xylanInterfaceNick'} =
150                 sprintf( '%d_%d', $slot, $port );
151
152             $interface->{'xylanInterfaceHumanName'} =
153                 sprintf( '%d/%d', $slot, $port );
154
155             $interface->{'xylanInterfaceComment'} =
156                 $devdetails->snmpVar($dd->oiddef('xylanPhyPortDescription') .
157                                      '.' . $slotDotPort);
158         }
159     }
160
161     # verify if all interfaces are processed
162
163     foreach my $ifIndex ( keys %{$data->{'interfaces'}} )
164     {
165         my $interface = $data->{'interfaces'}{$ifIndex};
166
167         if( not defined( $interface->{'xylanInterfaceNick'} ) )
168         {
169             Warn('Interface ' . $ifIndex . ' is not in phyPortTable');
170
171             my $nick = sprintf( 'PORT%d', $ifIndex );
172             $interface->{'xylanInterfaceNick'} = $nick;
173             $interface->{'xylanInterfaceHumanName'} = $nick;
174
175             $interface->{'xylanInterfaceComment'} = $interface->{'ifDescr'};
176         }
177     }
178
179     return 1;
180 }
181
182
183 sub buildConfig
184 {
185     my $devdetails = shift;
186     my $cb = shift;
187     my $devNode = shift;
188
189 }
190
191
192 1;
193
194
195 # Local Variables:
196 # mode: perl
197 # indent-tabs-mode: nil
198 # perl-indent-level: 4
199 # End: