default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / torrus / perllib / Torrus / DevDiscover / AscendMax.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: AscendMax.pm,v 1.1 2010-12-27 00:03:53 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # Ascend (Lucent) MAX device discovery.
21
22 # Tested with:
23 #
24 # MAX 4000, TAOS version 7.0.26
25
26 # NOTE: SNMP version 1 is only supported. Because of version 1 and numerous
27 # WAN DS0 interfaces, the discovery process may take few minutes.
28
29 package Torrus::DevDiscover::AscendMax;
30
31 use strict;
32 use Torrus::Log;
33
34
35 $Torrus::DevDiscover::registry{'AscendMax'} = {
36     'sequence'     => 500,
37     'checkdevtype' => \&checkdevtype,
38     'discover'     => \&discover,
39     'buildConfig'  => \&buildConfig
40     };
41
42
43 our %oiddef =
44     (
45      # ASCEND-MIB
46      'ASCEND-MIB::max' => '1.3.6.1.4.1.529.1.2',
47      # ASCEND-ADVANCED-AGENT-MIB
48      'ASCEND-ADVANCED-AGENT-MIB::wanLineTable' =>
49      '1.3.6.1.4.1.529.4.21',
50      'ASCEND-ADVANCED-AGENT-MIB::wanLineState' =>
51      '1.3.6.1.4.1.529.4.21.1.5',
52      'ASCEND-ADVANCED-AGENT-MIB::wanLineActiveChannels' =>
53      '1.3.6.1.4.1.529.4.21.1.7',
54      'ASCEND-ADVANCED-AGENT-MIB::wanLineSwitchedChannels' =>
55      '1.3.6.1.4.1.529.4.21.1.13'
56      );
57
58 # Not all interfaces are normally needed to monitor.
59 # You may override the interface filtering in devdiscover-siteconfig.pl:
60 # redefine $Torrus::DevDiscover::AscendMax::interfaceFilter
61 # or define $Torrus::DevDiscover::AscendMax::interfaceFilterOverlay
62
63 our $interfaceFilter;
64 our $interfaceFilterOverlay;
65 my %ascMaxInterfaceFilter;
66
67 if( not defined( $interfaceFilter ) )
68 {
69     $interfaceFilter = \%ascMaxInterfaceFilter;
70 }
71
72
73 # Key is some unique symbolic name, does not mean anything
74 # ifType is the number to match the interface type
75 # ifDescr is the regexp to match the interface description
76 %ascMaxInterfaceFilter =
77     (
78      'Console' => {
79          'ifType'  => 33                      # rs232
80          },
81      'E1' => {
82          'ifType'  => 19                      # e1
83          },
84      'wan_activeN' => {
85          'ifType'  => 23,                     # ppp
86          'ifDescr'  => '^wan\d+'
87          },
88      'wan_inactiveN' => {
89          'ifType'  => 1,                      # other
90          'ifDescr'  => '^wan\d+'
91          },
92      'wanidleN' => {
93          'ifType'  => 1,                      # other
94          'ifDescr'  => '^wanidle\d+'
95          },
96      'loopbacks' => {
97          'ifType'  => 24                      # softwareLoopback
98          }
99      );
100
101
102 sub checkdevtype
103 {
104     my $dd = shift;
105     my $devdetails = shift;
106
107     if( not $dd->oidBaseMatch
108         ( 'ASCEND-MIB::max',
109           $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) )
110     {
111         return 0;
112     }
113
114     &Torrus::DevDiscover::RFC2863_IF_MIB::addInterfaceFilter
115         ($devdetails, $interfaceFilter);
116
117     if( defined( $interfaceFilterOverlay ) )
118     {
119         &Torrus::DevDiscover::RFC2863_IF_MIB::addInterfaceFilter
120             ($devdetails, $interfaceFilterOverlay);
121     }
122
123     $devdetails->setCap('interfaceIndexingPersistent');
124
125     return 1;
126 }
127
128
129 sub discover
130 {
131     my $dd = shift;
132     my $devdetails = shift;
133
134     my $data = $devdetails->data();
135     my $session = $dd->session();
136
137     my $wanTableOid = $dd->oiddef('ASCEND-ADVANCED-AGENT-MIB::wanLineTable' );
138     my $stateOid =
139         $dd->oiddef('ASCEND-ADVANCED-AGENT-MIB::wanLineState' );
140     my $totalOid =
141         $dd->oiddef('ASCEND-ADVANCED-AGENT-MIB::wanLineSwitchedChannels' );
142
143     my $wanTable =  $session->get_table( -baseoid => $wanTableOid );
144     if( defined( $wanTable ) )
145     {
146         $devdetails->storeSnmpVars( $wanTable );
147         $devdetails->setCap('wanLineTable');
148
149         $data->{'ascend_wanLines'} = {};
150
151         foreach my $ifIndex ( $devdetails->getSnmpIndices( $stateOid ) )
152         {
153             # Check if the line State is 13(active)
154             if( $devdetails->snmpVar( $stateOid . '.' . $ifIndex) == 13 )
155             {
156                 my $descr = $devdetails->snmpVar($dd->oiddef('ifDescr') .
157                                                  '.' . $ifIndex);
158
159                 $data->{'ascend_wanLines'}{$ifIndex}{'description'} = $descr;
160                 $data->{'ascend_wanLines'}{$ifIndex}{'channels'} =
161                     $devdetails->snmpVar( $totalOid . '.' . $ifIndex );
162             }
163         }
164     }
165
166     return 1;
167 }
168
169
170 sub buildConfig
171 {
172     my $devdetails = shift;
173     my $cb = shift;
174     my $devNode = shift;
175
176     my $data = $devdetails->data();
177
178     my $callStatsNode = $cb->addSubtree( $devNode, 'Call_Statistics', undef,
179                                          ['AscendMax::ascend-totalcalls']);
180
181     foreach my $ifIndex ( sort {$a<=>$b} keys %{$data->{'ascend_wanLines'}} )
182     {
183         my $param = {};
184         $param->{'precedence'} = sprintf('%d', -10000 - $ifIndex);
185         $param->{'ascend-ifidx'} = $ifIndex;
186
187         my $nChannels = $data->{'ascend_wanLines'}{$ifIndex}{'channels'};
188         $param->{'upper-limit'} = $nChannels;
189         $param->{'graph-upper-limit'} = $nChannels;
190
191         my $subtreeName = $data->{'ascend_wanLines'}{$ifIndex}{'description'};
192         $subtreeName =~ s/\W/_/g;
193
194         $cb->addLeaf( $callStatsNode, $subtreeName, $param,
195                       ['AscendMax::ascend-line-stats']);
196     }
197 }
198
199
200 1;
201
202
203 # Local Variables:
204 # mode: perl
205 # indent-tabs-mode: nil
206 # perl-indent-level: 4
207 # End: