Info/Layer1/Cyclades.pm untested

filter: Statementstmt 0.0% 0 / 145 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 214 MC/DCmcdc 0.0% 0 / 86 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 15 totaltotal 0.0% 0 / 527 CC 25 SCAR 30.0
CC
25
Cov
0%
interfaces
30.0
i_speed
30.0
i_up
30.0
CRAP 20.1
1 # SNMP::Info::Layer1::Cyclades
2 #
3 # Copyright (c) 2018 Eric Miller
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the University of California, Santa Cruz nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29  
30 package SNMP::Info::Layer1::Cyclades;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::Layer1;
36  
37 @SNMP::Info::Layer1::Cyclades::ISA = qw/SNMP::Info::Layer1 Exporter/;
38 @SNMP::Info::Layer1::Cyclades::EXPORT_OK = qw//;
39  
40 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE, $AUTOLOAD);
41  
42 $VERSION = '3.985003';
43  
44 %MIBS = (
45 %SNMP::Info::Layer1::MIBS,
46 'CYCLADES-ACS-SYS-MIB' => 'cyACSversion',
47 'CYCLADES-ACS5K-SYS-MIB' => 'cyACS5Kversion',
48 'CYCLADES-ACS-CONF-MIB' => 'cyACSConf',
49 'CYCLADES-ACS5K-CONF-MIB' => 'cyACS5KConf',
50 'CYCLADES-ACS-INFO-MIB' => 'cyACSInfo',
51 'CYCLADES-ACS5K-INFO-MIB' => 'cyACS5KInfo',
52 'ACS-MIB' => 'acs6016',
53 'ACS8000-MIB' => 'acs8048',
54 );
55  
56 %GLOBALS = (
57  
58 %SNMP::Info::Layer1::GLOBALS,
59  
60 # CYCLADES-ACS-SYS-MIB
61 'cy_os_ver' => 'cyACSversion',
62 'cy_model' => 'cyACSpname',
63 'cy_serial' => 'cyACSDevId',
64 'cy_ps1_status' => 'cyACSPw1',
65 'cy_ps2_status' => 'cyACSPw2',
66  
67 # CYCLADES-ACS-CONF-MIB
68 'cy_root_ip' => 'CYCLADES_ACS_CONF_MIB__cyEthIPaddr',
69  
70 # CYCLADES-ACS5K-SYS-MIB
71 'cy5k_os_ver' => 'cyACS5Kversion',
72 'cy5k_model' => 'cyACS5Kpname',
73 'cy5k_serial' => 'cyACS5KDevId',
74 'cy5k_ps1_status' => 'cyACS5KPw1',
75 'cy5k_ps2_status' => 'cyACS5KPw2',
76  
77 # CYCLADES-ACS5K-CONF-MIB
78 'cy5k_root_ip' => 'CYCLADES_ACS5K_CONF_MIB__cyEthIPaddr',
79  
80 # ACS-MIB
81 'acs_os_ver' => 'ACS_MIB__acsFirmwareVersion',
82 'acs_model' => 'ACS_MIB__acsProductModel',
83 'acs_serial' => 'ACS_MIB__acsSerialNumber',
84 'acs_ps1_status' => 'ACS_MIB__acsPowerSupplyStatePw1',
85 'acs_ps2_status' => 'ACS_MIB__acsPowerSupplyStatePw2',
86  
87 # ACS8000-MIB
88 'acs8k_os_ver' => 'ACS8000_MIB__acsFirmwareVersion',
89 'acs8k_model' => 'ACS8000_MIB__acsProductModel',
90 'acs8k_serial' => 'ACS8000_MIB__acsSerialNumber',
91 'acs8k_ps1_status' => 'ACS8000_MIB__acsPowerSupplyStatePw1',
92 'acs8k_ps2_status' => 'ACS8000_MIB__acsPowerSupplyStatePw2',
93 );
94  
95 %FUNCS = (
96 %SNMP::Info::Layer1::FUNCS,
97  
98 # CYCLADES-ACS-INFO-MIB::cyInfoSerialTable
99 'cy_port_tty' => 'CYCLADES_ACS_INFO_MIB__cyISPortTty',
100 'cy_port_name' => 'CYCLADES_ACS_INFO_MIB__cyISPortName',
101 'cy_port_speed' => 'CYCLADES_ACS_INFO_MIB__cyISPortSpeed',
102 'cy_port_cd' => 'CYCLADES_ACS_INFO_MIB__cyISPortSigCD',
103  
104 # CYCLADES-ACS-CONF-MIB::cySerialPortTable
105 'cy_port_socket' => 'CYCLADES_ACS_CONF_MIB__cySPortSocketPort',
106  
107 # CYCLADES-ACS5K-INFO-MIB::cyInfoSerialTable
108 'cy5k_port_tty' => 'CYCLADES_ACS5K_INFO_MIB__cyISPortTty',
109 'cy5k_port_name' => 'CYCLADES_ACS5K_INFO_MIB__cyISPortName',
110 'cy5k_port_speed' => 'CYCLADES_ACS5K_INFO_MIB__cyISPortSpeed',
111 'cy5k_port_cd' => 'CYCLADES_ACS5K_INFO_MIB__cyISPortSigCD',
112  
113 # CYCLADES-ACS5K-CONF-MIB::cySerialPortTable
114 'cy5k_port_socket' => 'CYCLADES_ACS5K_CONF_MIB__cySPortSocketPort',
115  
116 # ACS-MIB::acsSerialPortTable
117 'acs_port_tty' => 'ACS_MIB__acsSerialPortTableDeviceName',
118 'acs_port_name' => 'ACS_MIB__acsSerialPortTableName',
119 'acs_port_speed' => 'ACS_MIB__acsSerialPortTableComSpeed',
120 'acs_port_cd' => 'ACS_MIB__acsSerialPortTableSignalStateDCD',
121  
122 # Equivalent to cySPortSocketPort doesn't exist in ACS-MIB
123 # Use 'acsSerialPortTableDeviceName' as an equivalent, it just needs
124 # to be unique so that we can differentiate between the index in the
125 # acsSerialPortTable from ifIndex which are both integers
126 # ACS-MIB::acsSerialPortTableEntry
127 'acs_port_socket' => 'ACS_MIB__acsSerialPortTableDeviceName',
128  
129 # ACS8000-MIB::acsSerialPortTable
130 'acs8k_port_tty' => 'ACS8000_MIB__acsSerialPortTableDeviceName',
131 'acs8k_port_name' => 'ACS8000_MIB__acsSerialPortTableName',
132 'acs8k_port_speed' => 'ACS8000_MIB__acsSerialPortTableComSpeed',
133 'acs8k_port_cd' => 'ACS8000_MIB__acsSerialPortTableSignalStateDCD',
134  
135 # Equivalent to cySPortSocketPort doesn't exist in ACS-MIB
136 # Use 'acsSerialPortTableDeviceName' as an equivalent, it just needs
137 # to be unique so that we can differentiate between the index in the
138 # acsSerialPortTable from ifIndex which are both integers
139 # ACS8000-MIB::acsSerialPortTableEntry
140 'acs8k_port_socket' => 'ACS8000_MIB__acsSerialPortTableDeviceName',
141 );
142  
143 %MUNGE = ( %SNMP::Info::Layer1::MUNGE, );
144  
145 # These devices don't have a FDB and we probably don't want to poll for ARP
146 # cache so turn off reported L2/L3.
147 sub layers {
148 return '01000001';
149 }
150  
151 sub os {
152 return 'avocent';
153 }
154  
155 # Use "short circuit" to return the first MIB instance that returns data to
156 # reduce network communications
157 # We'll try newest (acs*) first assuming those are most likely deployed
158 sub os_ver {
159 my $cyclades = shift;
160  
161 return
162 $cyclades->acs_os_ver()
163 || $cyclades->acs8k_os_ver()
164 || $cyclades->cy5k_os_ver()
165 || $cyclades->cy_os_ver()
166 || undef;
167 }
168  
169 sub vendor {
170 return 'vertiv';
171 }
172  
173 sub model {
174 my $cyclades = shift;
175  
176 my $model
177 = $cyclades->acs_model()
178 || $cyclades->acs8k_model()
179 || $cyclades->cy5k_model()
180 || $cyclades->cy_model()
181 || undef;
182  
183 return lc($model) if ( defined $model );
184  
185 my $id = $cyclades->id();
186 my $prod = SNMP::translateObj($id);
187  
188 return $prod || $id;
189 }
190  
191 sub serial {
192 my $cyclades = shift;
193  
194 return
195 $cyclades->acs_serial()
196 || $cyclades->acs8k_serial()
197 || $cyclades->cy5k_serial()
198 || $cyclades->cy_serial()
199 || undef;
200 }
201  
202 sub root_ip {
203 my $cyclades = shift;
204  
205 return
206 $cyclades->cy5k_root_ip()
207 || $cyclades->cy_root_ip()
208 || undef;
209 }
210  
211 sub ps1_status {
212 my $cyclades = shift;
213  
214 return
215 $cyclades->acs_ps1_status()
216 || $cyclades->acs8k_ps1_status()
217 || $cyclades->cy5k_ps1_status()
218 || $cyclades->cy_ps1_status()
219 || undef;
220 }
221  
222 sub ps2_status {
223 my $cyclades = shift;
224  
225 return
226 $cyclades->acs_ps2_status()
227 || $cyclades->acs8k_ps2_status()
228 || $cyclades->cy5k_ps2_status()
229 || $cyclades->cy_ps2_status()
230 || undef;
231 }
232  
233 # Extend interface methods to include serial ports
234 #
235 # Partials don't really help in this class, but implemented
236 # for consistency
237  
238 sub i_index {
239 my $cyclades = shift;
240 my $partial = shift;
241  
242 my $orig_index = $cyclades->orig_i_index($partial) || {};
243 my $cy_index
244 = $cyclades->acs_port_socket()
245 || $cyclades->acs8k_port_socket()
246 || $cyclades->cy5k_port_socket()
247 || $cyclades->cy_port_socket()
248 || {};
249  
250 my %i_index;
251 foreach my $iid ( keys %$orig_index ) {
252 my $index = $orig_index->{$iid};
253 next unless defined $index;
254  
255 $i_index{$iid} = $index;
256 }
257  
258 # Use alternative labeling system for the serial port, listening socket
259 # to avoid conflicts with ifIndex.
260 foreach my $iid ( keys %$cy_index ) {
261 my $index = $cy_index->{$iid};
262 next unless defined $index;
263 next if ( defined $partial and $index !~ /^$partial$/ );
264  
265 $i_index{$index} = $index;
266 }
267  
268 return \%i_index;
269 }
270  
271 sub interfaces {
272 my $cyclades = shift;
273 my $partial = shift;
274  
275 my $i_descr = $cyclades->orig_i_description($partial) || {};
276 my $cy_index
277 = $cyclades->acs_port_socket()
278 || $cyclades->acs8k_port_socket()
279 || $cyclades->cy5k_port_socket()
280 || $cyclades->cy_port_socket()
281 || {};
282 my $cy_p_tty
283 = $cyclades->acs_port_tty()
284 || $cyclades->acs8k_port_tty()
285 || $cyclades->cy5k_port_tty()
286 || $cyclades->cy_port_tty()
287 || {};
288  
289 my %if;
290 foreach my $iid ( keys %$i_descr ) {
291 my $descr = $i_descr->{$iid};
292 next unless defined $descr;
293  
294 $if{$iid} = $descr;
295 }
296  
297 foreach my $iid ( keys %$cy_p_tty ) {
298 my $index = $cy_index->{$iid};
299 next unless defined $index;
300 next if ( defined $partial and $index !~ /^$partial$/ );
301 my $name = $cy_p_tty->{$iid};
302 next unless defined $name;
303  
304 $if{$index} = $name;
305 }
306  
307 return \%if;
308 }
309  
310 sub i_speed {
311 my $cyclades = shift;
312 my $partial = shift;
313  
314 my $i_speed = $cyclades->orig_i_speed($partial) || {};
315 my $cy_index
316 = $cyclades->acs_port_socket()
317 || $cyclades->acs8k_port_socket()
318 || $cyclades->cy5k_port_socket()
319 || $cyclades->cy_port_socket()
320 || {};
321 my $cy_p_speed
322 = $cyclades->acs_port_speed()
323 || $cyclades->acs8k_port_speed()
324 || $cyclades->cy5k_port_speed()
325 || $cyclades->cy_port_speed()
326 || {};
327  
328 my %i_speed;
329 foreach my $iid ( keys %$i_speed ) {
330 my $speed = $i_speed->{$iid};
331 next unless defined $speed;
332  
333 $i_speed{$iid} = $speed;
334 }
335  
336 foreach my $iid ( keys %$cy_p_speed ) {
337 my $index = $cy_index->{$iid};
338 next unless defined $index;
339 next if ( defined $partial and $index !~ /^$partial$/ );
340 my $speed = $cy_p_speed->{$iid};
341 next unless defined $speed;
342  
343 $i_speed{$index} = $speed;
344 }
345  
346 return \%i_speed;
347 }
348  
349 sub i_up {
350 my $cyclades = shift;
351 my $partial = shift;
352  
353 my $i_up = $cyclades->orig_i_up($partial) || {};
354 my $cy_index
355 = $cyclades->acs_port_socket()
356 || $cyclades->acs8k_port_socket()
357 || $cyclades->cy5k_port_socket()
358 || $cyclades->cy_port_socket()
359 || {};
360 my $cy_p_up
361 = $cyclades->acs_port_cd()
362 || $cyclades->acs8k_port_cd()
363 || $cyclades->cy5k_port_cd()
364 || $cyclades->cy_port_cd()
365 || {};
366  
367 my %i_up;
368 foreach my $iid ( keys %$i_up ) {
369 my $up = $i_up->{$iid};
370 next unless defined $up;
371  
372 $i_up{$iid} = $up;
373 }
374  
375 foreach my $iid ( keys %$cy_p_up ) {
376 my $index = $cy_index->{$iid};
377 next unless defined $index;
378 next if ( defined $partial and $index !~ /^$partial$/ );
379 my $up = $cy_p_up->{$iid};
380 next unless defined $up;
381  
382 $i_up{$index} = $up;
383 }
384  
385 return \%i_up;
386 }
387  
388 sub i_description {
389 my $cyclades = shift;
390 my $partial = shift;
391  
392 my $i_desc = $cyclades->orig_i_description($partial) || {};
393 my $cy_index
394 = $cyclades->acs_port_socket()
395 || $cyclades->acs8k_port_socket()
396 || $cyclades->cy5k_port_socket()
397 || $cyclades->cy_port_socket()
398 || {};
399 my $cy_p_desc
400 = $cyclades->acs_port_name()
401 || $cyclades->acs8k_port_name()
402 || $cyclades->cy5k_port_name()
403 || $cyclades->cy_port_name()
404 || {};
405  
406 my %descr;
407 foreach my $iid ( keys %$i_desc ) {
408 my $desc = $i_desc->{$iid};
409 next unless defined $desc;
410  
411 $descr{$iid} = $desc;
412 }
413  
414 foreach my $iid ( keys %$cy_p_desc ) {
415 my $index = $cy_index->{$iid};
416 next unless defined $index;
417 next if ( defined $partial and $index !~ /^$partial$/ );
418 my $desc = $cy_p_desc->{$iid};
419 next unless defined $desc;
420  
421 $descr{$index} = $desc;
422 }
423  
424 return \%descr;
425 }
426  
427 sub i_name {
428 my $cyclades = shift;
429 my $partial = shift;
430  
431 my $i_name = $cyclades->orig_i_name($partial) || {};
432 my $cy_index
433 = $cyclades->acs_port_socket()
434 || $cyclades->acs8k_port_socket()
435 || $cyclades->cy5k_port_socket()
436 || $cyclades->cy_port_socket()
437 || {};
438 my $cy_p_desc
439 = $cyclades->acs_port_name()
440 || $cyclades->acs8k_port_name()
441 || $cyclades->cy5k_port_name()
442 || $cyclades->cy_port_name()
443 || {};
444  
445 my %i_name;
446 foreach my $iid ( keys %$i_name ) {
447 my $name = $i_name->{$iid};
448 next unless defined $name;
449  
450 $i_name{$iid} = $name;
451 }
452  
453 foreach my $iid ( keys %$cy_p_desc ) {
454 my $index = $cy_index->{$iid};
455 next unless defined $index;
456 next if ( defined $partial and $index !~ /^$partial$/ );
457 my $name = $cy_p_desc->{$iid};
458 next unless defined $name;
459  
460 $i_name{$index} = $name;
461 }
462  
463 return \%i_name;
464 }
465  
466 1;
467 __END__