| 1 | # SNMP::Info::EDP | ||
| 2 | # | ||
| 3 | # Copyright (c) 2012 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 | |||
| 31 | package SNMP::Info::EDP; | ||
| 32 | |||
| 33 | use strict; | ||
| 34 | use warnings; | ||
| 35 | use Exporter; | ||
| 36 | use SNMP::Info; | ||
| 37 | |||
| 38 | @SNMP::Info::EDP::ISA = qw/SNMP::Info Exporter/; | ||
| 39 | @SNMP::Info::EDP::EXPORT_OK = qw//; | ||
| 40 | |||
| 41 | our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE); | ||
| 42 | |||
| 43 | $VERSION = '3.985003'; | ||
| 44 | |||
| 45 | %MIBS = ( | ||
| 46 | 'EXTREME-EDP-MIB' => 'extremeEdpPortIfIndex', | ||
| 47 | ); | ||
| 48 | |||
| 49 | %GLOBALS = ( | ||
| 50 | |||
| 51 | ); | ||
| 52 | |||
| 53 | %FUNCS = ( | ||
| 54 | # EXTREME-EDP-MIB::extremeEdpTable | ||
| 55 | 'edp_rem_sysname' => 'extremeEdpNeighborName', | ||
| 56 | ); | ||
| 57 | |||
| 58 | %MUNGE = ( | ||
| 59 | 'edp_rem_sysname' => \&SNMP::Info::munge_null, | ||
| 60 | ); | ||
| 61 | |||
| 62 | sub hasEDP { | ||
| 63 | my $edp = shift; | ||
| 64 | |||
| 65 | my $edp_ip = $edp->extremeEdpNeighborVlanIpAddress() || {}; | ||
| 66 | |||
| 67 | return 1 if ( scalar( keys %$edp_ip ) ); | ||
| 68 | |||
| 69 | return; | ||
| 70 | } | ||
| 71 | |||
| 72 | # Since we need to get IP Addresses from the extremeEdpNeighborTable which has | ||
| 73 | # a different index (adds VLAN name) than the extremeEdpTable which holds | ||
| 74 | # the remote device details use the index from extremeEdpNeighborTable but skip | ||
| 75 | # indexes which have an address of 0.0.0.0. Would like to include only one | ||
| 76 | # address since they should all originate from the same device, but we don't | ||
| 77 | # know if they would all be reachable from the network management application. | ||
| 78 | # | ||
| 79 | # We don't implement partials since this is private index function | ||
| 80 | sub _edp_index { | ||
| 81 | my $edp = shift; | ||
| 82 | |||
| 83 | my $edp_ip = $edp->extremeEdpNeighborVlanIpAddress() || {}; | ||
| 84 | |||
| 85 | my %edp_index; | ||
| 86 | foreach my $key ( keys %$edp_ip ) { | ||
| 87 | my $ip = $edp_ip->{$key}; | ||
| 88 | next if ($ip eq '0.0.0.0'); | ||
| 89 | next unless $ip; | ||
| 90 | $edp_index{$key} = $key; | ||
| 91 | } | ||
| 92 | return \%edp_index; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub edp_if { | ||
| 96 | my $edp = shift; | ||
| 97 | |||
| 98 | my $index = $edp->_edp_index() || {}; | ||
| 99 | |||
| 100 | my %edp_if; | ||
| 101 | foreach my $key (keys %$index) { | ||
| 102 | my $iid = $key; | ||
| 103 | # ifIndex is first part of the iid | ||
| 104 | $iid = $1 if $iid =~ /^(\d+)\./; | ||
| 105 | $edp_if{$key} = $iid; | ||
| 106 | } | ||
| 107 | |||
| 108 | return \%edp_if; | ||
| 109 | } | ||
| 110 | |||
| 111 | sub edp_ip { | ||
| 112 | my $edp = shift; | ||
| 113 | |||
| 114 | my $index = $edp->_edp_index() || {}; | ||
| 115 | my $edp_ip = $edp->extremeEdpNeighborVlanIpAddress() || {}; | ||
| 116 | |||
| 117 | my %edp_ip; | ||
| 118 | foreach my $key ( keys %$index ) { | ||
| 119 | my $ip = $edp_ip->{$key}; | ||
| 120 | # MIB says should only be IPv4 | ||
| 121 | next unless ($ip =~ /\d+(\.\d+){3}/); | ||
| 122 | $edp_ip{$key} = $ip; | ||
| 123 | } | ||
| 124 | return \%edp_ip; | ||
| 125 | } | ||
| 126 | |||
| 127 | sub edp_port { | ||
| 128 | my $edp = shift; | ||
| 129 | |||
| 130 | my $index = $edp->_edp_index() || {}; | ||
| 131 | my $edp_rport = $edp->extremeEdpNeighborPort() || {}; | ||
| 132 | my $edp_rslot = $edp->extremeEdpNeighborSlot() || {}; | ||
| 133 | |||
| 134 | my %edp_port; | ||
| 135 | foreach my $key ( sort keys %$edp_rport ) { | ||
| 136 | my $port = $edp_rport->{$key}; | ||
| 137 | my $slot = $edp_rslot->{$key} || 0; | ||
| 138 | next unless $port; | ||
| 139 | my $slotport = defined $slot ? "$slot\/$port" : $port; | ||
| 140 | |||
| 141 | foreach my $iid ( sort keys %$index ) { | ||
| 142 | $edp_port{$iid} = $slotport if ($iid =~ /^$key/); | ||
| 143 | } | ||
| 144 | } | ||
| 145 | return \%edp_port; | ||
| 146 | } | ||
| 147 | |||
| 148 | sub edp_id { | ||
| 149 | my $edp = shift; | ||
| 150 | |||
| 151 | my $index = $edp->_edp_index() || {}; | ||
| 152 | my $edp_name = $edp->edp_rem_sysname() || {}; | ||
| 153 | |||
| 154 | my %edp_name; | ||
| 155 | foreach my $key ( sort keys %$edp_name ) { | ||
| 156 | my $name = $edp_name->{$key} || 0; | ||
| 157 | next unless $name; | ||
| 158 | |||
| 159 | foreach my $iid ( sort keys %$index ) { | ||
| 160 | $edp_name{$iid} = $name if ($iid =~ /^$key/); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | return \%edp_name; | ||
| 164 | } | ||
| 165 | |||
| 166 | sub edp_ver { | ||
| 167 | my $edp = shift; | ||
| 168 | |||
| 169 | my $index = $edp->_edp_index() || {}; | ||
| 170 | my $edp_ver = $edp->extremeEdpNeighborSoftwareVersion() || {}; | ||
| 171 | |||
| 172 | my %edp_ver; | ||
| 173 | foreach my $key ( sort keys %$edp_ver ) { | ||
| 174 | my $ver = $edp_ver->{$key} || 0; | ||
| 175 | next unless $ver; | ||
| 176 | |||
| 177 | foreach my $iid ( sort keys %$index ) { | ||
| 178 | $edp_ver{$iid} = $ver if ($iid =~ /^$key/); | ||
| 179 | } | ||
| 180 | } | ||
| 181 | return \%edp_ver; | ||
| 182 | } | ||
| 183 | |||
| 184 | 1; | ||
| 185 | __END__ |