Merge remote-tracking branch 'upstream/master'
[torrus-plus.git] / src / lib / Torrus / DevDiscover / AlliedTelesyn_PBC18.pm
blob376a78ae75884dc7c45f10ffe67c4e54fc6bf329
1 # Copyright (C) 2004 Marc Haber
2 # Copyright (C) 2005 Stanislav Sinyagin
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., 675 Mass Ave, Cambridge, MA 02139, USA.
18 # $Id$
19 # Marc Haber <mh+torrus-devel@zugschlus.de>
20 # Redesigned by Stanislav Sinyagin
22 # Allied Telesyn 18-Slot Media Converter Chassis
24 package Torrus::DevDiscover::AlliedTelesyn_PBC18;
26 use strict;
27 use warnings;
29 use Torrus::Log;
31 our $VERSION = 1.0;
34 $Torrus::DevDiscover::registry{'AlliedTelesyn_PBC18'} = {
35 'sequence' => 500,
36 'checkdevtype' => \&checkdevtype,
37 'discover' => \&discover,
38 'buildConfig' => \&buildConfig
42 our %oiddef =
44 'ATMCCommon-MIB::mediaconverter' => '1.3.6.1.4.1.207.1.12',
45 'ATMCCommon-MIB::mcModuleName' => '1.3.6.1.4.1.207.8.41.1.1.1.1.1.2',
46 'ATMCCommon-MIB::mcModuleType' => '1.3.6.1.4.1.207.8.41.1.1.1.1.1.3',
47 'ATMCCommon-MIB::mcModuleState' => '1.3.6.1.4.1.207.8.41.1.1.1.1.1.4',
48 'ATMCCommon-MIB::mcModuleAportLinkState' =>
49 '1.3.6.1.4.1.207.8.41.1.1.1.1.1.10',
50 'ATMCCommon-MIB::mcModuleBportLinkState' =>
51 '1.3.6.1.4.1.207.8.41.1.1.1.1.1.11',
52 'ATMCCommon-MIB::mcModuleCportLinkState' =>
53 '1.3.6.1.4.1.207.8.41.1.1.1.1.1.12',
54 'ATMCCommon-MIB::mcModuleDportLinkState' =>
55 '1.3.6.1.4.1.207.8.41.1.1.1.1.1.13',
60 our %knownModuleTypes =
62 8 => 'AT-PB103/1 (1x100Base-TX, 1x100Base-FX Single-Mode Fibre SC, 15km)',
66 sub checkdevtype
68 my $dd = shift;
69 my $devdetails = shift;
71 if( not $dd->oidBaseMatch
72 ( 'ATMCCommon-MIB::mediaconverter',
73 $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) )
75 return 0;
78 return 1;
82 sub discover
84 my $dd = shift;
85 my $devdetails = shift;
87 my $data = $devdetails->data();
88 my $session = $dd->session();
90 # Modules table
92 my $base = $dd->oiddef('ATMCCommon-MIB::mcModuleType');
94 my $table = $session->get_table( -baseoid => $base );
95 if( not defined( $table ) )
97 return 0;
100 $devdetails->storeSnmpVars( $table );
102 for my $INDEX ( $devdetails->getSnmpIndices($base) )
104 my $moduleType = $devdetails->snmpVar( $base . '.' . $INDEX );
105 if( $moduleType == 0 )
107 next;
110 $data->{'PBC18'}{$INDEX} = {};
111 if( defined( $knownModuleTypes{$moduleType} ) )
113 $data->{'PBC18'}{$INDEX}{'moduleDesc'} =
114 $knownModuleTypes{$moduleType};
116 else
118 Warn('Unknown PBC18 module type: ' . $moduleType);
122 for my $INDEX ( keys %{$data->{'PBC18'}} )
124 my $oids = [];
125 for my $oidname ( 'ATMCCommon-MIB::mcModuleName',
126 'ATMCCommon-MIB::mcModuleState',
127 'ATMCCommon-MIB::mcModuleAportLinkState',
128 'ATMCCommon-MIB::mcModuleBportLinkState',
129 'ATMCCommon-MIB::mcModuleCportLinkState',
130 'ATMCCommon-MIB::mcModuleDportLinkState' )
132 push( @{$oids}, $dd->oiddef( $oidname ) . '.' . $INDEX );
135 my $result = $session->get_request( -varbindlist => $oids );
136 if( $session->error_status() == 0 and defined( $result ) )
138 $devdetails->storeSnmpVars( $result );
140 else
142 Error('Error retrieving PBC18 module information');
143 return 0;
147 for my $INDEX ( keys %{$data->{'PBC18'}} )
149 if( $devdetails->snmpVar
150 ( $dd->oiddef('ATMCCommon-MIB::mcModuleState') .'.'.$INDEX )
151 != 1 )
153 delete $data->{'PBC18'}{$INDEX};
154 next;
157 my $name = $devdetails->snmpVar
158 ( $dd->oiddef('ATMCCommon-MIB::mcModuleName') .'.'.$INDEX );
160 if( defined($name) and $name ne '' )
162 $data->{'PBC18'}{$INDEX}{'moduleName'} = $name;
165 for my $portName ('A', 'B', 'C', 'D')
167 my $oid = $dd->oiddef
168 ('ATMCCommon-MIB::mcModule'.$portName.'portLinkState').
169 '.'.$INDEX;
171 my $portState = $devdetails->snmpVar ( $oid );
172 if( $portState == 1 or $portState == 2 )
174 $data->{'PBC18'}{$INDEX}{'portAvailable'}{$portName} = $oid;
179 return 1;
183 our %portLineColors =
185 'A' => '##green',
186 'B' => '##blue',
187 'C' => '##red',
188 'D' => '##gold'
192 sub buildConfig
194 my $devdetails = shift;
195 my $cb = shift;
196 my $devNode = shift;
198 my $data = $devdetails->data();
200 my $param = {
201 'data-file' => '%system-id%_pbc18_%pbc-module-index%.rrd',
202 'collector-scale' => '-1,*,2,+',
203 'graph-lower-limit' => 0,
204 'graph-upper-limit' => 1,
205 'rrd-cf' => 'MAX',
206 'rrd-create-dstype' => 'GAUGE',
207 'rrd-create-rra' =>
208 'RRA:MAX:0:1:4032 RRA:MAX:0.17:6:2016 RRA:MAX:0.042:288:732',
210 'has-overview-shortcuts' => 'yes',
211 'overview-shortcuts' => 'links',
212 'overview-subleave-name-links' => 'AllPorts',
213 'overview-shortcut-text-links' => 'All modules',
214 'overview-shortcut-title-links' => 'All converter modules',
215 'overview-page-title-links' => 'All converter modules',
218 $cb->addParams( $devNode, $param );
220 for my $INDEX ( sort {$a<=>$b} keys %{$data->{'PBC18'}} )
222 my $modParam = { 'pbc-module-index' => $INDEX };
224 if( defined( $data->{'PBC18'}{$INDEX}{'moduleDesc'} ) )
226 $modParam->{'legend'} =
227 'Module type: ' . $data->{'PBC18'}{$INDEX}{'moduleDesc'};
230 if( defined( $data->{'PBC18'}{$INDEX}{'moduleName'} ) )
232 $modParam->{'comment'} =
233 $data->{'PBC18'}{$INDEX}{'moduleName'};
236 my $modNode =
237 $cb->addSubtree( $devNode, 'Module_' . $INDEX, $modParam );
239 my $mgParam = {
240 'ds-type' => 'rrd-multigraph',
241 'ds-names' => '',
242 'graph-lower-limit' => '0',
243 'precedence' => '1000',
244 'comment' => 'Ports status',
245 'vertical-label' => 'Status',
248 my $n = 1;
249 for my $portName
250 ( sort keys %{$data->{'PBC18'}{$INDEX}{'portAvailable'}} )
252 if( $n > 1 )
254 $mgParam->{'ds-names'} .= ',';
257 my $dsname = 'port' . $portName;
258 $mgParam->{'ds-names'} .= $dsname;
260 $mgParam->{'graph-legend-' . $dsname} = 'Port ' . $portName;
261 $mgParam->{'line-style-' . $dsname} = 'LINE2';
262 $mgParam->{'line-color-' . $dsname} = $portLineColors{$portName};
263 $mgParam->{'line-order-' . $dsname} = $n;
264 $mgParam->{'ds-expr-' . $dsname} = '{Port_' . $portName . '}';
266 my $portParam = {
267 'rrd-ds' => 'Port' . $portName,
268 'snmp-object' =>
269 $data->{'PBC18'}{$INDEX}{'portAvailable'}{$portName},
272 $cb->addLeaf( $modNode, 'Port_' . $portName, $portParam );
273 $n++;
276 $cb->addLeaf( $modNode, 'AllPorts', $mgParam );
278 return;
286 # Local Variables:
287 # mode: perl
288 # indent-tabs-mode: nil
289 # perl-indent-level: 4
290 # End: