bury all dead whitespace, better off to just do it in one command. i wonder why ss...
[torrus-plus.git] / src / lib / Torrus / DevDiscover / CasaCMTS.pm
blobea793553110e701d77fb8910cd1d011923589a49
1 # Copyright (C) 2010 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 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19 # DOCSIS interface, CASA specific
21 package Torrus::DevDiscover::CasaCMTS;
23 use strict;
24 use warnings;
26 use Torrus::Log;
28 our $VERSION = 1.0;
30 $Torrus::DevDiscover::registry{'CasaCMTS'} = {
31 'sequence' => 500,
32 'checkdevtype' => \&checkdevtype,
33 'discover' => \&discover,
34 'buildConfig' => \&buildConfig
38 $Torrus::DevDiscover::RFC2863_IF_MIB::knownSelectorActions{
39 'DocsisMacModemsMonitor'} = 'CasaCMTS';
42 our %oiddef =
44 'casaProducts' => '1.3.6.1.4.1.20858.2',
48 sub checkdevtype
50 my $dd = shift;
51 my $devdetails = shift;
53 if( not $dd->oidBaseMatch
54 ( 'casaProducts',
55 $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) or
56 not $devdetails->isDevType('RFC2670_DOCS_IF') )
58 return 0;
61 return 1;
65 sub discover
67 my $dd = shift;
68 my $devdetails = shift;
70 my $data = $devdetails->data();
72 push( @{$data->{'docsConfig'}{'docsCableMaclayer'}{'templates'}},
73 'CasaCMTS::casa-docsis-mac-subtree' );
75 for my $ifIndex ( @{$data->{'docsCableMaclayer'}} )
77 my $interface = $data->{'interfaces'}{$ifIndex};
79 push( @{$interface->{'docsTemplates'}},
80 'CasaCMTS::casa-docsis-mac-util' );
83 for my $ifIndex ( @{$data->{'docsCableUpstream'}} )
85 my $interface = $data->{'interfaces'}{$ifIndex};
87 push( @{$interface->{'docsTemplates'}},
88 'CasaCMTS::casa-docsis-upstream-util' );
91 for my $ifIndex ( @{$data->{'docsCableDownstream'}} )
93 my $interface = $data->{'interfaces'}{$ifIndex};
95 push( @{$interface->{'docsTemplates'}},
96 'CasaCMTS::casa-docsis-downstream-util' );
99 $data->{'nameref'}{'ifNodeid'} = 'ifNameT';
101 return 1;
105 sub buildConfig
107 my $devdetails = shift;
108 my $cb = shift;
109 my $devNode = shift;
111 my $data = $devdetails->data();
114 if( scalar( @{$data->{'docsCableMaclayer'}} ) > 0 )
116 # Build All_Modems summary graph
117 my $param = {
118 'ds-type' => 'rrd-multigraph',
119 'ds-names' => 'total,active,registered',
120 'graph-lower-limit' => '0',
121 'precedence' => '1000',
122 'vertical-label' => 'Modems',
124 'graph-legend-total' => 'Total',
125 'line-style-total' => '##totalresource',
126 'line-color-total' => '##totalresource',
127 'line-order-total' => '1',
129 'graph-legend-active' => 'Active',
130 'line-style-active' => '##resourcepartusage',
131 'line-color-active' => '##resourcepartusage',
132 'line-order-active' => '2',
134 'graph-legend-registered' => 'Registered',
135 'line-style-registered' => '##resourceusage',
136 'line-color-registered' => '##resourceusage',
137 'line-order-registered' => '3',
138 'descriptive-nickname' => '%system-id%: All modems'
141 # for the sake of better Emacs formatting
142 $param->{'comment'} =
143 'Registered, Active and Total modems on CMTS';
145 $param->{'nodeid'} =
146 $data->{'docsConfig'}{'docsCableMaclayer'}{'nodeidCategory'} .
147 '//%nodeid-device%//modems';
149 my $first = 1;
150 for my $ifIndex ( @{$data->{'docsCableMaclayer'}} )
152 my $interface = $data->{'interfaces'}{$ifIndex};
154 my $intf = $interface->{$data->{'nameref'}{'ifSubtreeName'}};
156 if( $first )
158 $param->{'ds-expr-total'} =
159 '{' . $intf . '/Modems_Total}';
160 $param->{'ds-expr-active'} =
161 '{' . $intf . '/Modems_Active}';
162 $param->{'ds-expr-registered'} =
163 '{' . $intf . '/Modems_Registered}';
164 $first = 0;
166 else
168 $param->{'ds-expr-total'} .=
169 ',{' . $intf . '/Modems_Total},+';
170 $param->{'ds-expr-active'} .=
171 ',{' . $intf . '/Modems_Active},+';
172 $param->{'ds-expr-registered'} .=
173 ',{' . $intf . '/Modems_Registered},+';
177 my $macNode =
178 $cb->getChildSubtree( $devNode,
179 $data->{'docsConfig'}{
180 'docsCableMaclayer'}{
181 'subtreeName'} );
182 if( defined( $macNode ) )
184 $cb->addLeaf( $macNode, 'All_Modems', $param, [] );
186 else
188 Error('Could not find the MAC layer subtree');
189 exit 1;
192 # Apply selector actions
193 for my $ifIndex ( @{$data->{'docsCableMaclayer'}} )
195 my $interface = $data->{'interfaces'}{$ifIndex};
197 my $intf = $interface->{$data->{'nameref'}{'ifSubtreeName'}};
199 my $monitor =
200 $interface->{'selectorActions'}{'DocsisMacModemsMonitor'};
201 if( defined( $monitor ) )
203 my $intfNode = $cb->getChildSubtree( $macNode, $intf );
204 $cb->addLeaf( $intfNode, 'Modems_Registered',
205 {'monitor' => $monitor } );
210 if( scalar( @{$data->{'docsCableUpstream'}} ) > 0 )
212 my $upstrNode =
213 $cb->getChildSubtree( $devNode,
214 $data->{'docsConfig'}{'docsCableUpstream'}{
215 'subtreeName'} );
217 # Override the overview shortcus defined in rfc2670.docsis-if.xml
219 my $shortcuts = 'snr,fec,freq,modems';
221 my $param = {
222 'overview-shortcuts' =>
223 $shortcuts,
225 'overview-subleave-name-modems' => 'Modems',
226 'overview-direct-link-modems' => 'yes',
227 'overview-direct-link-view-modems' => 'expanded-dir-html',
228 'overview-shortcut-text-modems' => 'All modems',
229 'overview-shortcut-title-modems'=>
230 'Show modem quantities in one page',
231 'overview-page-title-modems' => 'Modem quantities',
234 $cb->addParams( $upstrNode, $param );
237 if( scalar( @{$data->{'docsCableDownstream'}} ) > 0 )
239 my $downstrNode =
240 $cb->getChildSubtree( $devNode,
241 $data->{'docsConfig'}{'docsCableDownstream'}{
242 'subtreeName'} );
244 # Override the overview shortcus defined in rfc2670.docsis-if.xml
246 my $shortcuts = 'util,modems';
248 my $param = {
249 'overview-shortcuts' => $shortcuts,
250 'overview-subleave-name-modems' => 'Modems',
251 'overview-direct-link-modems' => 'yes',
252 'overview-direct-link-view-modems' => 'expanded-dir-html',
253 'overview-shortcut-text-modems' => 'All modems',
254 'overview-shortcut-title-modems' =>
255 'Show modem quantities in one page',
256 'overview-page-title-modems' => 'Modem quantities',
259 $cb->addParams( $downstrNode, $param );
262 return;
269 # Local Variables:
270 # mode: perl
271 # indent-tabs-mode: nil
272 # perl-indent-level: 4
273 # End: