per-agent configuration of batch processors, #71837
[freeside.git] / torrus / perllib / Torrus / DevDiscover / CiscoVDSL.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: CiscoVDSL.pm,v 1.1 2010-12-27 00:03:53 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # Cisco VDSL Line statistics.
21 # Tested with Catalyst 2950 LRE
22
23 package Torrus::DevDiscover::CiscoVDSL;
24
25 use strict;
26 use Torrus::Log;
27
28
29 $Torrus::DevDiscover::registry{'CiscoVDSL'} = {
30     'sequence'     => 600,
31     'checkdevtype' => \&checkdevtype,
32     'discover'     => \&discover,
33     'buildConfig'  => \&buildConfig
34     };
35
36
37 our %oiddef =
38     (
39      # CISCO-IETF-VDSL-LINE-MIB
40      'cvdslCurrSnrMgn'  => '1.3.6.1.4.1.9.10.87.1.1.2.1.5',
41      );
42
43
44
45 sub checkdevtype
46 {
47     my $dd = shift;
48     my $devdetails = shift;
49
50     my $session = $dd->session();
51     my $data = $devdetails->data();
52
53     if( $devdetails->isDevType('CiscoGeneric') )
54     {
55         my $snrTable =
56             $session->get_table( -baseoid => $dd->oiddef('cvdslCurrSnrMgn') );
57         if( defined $snrTable )
58         {
59             $devdetails->storeSnmpVars( $snrTable );
60             return 1;
61         }
62     }
63
64     return 0;
65 }
66
67
68 sub discover
69 {
70     my $dd = shift;
71     my $devdetails = shift;
72
73     my $data = $devdetails->data();
74
75     $data->{'cvdsl'} = [];
76
77     foreach my $ifIndex ( keys %{$data->{'interfaces'}} )
78     {
79         my $oid = $dd->oiddef('cvdslCurrSnrMgn') . '.' . $ifIndex;
80         if( $devdetails->hasOID( $oid . '.1' ) and
81             $devdetails->hasOID( $oid . '.2' ) )
82         {
83             push( @{$data->{'cvdsl'}}, $ifIndex );
84         }
85     }
86
87     return 1;
88 }
89
90
91 sub buildConfig
92 {
93     my $devdetails = shift;
94     my $cb = shift;
95     my $devNode = shift;
96
97     my $subtreeName = 'VDSL_Line_Stats';
98
99     my $subtreeNode = $cb->addSubtree( $devNode, $subtreeName, {},
100                                        ['CiscoVDSL::cvdsl-subtree']);
101
102     my $data = $devdetails->data();
103
104     foreach my $ifIndex ( sort {$a<=>$b} @{$data->{'cvdsl'}} )
105     {
106         my $interface = $data->{'interfaces'}{$ifIndex};
107
108         my $ifSubtreeName = $interface->{$data->{'nameref'}{'ifSubtreeName'}};
109
110         my $templates = ['CiscoVDSL::cvdsl-interface'];
111
112         my $param = {
113             'interface-name' => $interface->{'param'}{'interface-name'},
114             'interface-nick' => $interface->{'param'}{'interface-nick'},
115             'comment'        => $interface->{'param'}{'comment'}
116         };
117
118         $cb->addSubtree( $subtreeNode, $ifSubtreeName, $param, $templates );
119     }
120 }
121
122
123 1;
124
125
126 # Local Variables:
127 # mode: perl
128 # indent-tabs-mode: nil
129 # perl-indent-level: 4
130 # End: