per-agent configuration of batch processors, #71837
[freeside.git] / torrus / perllib / Torrus / DevDiscover / AlliedTelesyn_PBC18.pm
1 #  Copyright (C) 2004 Marc Haber
2 #  Copyright (C) 2005 Stanislav Sinyagin
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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 # $Id: AlliedTelesyn_PBC18.pm,v 1.1 2010-12-27 00:03:49 ivan Exp $
19 # Marc Haber <mh+torrus-devel@zugschlus.de>
20 # Redesigned by Stanislav Sinyagin
21
22 # Allied Telesyn 18-Slot Media Converter Chassis
23
24 package Torrus::DevDiscover::AlliedTelesyn_PBC18;
25
26 use strict;
27 use Torrus::Log;
28
29
30 $Torrus::DevDiscover::registry{'AlliedTelesyn_PBC18'} = {
31     'sequence'     => 500,
32     'checkdevtype' => \&checkdevtype,
33     'discover'     => \&discover,
34     'buildConfig'  => \&buildConfig
35     };
36
37
38 our %oiddef =
39     (
40      'ATMCCommon-MIB::mediaconverter'    => '1.3.6.1.4.1.207.1.12',
41      'ATMCCommon-MIB::mcModuleName'      => '1.3.6.1.4.1.207.8.41.1.1.1.1.1.2',
42      'ATMCCommon-MIB::mcModuleType'      => '1.3.6.1.4.1.207.8.41.1.1.1.1.1.3',
43      'ATMCCommon-MIB::mcModuleState'     => '1.3.6.1.4.1.207.8.41.1.1.1.1.1.4',
44      'ATMCCommon-MIB::mcModuleAportLinkState' =>
45      '1.3.6.1.4.1.207.8.41.1.1.1.1.1.10',
46      'ATMCCommon-MIB::mcModuleBportLinkState' =>
47      '1.3.6.1.4.1.207.8.41.1.1.1.1.1.11',
48      'ATMCCommon-MIB::mcModuleCportLinkState' =>
49      '1.3.6.1.4.1.207.8.41.1.1.1.1.1.12',
50      'ATMCCommon-MIB::mcModuleDportLinkState' =>
51      '1.3.6.1.4.1.207.8.41.1.1.1.1.1.13',
52      
53      );
54
55
56 our %knownModuleTypes =
57     (
58      8 => 'AT-PB103/1 (1x100Base-TX, 1x100Base-FX Single-Mode Fibre SC, 15km)',
59      );
60
61
62 sub checkdevtype
63 {
64     my $dd = shift;
65     my $devdetails = shift;
66
67     if( not $dd->oidBaseMatch
68         ( 'ATMCCommon-MIB::mediaconverter',
69           $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) )
70     {
71         return 0;
72     }
73     
74     return 1;
75 }
76
77
78 sub discover
79 {
80     my $dd = shift;
81     my $devdetails = shift;
82
83     my $data = $devdetails->data();
84     my $session = $dd->session();
85     
86     # Modules table
87
88     my $oid = $dd->oiddef('ATMCCommon-MIB::mcModuleType');
89     
90     my $table = $session->get_table( -baseoid => $oid );    
91     if( not defined( $table ) )
92     {
93         return 0;
94     }
95     
96     $devdetails->storeSnmpVars( $table );
97     
98     foreach my $INDEX ( $devdetails->getSnmpIndices($oid) )
99     {
100         my $moduleType = $devdetails->snmpVar( $oid . '.' . $INDEX );
101         if( $moduleType == 0 )
102         {
103             next;
104         }
105
106         $data->{'PBC18'}{$INDEX} = {};
107         if( defined( $knownModuleTypes{$moduleType} ) )
108         {
109             $data->{'PBC18'}{$INDEX}{'moduleDesc'} =
110                 $knownModuleTypes{$moduleType};
111         }
112         else
113         {
114             Warn('Unknown PBC18 module type: ' . $moduleType);
115         }
116     }
117
118     foreach my $INDEX ( keys %{$data->{'PBC18'}} )
119     {
120         my $oids = [];
121         foreach my $oidname ( 'ATMCCommon-MIB::mcModuleName',
122                               'ATMCCommon-MIB::mcModuleState',
123                               'ATMCCommon-MIB::mcModuleAportLinkState',
124                               'ATMCCommon-MIB::mcModuleBportLinkState',
125                               'ATMCCommon-MIB::mcModuleCportLinkState',
126                               'ATMCCommon-MIB::mcModuleDportLinkState' )
127         {
128             push( @{$oids}, $dd->oiddef( $oidname ) . '.' . $INDEX );
129         }
130     
131         my $result = $session->get_request( -varbindlist => $oids );
132         if( $session->error_status() == 0 and defined( $result ) )
133         {
134             $devdetails->storeSnmpVars( $result );
135         }
136         else
137         {
138             Error('Error retrieving PBC18 module information');
139             return 0;
140         }
141     }
142
143     foreach my $INDEX ( keys %{$data->{'PBC18'}} )
144     {
145         if( $devdetails->snmpVar
146             ( $dd->oiddef('ATMCCommon-MIB::mcModuleState') .'.'.$INDEX )
147             != 1 )
148         {
149             delete $data->{'PBC18'}{$INDEX};
150             next;
151         }
152
153         my $name = $devdetails->snmpVar
154             ( $dd->oiddef('ATMCCommon-MIB::mcModuleName') .'.'.$INDEX );
155
156         if( length( $name ) > 0 )
157         {
158             $data->{'PBC18'}{$INDEX}{'moduleName'} = $name;
159         }
160
161         foreach my $portName ('A', 'B', 'C', 'D')
162         {
163             my $oid = $dd->oiddef
164                 ('ATMCCommon-MIB::mcModule'.$portName.'portLinkState').
165                 '.'.$INDEX;
166             
167             my $portState = $devdetails->snmpVar ( $oid );
168             if( $portState == 1 or $portState == 2 )
169             {
170                 $data->{'PBC18'}{$INDEX}{'portAvailable'}{$portName} = $oid;
171             }
172         }        
173     }
174
175     return 1;
176 }           
177
178
179 our %portLineColors =
180     (
181      'A' => '##green',
182      'B' => '##blue',
183      'C' => '##red',
184      'D' => '##gold'
185      );
186
187
188 sub buildConfig
189 {
190     my $devdetails = shift;
191     my $cb = shift;
192     my $devNode = shift;
193
194     my $data = $devdetails->data();
195
196     my $param = {
197         'data-file' => '%system-id%_pbc18_%pbc-module-index%.rrd',
198         'collector-scale' => '-1,*,2,+',
199         'graph-lower-limit' => 0,
200         'graph-upper-limit' => 1,
201         'rrd-cf' => 'MAX',
202         'rrd-create-dstype' => 'GAUGE',
203         'rrd-create-rra' =>
204             'RRA:MAX:0:1:4032 RRA:MAX:0.17:6:2016 RRA:MAX:0.042:288:732',
205
206             'has-overview-shortcuts' => 'yes',
207             'overview-shortcuts' => 'links',
208             'overview-subleave-name-links' => 'AllPorts',
209             'overview-shortcut-text-links' => 'All modules',
210             'overview-shortcut-title-links' => 'All converter modules',
211             'overview-page-title-links' => 'All converter modules',            
212         };
213
214     $cb->addParams( $devNode, $param );
215         
216     foreach my $INDEX ( sort {$a<=>$b} keys %{$data->{'PBC18'}} )
217     {
218         my $param = { 'pbc-module-index' => $INDEX };
219         
220         if( defined( $data->{'PBC18'}{$INDEX}{'moduleDesc'} ) )
221         {
222             $param->{'legend'} =
223                 'Module type: ' . $data->{'PBC18'}{$INDEX}{'moduleDesc'};
224         }
225
226         if( defined( $data->{'PBC18'}{$INDEX}{'moduleName'} ) )
227         {
228             $param->{'comment'} =
229                 $data->{'PBC18'}{$INDEX}{'moduleName'};
230         }
231         
232         my $modNode = $cb->addSubtree( $devNode, 'Module_' . $INDEX, $param );
233
234         my $mgParam = {
235             'ds-type'              => 'rrd-multigraph',
236             'ds-names'             => '',
237             'graph-lower-limit'    => '0',
238             'precedence'           => '1000',
239             'comment'              => 'Ports status',                
240             'vertical-label'       => 'Status',                
241         };
242         
243         my $n = 1;
244         foreach my $portName
245             ( sort keys %{$data->{'PBC18'}{$INDEX}{'portAvailable'}} )
246         {
247             if( $n > 1 )
248             {
249                 $mgParam->{'ds-names'} .= ',';
250             }
251
252             my $dsname = 'port' . $portName;
253             $mgParam->{'ds-names'} .= $dsname;
254
255             $mgParam->{'graph-legend-' . $dsname} = 'Port ' . $portName;
256             $mgParam->{'line-style-' . $dsname} = 'LINE2';
257             $mgParam->{'line-color-' . $dsname} = $portLineColors{$portName};
258             $mgParam->{'line-order-' . $dsname} = $n;
259             $mgParam->{'ds-expr-' . $dsname} = '{Port_' . $portName . '}';
260             
261             my $param = {
262                 'rrd-ds' => 'Port' . $portName,
263                 'snmp-object' =>
264                     $data->{'PBC18'}{$INDEX}{'portAvailable'}{$portName},
265                 };
266
267             $cb->addLeaf( $modNode, 'Port_' . $portName, $param );
268             $n++;
269         }
270
271         $cb->addLeaf( $modNode, 'AllPorts', $mgParam );        
272     }
273 }
274
275
276
277 1;
278
279
280 # Local Variables:
281 # mode: perl
282 # indent-tabs-mode: nil
283 # perl-indent-level: 4
284 # End: