import torrus 1.0.9
[freeside.git] / torrus / perllib / Torrus / DevDiscover / CiscoIOS_SAA.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: CiscoIOS_SAA.pm,v 1.1 2010-12-27 00:03:50 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # Cisco IOS Service Assurance Agent
21 # TODO:
22 #   should really consider rtt-type and rtt-echo-protocol when applying
23 #   per-rtt templates
24 #
25 #   translate TOS bits into DSCP values
26
27 package Torrus::DevDiscover::CiscoIOS_SAA;
28
29 use strict;
30 use Socket qw(inet_ntoa);
31
32 use Torrus::Log;
33
34
35 $Torrus::DevDiscover::registry{'CiscoIOS_SAA'} = {
36     'sequence'     => 510,
37     'checkdevtype' => \&checkdevtype,
38     'discover'     => \&discover,
39     'buildConfig'  => \&buildConfig
40     };
41
42
43 our %oiddef =
44     (
45      # CISCO-RTTMON-MIB
46      'rttMonCtrlAdminTable'               => '1.3.6.1.4.1.9.9.42.1.2.1',
47      'rttMonCtrlAdminOwner'               => '1.3.6.1.4.1.9.9.42.1.2.1.1.2',
48      'rttMonCtrlAdminTag'                 => '1.3.6.1.4.1.9.9.42.1.2.1.1.3',
49      'rttMonCtrlAdminRttType'             => '1.3.6.1.4.1.9.9.42.1.2.1.1.4',
50      'rttMonCtrlAdminFrequency'           => '1.3.6.1.4.1.9.9.42.1.2.1.1.6',
51      'rttMonCtrlAdminStatus'              => '1.3.6.1.4.1.9.9.42.1.2.1.1.9',
52      'rttMonEchoAdminTable'               => '1.3.6.1.4.1.9.9.42.1.2.2',
53      'rttMonEchoAdminProtocol'            => '1.3.6.1.4.1.9.9.42.1.2.2.1.1',
54      'rttMonEchoAdminTargetAddress'       => '1.3.6.1.4.1.9.9.42.1.2.2.1.2',
55      'rttMonEchoAdminPktDataRequestSize'  => '1.3.6.1.4.1.9.9.42.1.2.2.1.3',
56      'rttMonEchoAdminTargetPort'          => '1.3.6.1.4.1.9.9.42.1.2.2.1.5',
57      'rttMonEchoAdminTOS'                 => '1.3.6.1.4.1.9.9.42.1.2.2.1.9',
58      'rttMonEchoAdminTargetAddressString' => '1.3.6.1.4.1.9.9.42.1.2.2.1.11',
59      'rttMonEchoAdminNameServer'          => '1.3.6.1.4.1.9.9.42.1.2.2.1.12',
60      'rttMonEchoAdminURL'                 => '1.3.6.1.4.1.9.9.42.1.2.2.1.15',
61      'rttMonEchoAdminInterval'            => '1.3.6.1.4.1.9.9.42.1.2.2.1.17',
62      'rttMonEchoAdminNumPackets'          => '1.3.6.1.4.1.9.9.42.1.2.2.1.18'
63      );
64
65
66
67 our %adminInterpret =
68     (
69      'rttMonCtrlAdminOwner' => {
70          'order'   => 10,
71          'legend'  => 'Owner: %s;',
72          'param'   => 'rtt-owner'
73          },
74
75      'rttMonCtrlAdminTag' => {
76          'order'   => 20,
77          'legend'  => 'Tag: %s;',
78          'comment' => '%s: ',
79          'param'   => 'rtt-tag'
80          },
81
82      'rttMonCtrlAdminRttType' => {
83          'order'   => 30,
84          'legend'  => 'Type: %s;',
85          'translate' => \&translateRttType,
86          'param'   => 'rtt-type'
87          },
88
89      'rttMonCtrlAdminFrequency' => {
90          'order'   => 40,
91          'legend'  => 'Frequency: %d seconds;',
92          'param'   => 'rtt-frequency'
93          },
94
95      'rttMonEchoAdminProtocol' => {
96          'order'   => 50,
97          'legend'  => 'Protocol: %s;',
98          'translate' => \&translateRttEchoProtocol,
99          'param'   => 'rtt-echo-protocol'
100          },
101
102      'rttMonEchoAdminTargetAddress' => {
103          'order'   => 60,
104          'legend'  => 'Target: %s;',
105          'comment' => 'Target=%s ',
106          'translate' => \&translateRttTargetAddr,
107          'param'   => 'rtt-echo-target-addr',
108          'ignore-text' => '0.0.0.0'
109          },
110
111      'rttMonEchoAdminPktDataRequestSize' => {
112          'order'   => 70,
113          'legend'  => 'Packet size: %d octets;',
114          'param'   => 'rtt-echo-request-size'
115          },
116
117      'rttMonEchoAdminTargetPort' => {
118          'order'   => 80,
119          'legend'  => 'Port: %d;',
120          'param'   => 'rtt-echo-port',
121          'ignore-numeric' => 0
122          },
123
124      'rttMonEchoAdminTOS' => {
125          'order'   => 90,
126          'legend'  => 'TOS: %d;',
127          'comment' => 'TOS=%d ',
128          'param'   => 'rtt-echo-tos',
129          'ignore-numeric' => 0
130          },
131
132      'rttMonEchoAdminTargetAddressString' => {
133          'order'   => 100,
134          'legend'  => 'Address string: %s;',
135          'param'   => 'rtt-echo-addr-string'
136          },
137
138      'rttMonEchoAdminNameServer' => {
139          'order'   => 110,
140          'legend'  => 'NameServer: %s;',
141          'translate' => \&translateRttTargetAddr,
142          'param'   => 'rtt-echo-name-server',
143          'ignore-text' => '0.0.0.0'
144          },
145
146      'rttMonEchoAdminURL' => {
147          'order'   => 120,
148          'legend'  => 'URL: %s;',
149          'param'   => 'rtt-echo-url'
150          },
151
152      'rttMonEchoAdminInterval' => {
153          'order'   => 130,
154          'legend'  => 'Interval: %d milliseconds;',
155          'param'   => 'rtt-echo-interval',
156          'ignore-numeric' => 0
157          },
158
159      'rttMonEchoAdminNumPackets' => {
160          'order'   => 140,
161          'legend'  => 'Packets: %d;',
162          'param'   => 'rtt-echo-num-packets',
163          'ignore-numeric' => 0
164          }
165      );
166
167
168
169 sub checkdevtype
170 {
171     my $dd = shift;
172     my $devdetails = shift;
173
174     my $session = $dd->session();
175
176     if( $devdetails->isDevType('CiscoIOS') )
177     {
178         my $rttAdminTable =
179             $session->get_table( -baseoid =>
180                                  $dd->oiddef('rttMonCtrlAdminTable') );
181         if( defined $rttAdminTable and scalar( %{$rttAdminTable} ) > 0 )
182         {
183             $devdetails->storeSnmpVars( $rttAdminTable );
184             return 1;
185         }
186     }
187
188     return 0;
189 }
190
191
192 sub discover
193 {
194     my $dd = shift;
195     my $devdetails = shift;
196
197     my $session = $dd->session();
198     my $data = $devdetails->data();
199
200     my $rttEchoAdminTable =
201         $session->get_table( -baseoid =>
202                              $dd->oiddef('rttMonEchoAdminTable') );
203     if( defined $rttEchoAdminTable )
204     {
205         $devdetails->storeSnmpVars( $rttEchoAdminTable );
206         undef $rttEchoAdminTable;
207     }
208
209     $data->{'rtt_entries'} = {};
210
211     foreach my $rttIndex
212         ( $devdetails->getSnmpIndices( $dd->oiddef('rttMonCtrlAdminOwner') ) )
213     {
214         # we're interested in Active agents only
215         if( $devdetails->snmpVar($dd->oiddef('rttMonCtrlAdminStatus') .
216                                  '.' . $rttIndex) != 1 )
217         {
218             next;
219         }
220
221         my $ref = {};
222         $data->{'rtt_entries'}{$rttIndex} = $ref;
223         $ref->{'param'} = {};
224
225         my $comment = '';
226         my $legend = '';
227
228         foreach my $adminField
229             ( sort {$adminInterpret{$a}{'order'} <=>
230                         $adminInterpret{$b}{'order'}}
231               keys %adminInterpret )
232         {
233             my $value = $devdetails->snmpVar( $dd->oiddef( $adminField ) .
234                                               '.' . $rttIndex );
235             if( defined( $value ) and length( $value ) > 0 )
236             {
237                 my $intrp = $adminInterpret{$adminField};
238                 if( ref( $intrp->{'translate'} ) )
239                 {
240                     $value = &{$intrp->{'translate'}}( $value );
241                 }
242
243                 if( ( defined( $intrp->{'ignore-numeric'} ) and
244                       $value == $intrp->{'ignore-numeric'} )
245                     or
246                     ( defined( $intrp->{'ignore-text'} ) and
247                       $value eq $intrp->{'ignore-text'} ) )
248                 {
249                     next;
250                 }
251
252                 if( defined( $intrp->{'param'} ) )
253                 {
254                     $ref->{'param'}{$intrp->{'param'}} = $value;
255                 }
256
257                 if( defined( $intrp->{'comment'} ) )
258                 {
259                     $comment .= sprintf( $intrp->{'comment'}, $value );
260                 }
261
262                 if( defined( $intrp->{'legend'} ) )
263                 {
264                     $legend .= sprintf( $intrp->{'legend'}, $value );
265                 }
266             }
267         }
268
269         $ref->{'param'}{'rtt-index'} = $rttIndex;
270         $ref->{'param'}{'comment'} = $comment;
271         $ref->{'param'}{'legend'} = $legend;
272     }
273
274     return 1;
275 }
276
277
278 sub buildConfig
279 {
280     my $devdetails = shift;
281     my $cb = shift;
282     my $devNode = shift;
283
284     my $data = $devdetails->data();
285
286     my $subtreeNode =
287         $cb->addSubtree( $devNode, 'SAA', undef,
288                          ['CiscoIOS_SAA::cisco-saa-subtree']);
289
290     foreach my $rttIndex ( sort {$a<=>$b} keys %{$data->{'rtt_entries'}} )
291     {
292         my $subtreeName = 'rtt_' . $rttIndex;
293         my $param = $data->{'rtt_entries'}{$rttIndex}{'param'};
294         $param->{'precedence'} = sprintf('%d', 10000 - $rttIndex);
295
296         # TODO: should really consider rtt-type and rtt-echo-protocol
297
298         $cb->addSubtree( $subtreeNode, $subtreeName, $param,
299                          ['CiscoIOS_SAA::cisco-rtt-echo-subtree']);
300     }
301 }
302
303
304 our %rttType =
305     (
306      '1'  => 'echo',
307      '2'  => 'pathEcho',
308      '3'  => 'fileIO',
309      '4'  => 'script',
310      '5'  => 'udpEcho',
311      '6'  => 'tcpConnect',
312      '7'  => 'http',
313      '8'  => 'dns',
314      '9'  => 'jitter',
315      '10' => 'dlsw',
316      '11' => 'dhcp',
317      '12' => 'ftp'
318      );
319
320 sub translateRttType
321 {
322     my $value = shift;
323     return $rttType{$value};
324 }
325
326
327 our %rttEchoProtocol =
328     (
329      '1'   =>  'notApplicable',
330      '2'   =>  'ipIcmpEcho',
331      '3'   =>  'ipUdpEchoAppl',
332      '4'   =>  'snaRUEcho',
333      '5'   =>  'snaLU0EchoAppl',
334      '6'   =>  'snaLU2EchoAppl',
335      '7'   =>  'snaLU62Echo',
336      '8'   =>  'snaLU62EchoAppl',
337      '9'   =>  'appleTalkEcho',
338      '10'  =>  'appleTalkEchoAppl',
339      '11'  =>  'decNetEcho',
340      '12'  =>  'decNetEchoAppl',
341      '13'  =>  'ipxEcho',
342      '14'  =>  'ipxEchoAppl',
343      '15'  =>  'isoClnsEcho',
344      '16'  =>  'isoClnsEchoAppl',
345      '17'  =>  'vinesEcho',
346      '18'  =>  'vinesEchoAppl',
347      '19'  =>  'xnsEcho',
348      '20'  =>  'xnsEchoAppl',
349      '21'  =>  'apolloEcho',
350      '22'  =>  'apolloEchoAppl',
351      '23'  =>  'netbiosEchoAppl',
352      '24'  =>  'ipTcpConn',
353      '25'  =>  'httpAppl',
354      '26'  =>  'dnsAppl',
355      '27'  =>  'jitterAppl',
356      '28'  =>  'dlswAppl',
357      '29'  =>  'dhcpAppl',
358      '30'  =>  'ftpAppl'
359      );
360
361 sub translateRttEchoProtocol
362 {
363     my $value = shift;
364     return $rttEchoProtocol{$value};
365 }
366
367 sub translateRttTargetAddr
368 {
369     my $value = shift;
370     $value =~ s/^0x//;
371     return inet_ntoa( pack( 'H8', $value ) );
372 }
373
374
375 1;
376
377
378 # Local Variables:
379 # mode: perl
380 # indent-tabs-mode: nil
381 # perl-indent-level: 4
382 # End: