Info/PowerEthernet.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 54 CC 3 SCAR 13.9
CC
3
Cov
0%
peth_port_ifindex
6.0
peth_port_neg_power
6.0
BEGIN
2.0
CRAP 4.0
1 # SNMP::Info::PowerEthernet
2 #
3 # Copyright (c) 2008 Bill Fenner
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::PowerEthernet;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info;
36  
37 @SNMP::Info::PowerEthernet::ISA = qw/SNMP::Info Exporter/;
38 @SNMP::Info::PowerEthernet::EXPORT_OK = qw//;
39  
40 our ($VERSION, %MIBS, %FUNCS, %GLOBALS, %MUNGE);
41  
42 $VERSION = '3.985003';
43  
44 %MIBS = ( 'POWER-ETHERNET-MIB' => 'pethPsePortDetectionStatus' );
45  
46 %GLOBALS = ();
47  
48 %FUNCS = (
49  
50 # parts of pethPsePortTable
51 'peth_port_admin' => 'pethPsePortAdminEnable',
52 'peth_port_status' => 'pethPsePortDetectionStatus',
53 'peth_port_class' => 'pethPsePortPowerClassifications',
54  
55 # pethMainPseTable
56 'peth_power_watts' => 'pethMainPsePower',
57 'peth_power_status' => 'pethMainPseOperStatus',
58 'peth_power_consumption' => 'pethMainPseConsumptionPower',
59 'peth_power_threshold' => 'pethMainPseUsageThreshold',
60 );
61  
62 %MUNGE = ();
63  
64 # POWER-ETHERNET-MIB doesn't define a mapping of its
65 # "module"/"port" index to ifIndex. Different vendors
66 # do this in different ways. This is a poor fallback:
67 # if all of the module values = 1, return the port number
68 # on the assumption that port number = ifindex.
69 # If there is a module != 1, this heuristic doesn't work
70 # so returns undef.
71 sub peth_port_ifindex {
72 my $peth = shift;
73 my $partial = shift;
74  
75 my $peth_port_status = $peth->peth_port_status($partial);
76 my $peth_port_ifindex = {};
77  
78 foreach my $i ( keys %$peth_port_status ) {
79 my ( $module, $port ) = split( /\./, $i );
80 if ( $module != 1 ) {
81  
82 # This heuristic won't work, so say that we got nothing.
83 # If you have this case, you have to write a device-specific
84 # version of this function.
85 return;
86 }
87 $peth_port_ifindex->{$i} = $port;
88 }
89 return $peth_port_ifindex;
90 }
91  
92 # Subclasses are encouraged to override this method to report
93 # what has actually been negotiated with the device, if a
94 # protocol with more values (e.g., CDP) has been used.
95 sub peth_port_neg_power {
96 my $peth = shift;
97 my $partial = shift;
98  
99 my $peth_port_status = $peth->peth_port_status($partial);
100 my $peth_port_class = $peth->peth_port_class($partial);
101  
102 my $poemax = { 'class0' => 12950, 'class1' => 3840, 'class2' => 6490, 'class3' => 12950,
103 'class4' => 25500 };
104  
105 my $peth_port_neg_power = {};
106 foreach my $i ( keys %$peth_port_status ) {
107 if ($peth_port_status->{$i} eq 'deliveringPower') {
108 $peth_port_neg_power->{$i} = $poemax->{ $peth_port_class->{$i} };
109 }
110 }
111 return $peth_port_neg_power;
112 }
113  
114 1;
115  
116 __END__