torrus, RT#10574
[freeside.git] / torrus / perllib / Torrus / DevDiscover / RFC2662_ADSL_LINE.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: RFC2662_ADSL_LINE.pm,v 1.1 2010-12-27 00:03:53 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # ADSL Line statistics.
21
22 # We assume that adslAturPhysTable is always present when adslAtucPhysTable
23 # is there. Probably that's wrong, and needs to be redesigned.
24
25 package Torrus::DevDiscover::RFC2662_ADSL_LINE;
26
27 use strict;
28 use Torrus::Log;
29
30
31 $Torrus::DevDiscover::registry{'RFC2662_ADSL_LINE'} = {
32     'sequence'     => 100,
33     'checkdevtype' => \&checkdevtype,
34     'discover'     => \&discover,
35     'buildConfig'  => \&buildConfig
36     };
37
38
39 our %oiddef =
40     (
41      # ADSL-LINE-MIB
42      'adslAtucPhysTable'  => '1.3.6.1.2.1.10.94.1.1.2',
43      'adslAtucCurrSnrMgn' => '1.3.6.1.2.1.10.94.1.1.2.1.4',
44      'adslAturPhysTable' => '1.3.6.1.2.1.10.94.1.1.3'
45      );
46
47
48
49 sub checkdevtype
50 {
51     my $dd = shift;
52     my $devdetails = shift;
53
54     my $session = $dd->session();
55     my $data = $devdetails->data();
56
57     my $atucTable =
58         $session->get_table( -baseoid => $dd->oiddef('adslAtucPhysTable') );
59     if( not defined $atucTable )
60     {
61         return 0;
62     }
63     $devdetails->storeSnmpVars( $atucTable );
64
65     ## Do we need to check adslAtucPhysTable ? ##
66
67     return 1;
68 }
69
70
71 sub discover
72 {
73     my $dd = shift;
74     my $devdetails = shift;
75
76     my $data = $devdetails->data();
77
78     $data->{'adslAtucPhysTable'} = [];
79
80     foreach my $ifIndex ( keys %{$data->{'interfaces'}} )
81     {
82         if( $devdetails->hasOID( $dd->oiddef('adslAtucCurrSnrMgn') .
83                                  '.' . $ifIndex ) )
84         {
85             push( @{$data->{'adslAtucPhysTable'}}, $ifIndex );
86         }
87     }
88
89     return 1;
90 }
91
92
93 sub buildConfig
94 {
95     my $devdetails = shift;
96     my $cb = shift;
97     my $devNode = shift;
98
99     # Build SNR subtree
100     my $subtreeName = 'ADSL_Line_Stats';
101
102     my $param = {
103         'precedence'         => '-600',
104         'comment'            => 'ADSL line statistics'
105         };
106     my $subtreeNode = $cb->addSubtree( $devNode, $subtreeName, $param );
107
108     my $data = $devdetails->data();
109
110     foreach my $ifIndex ( sort {$a<=>$b} @{$data->{'adslAtucPhysTable'}} )
111     {
112         my $interface = $data->{'interfaces'}{$ifIndex};
113
114         my $ifSubtreeName = $interface->{$data->{'nameref'}{'ifSubtreeName'}};
115
116         my $templates = ['RFC2662_ADSL_LINE::adsl-line-interface'];
117
118         my $param = {
119             'interface-name' => $interface->{'param'}{'interface-name'},
120             'interface-nick' => $interface->{'param'}{'interface-nick'},
121             'collector-timeoffset-hashstring' =>'%system-id%:%interface-nick%',
122             'comment'        => $interface->{'param'}{'comment'}
123         };
124         
125         $param->{'node-display-name'} =
126             $interface->{$data->{'nameref'}{'ifReferenceName'}};
127         
128         $cb->addSubtree( $subtreeNode, $ifSubtreeName, $param, $templates );
129     }
130 }
131
132
133 1;
134
135
136 # Local Variables:
137 # mode: perl
138 # indent-tabs-mode: nil
139 # perl-indent-level: 4
140 # End: