| 1 | # SNMP::Info::CiscoPower | ||
| 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::CiscoPower; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info; | ||
| 36 | |||
| 37 | @SNMP::Info::CiscoPower::ISA = qw/SNMP::Info Exporter/; | ||
| 38 | @SNMP::Info::CiscoPower::EXPORT_OK = qw//; | ||
| 39 | |||
| 40 | our ($VERSION, %MIBS, %FUNCS, %GLOBALS, %MUNGE); | ||
| 41 | |||
| 42 | $VERSION = '3.985003'; | ||
| 43 | |||
| 44 | %MIBS = ( 'CISCO-POWER-ETHERNET-EXT-MIB' => 'cpeExtPsePortEntPhyIndex', | ||
| 45 | 'CISCO-CDP-MIB' => 'cdpCachePowerConsumption', | ||
| 46 | ); | ||
| 47 | |||
| 48 | %GLOBALS = (); | ||
| 49 | |||
| 50 | %FUNCS = ( | ||
| 51 | 'cpeth_ent_phy' => 'cpeExtPsePortEntPhyIndex', | ||
| 52 | 'peth_port_power' => 'cpeExtPsePortPwrConsumption', | ||
| 53 | ); | ||
| 54 | |||
| 55 | %MUNGE = (); | ||
| 56 | |||
| 57 | # Cisco overcame the limitation of the module.port index of the | ||
| 58 | # pethPsePortTable by adding another mapping table, which maps | ||
| 59 | # a pethPsePortTable row to an entPhysicalTable index, which can | ||
| 60 | # then be mapped to ifIndex. | ||
| 61 | sub peth_port_ifindex { | ||
| 62 | my $cpeth = shift; | ||
| 63 | my $partial = shift; | ||
| 64 | |||
| 65 | my $ent_phy = $cpeth->cpeth_ent_phy($partial); | ||
| 66 | my $e_port = $cpeth->e_port(); | ||
| 67 | |||
| 68 | my $peth_port_ifindex = {}; | ||
| 69 | foreach my $i ( keys %$ent_phy ) { | ||
| 70 | if ( $e_port->{ $ent_phy->{$i} } ) { | ||
| 71 | $peth_port_ifindex->{$i} = $e_port->{ $ent_phy->{$i} }; | ||
| 72 | } | ||
| 73 | } | ||
| 74 | return $peth_port_ifindex; | ||
| 75 | } | ||
| 76 | |||
| 77 | # peth_port_neg_power uses the same index as the other peth_port_* tables. | ||
| 78 | # However, cdpCachePowerConsumption uses <ifIndex>.<neighbor>. | ||
| 79 | # Therefore, we have to invert peth_port_ifindex, to get to | ||
| 80 | # the index that is expected and the rest of the code can re-invert it. | ||
| 81 | sub peth_port_neg_power { | ||
| 82 | my $cpeth = shift; | ||
| 83 | my $partial = shift; | ||
| 84 | |||
| 85 | # Ignoring partial, since it's not easy to implement properly. | ||
| 86 | my $index = $cpeth->peth_port_ifindex(); | ||
| 87 | my %inverse_index; | ||
| 88 | foreach my $i ( keys %$index ) { | ||
| 89 | $inverse_index{ $index->{$i} } = $i; | ||
| 90 | } | ||
| 91 | my $neg_power = $cpeth->cdpCachePowerConsumption(); | ||
| 92 | my $peth_port_neg_power = {}; | ||
| 93 | foreach my $i ( keys %$neg_power ) { | ||
| 94 | my( $ifIndex, $nbrIndex ) = split( /\./, $i ); | ||
| 95 | if ( defined( $inverse_index{ $ifIndex } ) ) { | ||
| 96 | $peth_port_neg_power->{ $inverse_index{ $ifIndex } } = $neg_power->{ $i }; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | return $peth_port_neg_power; | ||
| 100 | } | ||
| 101 | |||
| 102 | 1; | ||
| 103 | |||
| 104 | __END__ |