Merge remote-tracking branch 'upstream/master'
[torrus-plus.git] / src / lib / Torrus / DevDiscover / CiscoIOS_SAA.pm
blob5a527f66ec8eb22e9eb2f7eca0c37be279e9c71f
1 # Copyright (C) 2002 Stanislav Sinyagin
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.
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.
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.
17 # $Id$
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
20 # Cisco IOS Service Assurance Agent
21 # TODO:
22 # should really consider rtt-type and rtt-echo-protocol when applying
23 # per-rtt templates
25 # translate TOS bits into DSCP values
27 package Torrus::DevDiscover::CiscoIOS_SAA;
29 use strict;
30 use warnings;
32 use Socket qw(inet_ntoa);
33 use Torrus::Log;
35 our $VERSION = 1.0;
37 $Torrus::DevDiscover::registry{'CiscoIOS_SAA'} = {
38 'sequence' => 510,
39 'checkdevtype' => \&checkdevtype,
40 'discover' => \&discover,
41 'buildConfig' => \&buildConfig
45 our %oiddef =
47 # CISCO-RTTMON-MIB
48 'rttMonCtrlAdminTable' => '1.3.6.1.4.1.9.9.42.1.2.1',
49 'rttMonCtrlAdminOwner' => '1.3.6.1.4.1.9.9.42.1.2.1.1.2',
50 'rttMonCtrlAdminTag' => '1.3.6.1.4.1.9.9.42.1.2.1.1.3',
51 'rttMonCtrlAdminRttType' => '1.3.6.1.4.1.9.9.42.1.2.1.1.4',
52 'rttMonCtrlAdminFrequency' => '1.3.6.1.4.1.9.9.42.1.2.1.1.6',
53 'rttMonCtrlAdminStatus' => '1.3.6.1.4.1.9.9.42.1.2.1.1.9',
54 'rttMonEchoAdminTable' => '1.3.6.1.4.1.9.9.42.1.2.2',
55 'rttMonEchoAdminProtocol' => '1.3.6.1.4.1.9.9.42.1.2.2.1.1',
56 'rttMonEchoAdminTargetAddress' => '1.3.6.1.4.1.9.9.42.1.2.2.1.2',
57 'rttMonEchoAdminPktDataRequestSize' => '1.3.6.1.4.1.9.9.42.1.2.2.1.3',
58 'rttMonEchoAdminTargetPort' => '1.3.6.1.4.1.9.9.42.1.2.2.1.5',
59 'rttMonEchoAdminTOS' => '1.3.6.1.4.1.9.9.42.1.2.2.1.9',
60 'rttMonEchoAdminTargetAddressString' => '1.3.6.1.4.1.9.9.42.1.2.2.1.11',
61 'rttMonEchoAdminNameServer' => '1.3.6.1.4.1.9.9.42.1.2.2.1.12',
62 'rttMonEchoAdminURL' => '1.3.6.1.4.1.9.9.42.1.2.2.1.15',
63 'rttMonEchoAdminInterval' => '1.3.6.1.4.1.9.9.42.1.2.2.1.17',
64 'rttMonEchoAdminNumPackets' => '1.3.6.1.4.1.9.9.42.1.2.2.1.18'
69 our %adminInterpret =
71 'rttMonCtrlAdminOwner' => {
72 'order' => 10,
73 'legend' => 'Owner: %s;',
74 'param' => 'rtt-owner'
77 'rttMonCtrlAdminTag' => {
78 'order' => 20,
79 'legend' => 'Tag: %s;',
80 'comment' => '%s: ',
81 'param' => 'rtt-tag'
84 'rttMonCtrlAdminRttType' => {
85 'order' => 30,
86 'legend' => 'Type: %s;',
87 'translate' => \&translateRttType,
88 'param' => 'rtt-type'
91 'rttMonCtrlAdminFrequency' => {
92 'order' => 40,
93 'legend' => 'Frequency: %d seconds;',
94 'param' => 'rtt-frequency'
97 'rttMonEchoAdminProtocol' => {
98 'order' => 50,
99 'legend' => 'Protocol: %s;',
100 'translate' => \&translateRttEchoProtocol,
101 'param' => 'rtt-echo-protocol'
104 'rttMonEchoAdminTargetAddress' => {
105 'order' => 60,
106 'legend' => 'Target: %s;',
107 'comment' => 'Target=%s ',
108 'translate' => \&translateRttTargetAddr,
109 'param' => 'rtt-echo-target-addr',
110 'ignore-text' => '0.0.0.0'
113 'rttMonEchoAdminPktDataRequestSize' => {
114 'order' => 70,
115 'legend' => 'Packet size: %d octets;',
116 'param' => 'rtt-echo-request-size'
119 'rttMonEchoAdminTargetPort' => {
120 'order' => 80,
121 'legend' => 'Port: %d;',
122 'param' => 'rtt-echo-port',
123 'ignore-numeric' => 0
126 'rttMonEchoAdminTOS' => {
127 'order' => 90,
128 'legend' => 'TOS: %d;',
129 'comment' => 'TOS=%d ',
130 'param' => 'rtt-echo-tos',
131 'ignore-numeric' => 0
134 'rttMonEchoAdminTargetAddressString' => {
135 'order' => 100,
136 'legend' => 'Address string: %s;',
137 'param' => 'rtt-echo-addr-string'
140 'rttMonEchoAdminNameServer' => {
141 'order' => 110,
142 'legend' => 'NameServer: %s;',
143 'translate' => \&translateRttTargetAddr,
144 'param' => 'rtt-echo-name-server',
145 'ignore-text' => '0.0.0.0'
148 'rttMonEchoAdminURL' => {
149 'order' => 120,
150 'legend' => 'URL: %s;',
151 'param' => 'rtt-echo-url'
154 'rttMonEchoAdminInterval' => {
155 'order' => 130,
156 'legend' => 'Interval: %d milliseconds;',
157 'param' => 'rtt-echo-interval',
158 'ignore-numeric' => 0
161 'rttMonEchoAdminNumPackets' => {
162 'order' => 140,
163 'legend' => 'Packets: %d;',
164 'param' => 'rtt-echo-num-packets',
165 'ignore-numeric' => 0
171 sub checkdevtype
173 my $dd = shift;
174 my $devdetails = shift;
176 my $session = $dd->session();
178 if( $devdetails->isDevType('CiscoIOS') )
180 my $rttAdminTable =
181 $session->get_table( -baseoid =>
182 $dd->oiddef('rttMonCtrlAdminTable') );
183 if( defined($rttAdminTable) and scalar(keys %{$rttAdminTable}) > 0 )
185 $devdetails->storeSnmpVars( $rttAdminTable );
186 return 1;
190 return 0;
194 sub discover
196 my $dd = shift;
197 my $devdetails = shift;
199 my $session = $dd->session();
200 my $data = $devdetails->data();
202 my $rttEchoAdminTable =
203 $session->get_table( -baseoid =>
204 $dd->oiddef('rttMonEchoAdminTable') );
205 if( defined $rttEchoAdminTable )
207 $devdetails->storeSnmpVars( $rttEchoAdminTable );
208 undef $rttEchoAdminTable;
211 $data->{'rtt_entries'} = {};
213 for my $rttIndex
214 ( $devdetails->getSnmpIndices( $dd->oiddef('rttMonCtrlAdminOwner') ) )
216 # we're interested in Active agents only
217 if( $devdetails->snmpVar($dd->oiddef('rttMonCtrlAdminStatus') .
218 '.' . $rttIndex) != 1 )
220 next;
223 my $ref = {};
224 $data->{'rtt_entries'}{$rttIndex} = $ref;
225 $ref->{'param'} = {};
227 my $comment = '';
228 my $legend = '';
230 for my $adminField
231 ( sort {$adminInterpret{$a}{'order'} <=>
232 $adminInterpret{$b}{'order'}}
233 keys %adminInterpret )
235 my $value = $devdetails->snmpVar( $dd->oiddef( $adminField ) .
236 '.' . $rttIndex );
237 if( defined( $value ) and length( $value ) > 0 )
239 my $intrp = $adminInterpret{$adminField};
240 if( ref( $intrp->{'translate'} ) )
242 $value = &{$intrp->{'translate'}}( $value );
245 if( ( defined( $intrp->{'ignore-numeric'} ) and
246 $value == $intrp->{'ignore-numeric'} )
248 ( defined( $intrp->{'ignore-text'} ) and
249 $value eq $intrp->{'ignore-text'} ) )
251 next;
254 if( defined( $intrp->{'param'} ) )
256 $ref->{'param'}{$intrp->{'param'}} = $value;
259 if( defined( $intrp->{'comment'} ) )
261 $comment .= sprintf( $intrp->{'comment'}, $value );
264 if( defined( $intrp->{'legend'} ) )
266 $legend .= sprintf( $intrp->{'legend'}, $value );
271 $ref->{'param'}{'rtt-index'} = $rttIndex;
272 $ref->{'param'}{'comment'} = $comment;
273 $ref->{'param'}{'legend'} = $legend;
276 return 1;
280 sub buildConfig
282 my $devdetails = shift;
283 my $cb = shift;
284 my $devNode = shift;
286 my $data = $devdetails->data();
288 my $subtreeNode =
289 $cb->addSubtree( $devNode, 'SAA', undef,
290 ['CiscoIOS_SAA::cisco-saa-subtree']);
292 for my $rttIndex ( sort {$a<=>$b} keys %{$data->{'rtt_entries'}} )
294 my $subtreeName = 'rtt_' . $rttIndex;
295 my $param = $data->{'rtt_entries'}{$rttIndex}{'param'};
296 $param->{'precedence'} = sprintf('%d', 10000 - $rttIndex);
298 # TODO: should really consider rtt-type and rtt-echo-protocol
300 $cb->addSubtree( $subtreeNode, $subtreeName, $param,
301 ['CiscoIOS_SAA::cisco-rtt-echo-subtree']);
304 return;
308 our %rttType =
310 '1' => 'echo',
311 '2' => 'pathEcho',
312 '3' => 'fileIO',
313 '4' => 'script',
314 '5' => 'udpEcho',
315 '6' => 'tcpConnect',
316 '7' => 'http',
317 '8' => 'dns',
318 '9' => 'jitter',
319 '10' => 'dlsw',
320 '11' => 'dhcp',
321 '12' => 'ftp'
324 sub translateRttType
326 my $value = shift;
327 return $rttType{$value};
331 our %rttEchoProtocol =
333 '1' => 'notApplicable',
334 '2' => 'ipIcmpEcho',
335 '3' => 'ipUdpEchoAppl',
336 '4' => 'snaRUEcho',
337 '5' => 'snaLU0EchoAppl',
338 '6' => 'snaLU2EchoAppl',
339 '7' => 'snaLU62Echo',
340 '8' => 'snaLU62EchoAppl',
341 '9' => 'appleTalkEcho',
342 '10' => 'appleTalkEchoAppl',
343 '11' => 'decNetEcho',
344 '12' => 'decNetEchoAppl',
345 '13' => 'ipxEcho',
346 '14' => 'ipxEchoAppl',
347 '15' => 'isoClnsEcho',
348 '16' => 'isoClnsEchoAppl',
349 '17' => 'vinesEcho',
350 '18' => 'vinesEchoAppl',
351 '19' => 'xnsEcho',
352 '20' => 'xnsEchoAppl',
353 '21' => 'apolloEcho',
354 '22' => 'apolloEchoAppl',
355 '23' => 'netbiosEchoAppl',
356 '24' => 'ipTcpConn',
357 '25' => 'httpAppl',
358 '26' => 'dnsAppl',
359 '27' => 'jitterAppl',
360 '28' => 'dlswAppl',
361 '29' => 'dhcpAppl',
362 '30' => 'ftpAppl'
365 sub translateRttEchoProtocol
367 my $value = shift;
368 return $rttEchoProtocol{$value};
371 sub translateRttTargetAddr
373 my $value = shift;
374 $value =~ s/^0x//;
375 return inet_ntoa( pack( 'H8', $value ) );
382 # Local Variables:
383 # mode: perl
384 # indent-tabs-mode: nil
385 # perl-indent-level: 4
386 # End: