| 1 | # SNMP::Info::Layer1 - SNMP Interface to Layer1 Devices | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008 Max Baker changes from version 0.8 and beyond. | ||
| 4 | # | ||
| 5 | # Copyright (c) 2002,2003 Regents of the University of California | ||
| 6 | # All rights reserved. | ||
| 7 | # | ||
| 8 | # Redistribution and use in source and binary forms, with or without | ||
| 9 | # modification, are permitted provided that the following conditions are met: | ||
| 10 | # | ||
| 11 | # * Redistributions of source code must retain the above copyright notice, | ||
| 12 | # this list of conditions and the following disclaimer. | ||
| 13 | # * Redistributions in binary form must reproduce the above copyright | ||
| 14 | # notice, this list of conditions and the following disclaimer in the | ||
| 15 | # documentation and/or other materials provided with the distribution. | ||
| 16 | # * Neither the name of the University of California, Santa Cruz nor the | ||
| 17 | # names of its contributors may be used to endorse or promote products | ||
| 18 | # derived from this software without specific prior written permission. | ||
| 19 | # | ||
| 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 21 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 22 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 24 | # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 25 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 26 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 27 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 28 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 29 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 30 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 31 | |||
| 32 | package SNMP::Info::Layer1; | ||
| 33 | |||
| 34 | use strict; | ||
| 35 | use warnings; | ||
| 36 | use Exporter; | ||
| 37 | use SNMP::Info; | ||
| 38 | |||
| 39 | @SNMP::Info::Layer1::ISA = qw/SNMP::Info Exporter/; | ||
| 40 | @SNMP::Info::Layer1::EXPORT_OK = qw//; | ||
| 41 | |||
| 42 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %PORTSTAT, %MUNGE); | ||
| 43 | |||
| 44 | $VERSION = '3.985003'; | ||
| 45 | |||
| 46 | %MIBS = ( %SNMP::Info::MIBS, 'SNMP-REPEATER-MIB' => 'rptrPortGroupIndex' ); | ||
| 47 | |||
| 48 | %GLOBALS = ( | ||
| 49 | %SNMP::Info::GLOBALS, | ||
| 50 | 'ports_managed' => 'ifNumber', | ||
| 51 | 'rptr_slots' => 'rptrGroupCapacity', | ||
| 52 | 'slots' => 'rptrGroupCapacity', | ||
| 53 | ); | ||
| 54 | |||
| 55 | %FUNCS = ( | ||
| 56 | %SNMP::Info::FUNCS, | ||
| 57 | 'rptr_ports' => 'rptrGroupPortCapacity', | ||
| 58 | 'rptr_port' => 'rptrPortIndex', | ||
| 59 | 'rptr_slot' => 'rptrPortGroupIndex', | ||
| 60 | 'rptr_up_admin' => 'rptrPortAdminStatus', | ||
| 61 | 'rptr_up' => 'rptrPortOperStatus', | ||
| 62 | 'rptr_last_src' => 'rptrAddrTrackNewLastSrcAddress', | ||
| 63 | ); | ||
| 64 | |||
| 65 | %MUNGE = ( | ||
| 66 | |||
| 67 | # Inherit all the built in munging | ||
| 68 | %SNMP::Info::MUNGE, | ||
| 69 | 'rptr_last_src' => \&SNMP::Info::munge_mac, | ||
| 70 | ); | ||
| 71 | |||
| 72 | # Method OverRides | ||
| 73 | |||
| 74 | # assuming managed ports aren't in repeater ports? | ||
| 75 | sub ports { | ||
| 76 | my $l1 = shift; | ||
| 77 | |||
| 78 | my $ports = $l1->ports_managed(); | ||
| 79 | my $rptr_ports = $l1->rptr_ports(); | ||
| 80 | |||
| 81 | foreach my $group ( keys %$rptr_ports ) { | ||
| 82 | $ports += $rptr_ports->{$group}; | ||
| 83 | } | ||
| 84 | |||
| 85 | return $ports; | ||
| 86 | } | ||
| 87 | |||
| 88 | # $l1->model() - Looks at sysObjectID which gives the oid of the system | ||
| 89 | # name, contained in a proprietary MIB. | ||
| 90 | sub model { | ||
| 91 | my $l1 = shift; | ||
| 92 | my $id = $l1->id(); | ||
| 93 | my $model = &SNMP::translateObj($id); | ||
| 94 | |||
| 95 | # HP | ||
| 96 | $model =~ s/^hpswitch//i; | ||
| 97 | |||
| 98 | # Cisco | ||
| 99 | $model =~ s/sysid$//i; | ||
| 100 | |||
| 101 | return $model; | ||
| 102 | } | ||
| 103 | |||
| 104 | sub vendor { | ||
| 105 | my $l1 = shift; | ||
| 106 | my $descr = $l1->description(); | ||
| 107 | |||
| 108 | return 'hp' if ( $descr =~ /hp/i ); | ||
| 109 | return 'cisco' if ( $descr =~ /(catalyst|cisco|ios)/i ); | ||
| 110 | return 'allied' if ( $descr =~ /allied/i ); | ||
| 111 | return 'asante' if ( $descr =~ /asante/i ); | ||
| 112 | |||
| 113 | return 'unknown'; | ||
| 114 | |||
| 115 | } | ||
| 116 | |||
| 117 | # By Default we'll use the description field | ||
| 118 | sub interfaces { | ||
| 119 | my $l1 = shift; | ||
| 120 | my $partial = shift; | ||
| 121 | |||
| 122 | my $interfaces = $l1->i_index($partial) || {}; | ||
| 123 | my $rptr_port = $l1->rptr_port($partial) || {}; | ||
| 124 | |||
| 125 | foreach my $port ( keys %$rptr_port ) { | ||
| 126 | $interfaces->{$port} = $port; | ||
| 127 | } | ||
| 128 | return $interfaces; | ||
| 129 | } | ||
| 130 | |||
| 131 | sub i_up_admin { | ||
| 132 | my $l1 = shift; | ||
| 133 | my $partial = shift; | ||
| 134 | |||
| 135 | my $i_up_admin = $l1->SUPER::i_up_admin($partial) || {}; | ||
| 136 | my $rptr_up_admin = $l1->rptr_up_admin($partial) || {}; | ||
| 137 | |||
| 138 | foreach my $key ( keys %$rptr_up_admin ) { | ||
| 139 | my $up = $rptr_up_admin->{$key}; | ||
| 140 | $i_up_admin->{$key} = 'up' if $up =~ /enabled/; | ||
| 141 | $i_up_admin->{$key} = 'down' if $up =~ /disabled/; | ||
| 142 | } | ||
| 143 | |||
| 144 | return $i_up_admin; | ||
| 145 | } | ||
| 146 | |||
| 147 | sub i_up { | ||
| 148 | my $l1 = shift; | ||
| 149 | my $partial = shift; | ||
| 150 | |||
| 151 | my $i_up = $l1->SUPER::i_up($partial) || {}; | ||
| 152 | my $rptr_up = $l1->rptr_up($partial) || {}; | ||
| 153 | |||
| 154 | foreach my $key ( keys %$rptr_up ) { | ||
| 155 | my $up = $rptr_up->{$key}; | ||
| 156 | $i_up->{$key} = 'up' if $up =~ /operational/; | ||
| 157 | } | ||
| 158 | |||
| 159 | return $i_up; | ||
| 160 | } | ||
| 161 | |||
| 162 | 1; | ||
| 163 | __END__ |