| 1 | # SNMP::Info::Layer2::HP - SNMP Interface to HP ProCurve Switches | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008-2009 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::Layer2::HP; | ||
| 33 | |||
| 34 | use strict; | ||
| 35 | use warnings; | ||
| 36 | use Exporter; | ||
| 37 | use SNMP::Info::Layer3; | ||
| 38 | use SNMP::Info::MAU; | ||
| 39 | use SNMP::Info::CDP; | ||
| 40 | use SNMP::Info::Aggregate 'agg_ports_ifstack'; | ||
| 41 | |||
| 42 | @SNMP::Info::Layer2::HP::ISA = qw/ | ||
| 43 | SNMP::Info::Aggregate | ||
| 44 | SNMP::Info::Layer3 | ||
| 45 | SNMP::Info::MAU | ||
| 46 | SNMP::Info::CDP | ||
| 47 | Exporter | ||
| 48 | /; | ||
| 49 | @SNMP::Info::Layer2::HP::EXPORT_OK = qw//; | ||
| 50 | |||
| 51 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %PORTSTAT, %MODEL_MAP, %MUNGE); | ||
| 52 | |||
| 53 | $VERSION = '3.985003'; | ||
| 54 | |||
| 55 | %MIBS = ( | ||
| 56 | %SNMP::Info::Layer3::MIBS, | ||
| 57 | %SNMP::Info::MAU::MIBS, | ||
| 58 | %SNMP::Info::CDP::MIBS, | ||
| 59 | %SNMP::Info::Aggregate::MIBS, | ||
| 60 | 'RFC1271-MIB' => 'logDescription', | ||
| 61 | 'HP-ICF-OID' => 'hpSwitch4000', | ||
| 62 | 'STATISTICS-MIB' => 'hpSwitchCpuStat', | ||
| 63 | 'NETSWITCH-MIB' => 'hpMsgBufFree', | ||
| 64 | 'CONFIG-MIB' => 'hpSwitchConfig', | ||
| 65 | 'HP-ICF-CHASSIS' => 'hpicfSensorObjectId', | ||
| 66 | 'HP-ICF-BRIDGE' => 'hpicfBridgeRstpForceVersion', | ||
| 67 | 'HP-ICF-POE-MIB' => 'hpicfPoePethPsePortCurrent', | ||
| 68 | 'SEMI-MIB' => 'hpHttpMgSerialNumber', | ||
| 69 | 'HP-SWITCH-PL-MIB' => 'hpSwitchProliant', | ||
| 70 | 'BLADETYPE4-NETWORK-MIB' => 'hpProLiant-GbE2c-InterconnectSwitch', | ||
| 71 | ); | ||
| 72 | |||
| 73 | %GLOBALS = ( | ||
| 74 | %SNMP::Info::Layer3::GLOBALS, | ||
| 75 | %SNMP::Info::MAU::GLOBALS, | ||
| 76 | %SNMP::Info::CDP::GLOBALS, | ||
| 77 | %SNMP::Info::Aggregate::GLOBALS, | ||
| 78 | 'serial1' => 'entPhysicalSerialNum.1', | ||
| 79 | 'serial2' => 'hpHttpMgSerialNumber.0', | ||
| 80 | 'hp_cpu' => 'hpSwitchCpuStat.0', | ||
| 81 | 'hp_mem_total' => 'hpGlobalMemTotalBytes.1', | ||
| 82 | 'mem_free' => 'hpGlobalMemFreeBytes.1', | ||
| 83 | 'mem_used' => 'hpGlobalMemAllocBytes.1', | ||
| 84 | 'os_version' => 'hpSwitchOsVersion.0', | ||
| 85 | 'os_version2' => 'hpHttpMgVersion.0', | ||
| 86 | 'os_bin' => 'hpSwitchRomVersion.0', | ||
| 87 | 'mac' => 'hpSwitchBaseMACAddress.0', | ||
| 88 | 'rstp_ver' => 'hpicfBridgeRstpForceVersion', | ||
| 89 | ); | ||
| 90 | |||
| 91 | %FUNCS = ( | ||
| 92 | %SNMP::Info::Layer3::FUNCS, | ||
| 93 | %SNMP::Info::MAU::FUNCS, | ||
| 94 | %SNMP::Info::CDP::FUNCS, | ||
| 95 | %SNMP::Info::Aggregate::FUNCS, | ||
| 96 | 'i_type2' => 'ifType', | ||
| 97 | |||
| 98 | # RFC1271 | ||
| 99 | 'l_descr' => 'logDescription', | ||
| 100 | |||
| 101 | # CONFIG-MIB::hpSwitchPortTable | ||
| 102 | 'hp_duplex' => 'hpSwitchPortEtherMode', | ||
| 103 | 'hp_duplex_admin' => 'hpSwitchPortFastEtherMode', | ||
| 104 | 'vendor_i_type' => 'hpSwitchPortType', | ||
| 105 | |||
| 106 | # HP-ICF-CHASSIS | ||
| 107 | 'hp_s_oid' => 'hpicfSensorObjectId', | ||
| 108 | 'hp_s_name' => 'hpicfSensorDescr', | ||
| 109 | 'hp_s_status' => 'hpicfSensorStatus', | ||
| 110 | |||
| 111 | # HP-ICF-POE-MIB | ||
| 112 | 'peth_port_power' => 'hpicfPoePethPsePortPower', | ||
| 113 | ); | ||
| 114 | |||
| 115 | %MUNGE = ( | ||
| 116 | # Inherit all the built in munging | ||
| 117 | %SNMP::Info::Layer3::MUNGE, | ||
| 118 | %SNMP::Info::MAU::MUNGE, | ||
| 119 | %SNMP::Info::CDP::MUNGE, | ||
| 120 | %SNMP::Info::Aggregate::MUNGE, | ||
| 121 | 'c_id' => \&munge_hp_c_id, | ||
| 122 | ); | ||
| 123 | |||
| 124 | |||
| 125 | # Model map, reverse sorted by common model name (sort -k2 -r) | ||
| 126 | # Potential sources for model information: http://www.hp.com/rnd/software/switches.htm or HP-ICF-OID MIB | ||
| 127 | %MODEL_MAP = ( | ||
| 128 | 'Stack2930M' => '2930M Stack', | ||
| 129 | 'arubaStack2930M' => '2930M Stack', | ||
| 130 | 'J8131A' => 'WAP-420-WW', | ||
| 131 | 'J8130A' => 'WAP-420-NA', | ||
| 132 | 'J9833A' => 'PS1810-8G', | ||
| 133 | 'J9834A' => 'PS1810-24G', | ||
| 134 | 'J8133A' => 'AP520WL', | ||
| 135 | 'J8680A' => '9408sl', | ||
| 136 | 'J9091A' => '8212zl', | ||
| 137 | 'J9475A' => '8206zl', | ||
| 138 | 'J9265A' => '6600ml-24XG', | ||
| 139 | 'J9264A' => '6600ml-24G-4XG', | ||
| 140 | 'J9263A' => '6600ml-24G', | ||
| 141 | 'J9452A' => '6600-48G-4XG', | ||
| 142 | 'J9451A' => '6600-48G', | ||
| 143 | 'J8474A' => '6410cl-6XG', | ||
| 144 | 'J8433A' => '6400cl-6XG', | ||
| 145 | 'J8992A' => '6200yl-24G', | ||
| 146 | 'J4902A' => '6108', | ||
| 147 | 'J8698A' => '5412zl', | ||
| 148 | 'J9851A' => '5412R-zl2', | ||
| 149 | 'J8719A' => '5408yl', | ||
| 150 | 'J8697A' => '5406zl', | ||
| 151 | 'J9850A' => '5406R-zl2', | ||
| 152 | 'J8718A' => '5404yl', | ||
| 153 | 'J4819A' => '5308XL', | ||
| 154 | 'J4850A' => '5304XL', | ||
| 155 | 'J8773A' => '4208vl', | ||
| 156 | 'J8770A' => '4204vl', | ||
| 157 | 'J8772A' => '4202vl-72', | ||
| 158 | 'J9032A' => '4202vl-68G', | ||
| 159 | 'J9031A' => '4202vl-68', | ||
| 160 | 'J8771A' => '4202vl-48G', | ||
| 161 | 'J4865A' => '4108GL', | ||
| 162 | 'J4887A' => '4104GL', | ||
| 163 | 'JL074A' => '3810M-48G-PoE+', | ||
| 164 | 'JL072A' => '3810M-48G', | ||
| 165 | 'JL076A' => '3810M-40G-8SR-PoE+', | ||
| 166 | 'JL073A' => '3810M-24G-PoE+', | ||
| 167 | 'JL071A' => '3810M-24G', | ||
| 168 | 'JL075A' => '3810M-16SFP+', | ||
| 169 | 'JL077A' => '3810M-16SR-PoE+', | ||
| 170 | 'J9588A' => '3800-48G-PoE+-4XG', | ||
| 171 | 'J9574A' => '3800-48G-PoE+-4SFP+', | ||
| 172 | 'J9586A' => '3800-48G-4XG', | ||
| 173 | 'J9576A' => '3800-48G-4SFP+', | ||
| 174 | 'J9584A' => '3800-24SFP-2SFP+', | ||
| 175 | 'J9587A' => '3800-24G-PoE+-2XG', | ||
| 176 | 'J9573A' => '3800-24G-PoE+-2SFP+', | ||
| 177 | 'J9585A' => '3800-24G-2XG', | ||
| 178 | 'J9575A' => '3800-24G-2SFP+', | ||
| 179 | 'J8693A' => '3500yl-48G-PWR', | ||
| 180 | 'J8692A' => '3500yl-24G-PWR', | ||
| 181 | 'J9473A' => '3500-48-PoE', | ||
| 182 | 'J9472A' => '3500-48', | ||
| 183 | 'J9471A' => '3500-24-PoE', | ||
| 184 | 'J9470A' => '3500-24', | ||
| 185 | 'J4906A' => '3400cl-48G', | ||
| 186 | 'J4905A' => '3400cl-24G', | ||
| 187 | 'J4815A' => '3324XL', | ||
| 188 | 'J4851A' => '3124', | ||
| 189 | 'JL322A' => '2930M-48G-PoE+', | ||
| 190 | 'JL321A' => '2930M-48G', | ||
| 191 | 'JL323A' => '2930M-40G-8SR-PoE+', | ||
| 192 | 'R0M67A' => '2930M-40G-8SR-PoE-Class6', | ||
| 193 | 'R0M68A' => '2930M-24SR-PoE-Class6', | ||
| 194 | 'JL320A' => '2930M-24G-PoE+', | ||
| 195 | 'JL324A' => '2930M-24G-8SR-PoE+', | ||
| 196 | 'JL319A' => '2930M-24G', | ||
| 197 | 'JL258A' => '2930F-8G-PoE+-2SFP+', | ||
| 198 | 'JL692A' => '2930F-8G-PoE+-2SFP+-TAA', | ||
| 199 | 'JL693A' => '2930F-12G-PoE+-2G-2SFP+', | ||
| 200 | 'JL558A' => '2930F-48G-PoE+-4SFP+-740W', | ||
| 201 | 'JL559A' => '2930F-48G-PoE+-4SFP+-740W-TAA', | ||
| 202 | 'JL557A' => '2930F-48G-PoE+-4SFP-740W', | ||
| 203 | 'JL256A' => '2930F-48G-PoE+-4SFP+', | ||
| 204 | 'JL264A' => '2930F-48G-PoE+-4SFP+-TAA', | ||
| 205 | 'JL262A' => '2930F-48G-PoE+-4SFP', | ||
| 206 | 'JL254A' => '2930F-48G-4SFP+', | ||
| 207 | 'JL260A' => '2930F-48G-4SFP', | ||
| 208 | 'JL255A' => '2930F-24G-PoE+-4SFP+', | ||
| 209 | 'JL263A' => '2930F-24G-PoE+-4SFP+-TAA', | ||
| 210 | 'JL261A' => '2930F-24G-PoE+-4SFP', | ||
| 211 | 'JL253A' => '2930F-24G-4SFP+', | ||
| 212 | 'JL259A' => '2930F-24G-4SFP', | ||
| 213 | 'J9729A' => '2920-48G-PoE+', | ||
| 214 | 'J9729A' => '2920-48G-PoE+', | ||
| 215 | 'J9728A' => '2920-48G', | ||
| 216 | 'J9728A' => '2920-48G', | ||
| 217 | 'J9727A' => '2920-24G-PoE+', | ||
| 218 | 'J9727A' => '2920-24G-PoE+', | ||
| 219 | 'J9726A' => '2920-24G', | ||
| 220 | 'J9726A' => '2920-24G', | ||
| 221 | 'J9562A' => '2915-8G-PoE', | ||
| 222 | 'J9148A' => '2910al-48G-PoE+', | ||
| 223 | 'J9147A' => '2910al-48G', | ||
| 224 | 'J9146A' => '2910al-24G-PoE+', | ||
| 225 | 'J9145A' => '2910al-24G', | ||
| 226 | 'J9050A' => '2900-48G', | ||
| 227 | 'J9049A' => '2900-24G', | ||
| 228 | 'J4904A' => '2848', | ||
| 229 | 'J4903A' => '2824', | ||
| 230 | 'J9022A' => '2810-48G', | ||
| 231 | 'J9021A' => '2810-24G', | ||
| 232 | 'J8165A' => '2650-PWR', | ||
| 233 | 'J4899B' => '2650-CR', | ||
| 234 | 'J4899C' => '2650C', | ||
| 235 | 'J4899A' => '2650', | ||
| 236 | 'J8164A' => '2626-PWR', | ||
| 237 | 'J4900B' => '2626-CR', | ||
| 238 | 'J4900C' => '2626C', | ||
| 239 | 'J4900A' => '2626', | ||
| 240 | 'J9627A' => '2620-48-PoE+', | ||
| 241 | 'J9626A' => '2620-48', | ||
| 242 | 'J9624A' => '2620-24-PPoE+', | ||
| 243 | 'J9625A' => '2620-24-PoE+', | ||
| 244 | 'J9623A' => '2620-24', | ||
| 245 | 'J9565A' => '2615-8-PoE', | ||
| 246 | 'J9089A' => '2610-48-PWR', | ||
| 247 | 'J9088A' => '2610-48', | ||
| 248 | 'J9087A' => '2610-24-PWR', | ||
| 249 | 'J9086A' => '2610-24/12PWR', | ||
| 250 | 'J9085A' => '2610-24', | ||
| 251 | 'J8762A' => '2600-8-PWR', | ||
| 252 | 'JL357A' => '2540-48G-PoE+-4SFP+', | ||
| 253 | 'JL355A' => '2540-48G-4SFP+', | ||
| 254 | 'JL356A' => '2540-24G-PoE+-4SFP+', | ||
| 255 | 'JL354A' => '2540-24G-4SFP+', | ||
| 256 | 'JL070A' => '2530-8-PoE+ Internal PS', | ||
| 257 | 'J9780A' => '2530-8-PoE+', | ||
| 258 | 'J9774A' => '2530-8G-PoEP', | ||
| 259 | 'J9777A' => '2530-8G', | ||
| 260 | 'J9783A' => '2530-8', | ||
| 261 | 'J9778A' => '2530-48-PoE+', | ||
| 262 | 'J9853A' => '2530-48G-PoE+-2SFP+', | ||
| 263 | 'J9772A' => '2530-48G-PoE+', | ||
| 264 | 'J9855A' => '2530-48G-2SFP+', | ||
| 265 | 'J9775A' => '2530-48G', | ||
| 266 | 'J9781A' => '2530-48', | ||
| 267 | 'J9779A' => '2530-24-PoE+', | ||
| 268 | 'J9854A' => '2530-24G-PoE+-2SFP+', | ||
| 269 | 'J9773A' => '2530-24G-PoE+', | ||
| 270 | 'J9856A' => '2530-24G-2SFP+', | ||
| 271 | 'J9776A' => '2530-24G', | ||
| 272 | 'J9782A' => '2530-24', | ||
| 273 | 'J4813A' => '2524', | ||
| 274 | 'J9298A' => '2520G-8-PoE', | ||
| 275 | 'J9299A' => '2520G-24-PoE', | ||
| 276 | 'J9137A' => '2520-8-PoE', | ||
| 277 | 'J9138A' => '2520-24-PoE', | ||
| 278 | 'J4812A' => '2512', | ||
| 279 | 'J9280A' => '2510G-48', | ||
| 280 | 'J9279A' => '2510G-24', | ||
| 281 | 'J9020A' => '2510-48A', | ||
| 282 | 'J9019B' => '2510-24B', | ||
| 283 | 'J9019A' => '2510-24A', | ||
| 284 | 'J4818A' => '2324', | ||
| 285 | 'J4817A' => '2312', | ||
| 286 | 'J9449A' => '1810G-8', | ||
| 287 | 'J9450A' => '1810G-24', | ||
| 288 | 'J9802A' => '1810-8G', | ||
| 289 | 'J9803A' => '1810-24G', | ||
| 290 | 'J9029A' => '1800-8G', | ||
| 291 | 'J9028A' => '1800-24G', | ||
| 292 | ); | ||
| 293 | |||
| 294 | # Method Overrides | ||
| 295 | |||
| 296 | sub stp_ver { | ||
| 297 | my $hp = shift; | ||
| 298 | return $hp->rstp_ver() || $hp->SUPER::stp_ver(); | ||
| 299 | } | ||
| 300 | |||
| 301 | sub cpu { | ||
| 302 | my $hp = shift; | ||
| 303 | return $hp->hp_cpu(); | ||
| 304 | } | ||
| 305 | |||
| 306 | sub mem_total { | ||
| 307 | my $hp = shift; | ||
| 308 | return $hp->hp_mem_total(); | ||
| 309 | } | ||
| 310 | |||
| 311 | sub os { | ||
| 312 | return 'hp'; | ||
| 313 | } | ||
| 314 | |||
| 315 | sub os_ver { | ||
| 316 | my $hp = shift; | ||
| 317 | my $os_version = $hp->os_version() || $hp->os_version2(); | ||
| 318 | return $os_version if defined $os_version; | ||
| 319 | |||
| 320 | # Some older ones don't have this value,so we cull it from the description | ||
| 321 | my $descr = $hp->description(); | ||
| 322 | if ( $descr =~ m/revision ([A-Z]{1}\.\d{2}\.\d{2})/ ) { | ||
| 323 | return $1; | ||
| 324 | } | ||
| 325 | return; | ||
| 326 | } | ||
| 327 | |||
| 328 | # Regular managed ProCurve switches have the serial num in entity mib, | ||
| 329 | # the web-managed models in the semi mib (hphttpmanageable). | ||
| 330 | sub serial { | ||
| 331 | my $hp = shift; | ||
| 332 | |||
| 333 | my $serial = $hp->serial1() || $hp->serial2() || undef;; | ||
| 334 | |||
| 335 | return $serial; | ||
| 336 | } | ||
| 337 | |||
| 338 | # Lookup model number, and translate the part number to the common number | ||
| 339 | sub model { | ||
| 340 | my $hp = shift; | ||
| 341 | my $id = $hp->id(); | ||
| 342 | return unless defined $id; | ||
| 343 | my $model = &SNMP::translateObj($id); | ||
| 344 | return $id unless defined $model; | ||
| 345 | |||
| 346 | $model =~ s/^(?:hpSwitch|arubaSwitch|aruba(?=JL\d))//i; | ||
| 347 | |||
| 348 | return defined $MODEL_MAP{$model} ? $MODEL_MAP{$model} : $model; | ||
| 349 | } | ||
| 350 | |||
| 351 | sub interfaces { | ||
| 352 | my $hp = shift; | ||
| 353 | my $interfaces = $hp->i_index(); | ||
| 354 | my $i_descr = $hp->i_description(); | ||
| 355 | |||
| 356 | my %if; | ||
| 357 | foreach my $iid ( keys %$interfaces ) { | ||
| 358 | my $descr = $i_descr->{$iid}; | ||
| 359 | next unless defined $descr; | ||
| 360 | $if{$iid} = $descr if ( defined $descr and length $descr ); | ||
| 361 | } | ||
| 362 | |||
| 363 | return \%if | ||
| 364 | |||
| 365 | } | ||
| 366 | |||
| 367 | sub i_name { | ||
| 368 | my $hp = shift; | ||
| 369 | my $i_alias = $hp->i_alias(); | ||
| 370 | my $e_name = $hp->e_name(); | ||
| 371 | my $e_port = $hp->e_port(); | ||
| 372 | |||
| 373 | my %i_name; | ||
| 374 | |||
| 375 | foreach my $port ( keys %$e_name ) { | ||
| 376 | my $iid = $e_port->{$port}; | ||
| 377 | next unless defined $iid; | ||
| 378 | my $alias = $i_alias->{$iid}; | ||
| 379 | next unless defined $iid; | ||
| 380 | $i_name{$iid} = $e_name->{$port}; | ||
| 381 | |||
| 382 | # Check for alias | ||
| 383 | $i_name{$iid} = $alias if ( defined $alias and length($alias) ); | ||
| 384 | } | ||
| 385 | |||
| 386 | return \%i_name; | ||
| 387 | } | ||
| 388 | |||
| 389 | sub i_duplex { | ||
| 390 | my $hp = shift; | ||
| 391 | |||
| 392 | return $hp->mau_i_duplex(); | ||
| 393 | } | ||
| 394 | |||
| 395 | sub i_duplex_admin { | ||
| 396 | my $hp = shift; | ||
| 397 | my $partial = shift; | ||
| 398 | |||
| 399 | # Try HP MIB first | ||
| 400 | my $hp_duplex = $hp->hp_duplex_admin($partial); | ||
| 401 | if ( defined $hp_duplex and scalar( keys %$hp_duplex ) ) { | ||
| 402 | |||
| 403 | my %i_duplex; | ||
| 404 | foreach my $if ( keys %$hp_duplex ) { | ||
| 405 | my $duplex = $hp_duplex->{$if}; | ||
| 406 | next unless defined $duplex; | ||
| 407 | |||
| 408 | $duplex = 'half' if $duplex =~ /half/i; | ||
| 409 | $duplex = 'full' if $duplex =~ /full/i; | ||
| 410 | $duplex = 'auto' if $duplex =~ /auto/i; | ||
| 411 | $i_duplex{$if} = $duplex; | ||
| 412 | } | ||
| 413 | return \%i_duplex; | ||
| 414 | } | ||
| 415 | else { | ||
| 416 | return $hp->mau_i_duplex_admin(); | ||
| 417 | } | ||
| 418 | } | ||
| 419 | |||
| 420 | sub vendor { | ||
| 421 | return 'hp'; | ||
| 422 | } | ||
| 423 | |||
| 424 | sub log { | ||
| 425 | my $hp = shift; | ||
| 426 | |||
| 427 | my $log = $hp->l_descr(); | ||
| 428 | |||
| 429 | my $logstring = undef; | ||
| 430 | |||
| 431 | foreach my $val ( values %$log ) { | ||
| 432 | next if $val =~ /^Link\s+(Up|Down)/; | ||
| 433 | $logstring .= "$val\n"; | ||
| 434 | } | ||
| 435 | |||
| 436 | return $logstring; | ||
| 437 | } | ||
| 438 | |||
| 439 | sub slots { | ||
| 440 | my $hp = shift; | ||
| 441 | |||
| 442 | my $e_name = $hp->e_name(); | ||
| 443 | |||
| 444 | return unless defined $e_name; | ||
| 445 | |||
| 446 | my $slots; | ||
| 447 | foreach my $slot ( keys %$e_name ) { | ||
| 448 | $slots++ if $e_name->{$slot} =~ /slot/i; | ||
| 449 | } | ||
| 450 | |||
| 451 | return $slots; | ||
| 452 | } | ||
| 453 | |||
| 454 | sub fan { | ||
| 455 | my $hp = shift; | ||
| 456 | return &_sensor( $hp, 'fan' ); | ||
| 457 | } | ||
| 458 | |||
| 459 | sub ps1_status { | ||
| 460 | my $hp = shift; | ||
| 461 | return &_sensor( $hp, 'power', '^power supply 1' ) | ||
| 462 | || &_sensor( $hp, 'power', '^power supply sensor' ); | ||
| 463 | } | ||
| 464 | |||
| 465 | sub ps2_status { | ||
| 466 | my $hp = shift; | ||
| 467 | return &_sensor( $hp, 'power', '^power supply 2' ) | ||
| 468 | || &_sensor( $hp, 'power', '^redundant' ); | ||
| 469 | } | ||
| 470 | |||
| 471 | sub _sensor { | ||
| 472 | my $hp = shift; | ||
| 473 | my $search_type = shift || 'fan'; | ||
| 474 | my $search_name = shift || ''; | ||
| 475 | my $hp_s_oid = $hp->hp_s_oid(); | ||
| 476 | my $result; | ||
| 477 | foreach my $sensor ( keys %$hp_s_oid ) { | ||
| 478 | my $sensortype = &SNMP::translateObj( $hp_s_oid->{$sensor} ); | ||
| 479 | if ( $sensortype =~ /$search_type/i ) { | ||
| 480 | my $sensorname = $hp->hp_s_name()->{$sensor}; | ||
| 481 | my $sensorstatus = $hp->hp_s_status()->{$sensor}; | ||
| 482 | if ( $sensorname =~ /$search_name/i ) { | ||
| 483 | $result = $sensorstatus; | ||
| 484 | } | ||
| 485 | } | ||
| 486 | } | ||
| 487 | return $result; | ||
| 488 | } | ||
| 489 | |||
| 490 | sub munge_hp_c_id { | ||
| 491 | my ($v) = @_; | ||
| 492 | if ( length(unpack('H*', $v)) == 12 ){ | ||
| 493 | return join(':',map { sprintf "%02x", $_ } unpack('C*', $v)); | ||
| 494 | }if ( length(unpack('H*', $v)) == 10 ){ | ||
| 495 | # IP address (first octet is sign, I guess) | ||
| 496 | my @octets = (map { sprintf "%02x",$_ } unpack('C*', $v))[1..4]; | ||
| 497 | return join '.', map { hex($_) } @octets; | ||
| 498 | }else{ | ||
| 499 | return $v; | ||
| 500 | } | ||
| 501 | } | ||
| 502 | |||
| 503 | # POWER-ETHERNET-MIB doesn't define a mapping of its | ||
| 504 | # "module"/"port" index to ifIndex. Different vendors | ||
| 505 | # do this in different ways. | ||
| 506 | # HP switches use the ifIndex as port index, so we can | ||
| 507 | # ignore the module information and map the index directly | ||
| 508 | # onto an ifIndex. | ||
| 509 | sub peth_port_ifindex { | ||
| 510 | my $peth = shift; | ||
| 511 | my $partial = shift; | ||
| 512 | |||
| 513 | my $peth_port_status = $peth->peth_port_status($partial); | ||
| 514 | my $peth_port_ifindex; | ||
| 515 | |||
| 516 | foreach my $i ( keys %$peth_port_status ) { | ||
| 517 | my ( $module, $port ) = split( /\./, $i ); | ||
| 518 | $peth_port_ifindex->{$i} = $port; | ||
| 519 | } | ||
| 520 | return $peth_port_ifindex; | ||
| 521 | } | ||
| 522 | |||
| 523 | sub set_i_vlan { | ||
| 524 | my $hp = shift; | ||
| 525 | my $rv; | ||
| 526 | |||
| 527 | my $qb_i_vlan = $hp->qb_i_vlan_t(); | ||
| 528 | if (defined $qb_i_vlan and scalar(keys %$qb_i_vlan)){ | ||
| 529 | my $vlan = shift; | ||
| 530 | my $iid = shift; | ||
| 531 | |||
| 532 | my $qb_v_egress = $hp->qb_v_egress(); | ||
| 533 | if (defined $qb_v_egress and scalar($qb_v_egress->{$vlan})) { | ||
| 534 | # store current untagged VLAN to remove it from the port list later | ||
| 535 | my $old_untagged = $qb_i_vlan->{$iid}; | ||
| 536 | |||
| 537 | # set new untagged / native VLAN | ||
| 538 | $rv = $hp->set_qb_i_vlan($vlan, $iid); | ||
| 539 | |||
| 540 | # If change is successful, the old native VLAN will now be a tagged VLAN on the port. This is generally not what we want. | ||
| 541 | # We'll have to remove this VLAN from the "egress list" on the port. | ||
| 542 | if (defined $rv and $old_untagged != $vlan) { | ||
| 543 | if (defined $old_untagged and defined $qb_v_egress and scalar($qb_v_egress->{$vlan})){ | ||
| 544 | |||
| 545 | # First, get the egress list of the old native VLAN (arrayref structure) | ||
| 546 | my $egressports = $qb_v_egress->{$old_untagged}; | ||
| 547 | |||
| 548 | # Since arrays are zero-based, we have to change the element at Index - 1 | ||
| 549 | $egressports->[$iid-1] = "0"; | ||
| 550 | |||
| 551 | # After changing, pack the array into a binary structure (expected by set_qb_v_egress) and set the new value on the device. | ||
| 552 | my $new_egresslist = pack("B*", join('', @$egressports)); | ||
| 553 | |||
| 554 | $rv = $hp->set_qb_v_egress($new_egresslist, $old_untagged); | ||
| 555 | } | ||
| 556 | } | ||
| 557 | } else { | ||
| 558 | $hp->error_throw(sprintf("Requested VLAN %s doesn't seem to exist on device...", $vlan)); | ||
| 559 | } | ||
| 560 | } | ||
| 561 | return $rv; | ||
| 562 | } | ||
| 563 | |||
| 564 | sub set_i_vlan_tagged { | ||
| 565 | my $hp = shift; | ||
| 566 | my $rv; | ||
| 567 | |||
| 568 | my $qb_i_vlan = $hp->qb_i_vlan_t(); | ||
| 569 | if (defined $qb_i_vlan and scalar(keys %$qb_i_vlan)){ | ||
| 570 | my $vlan = shift; | ||
| 571 | my $iid = shift; | ||
| 572 | |||
| 573 | my $qb_v_egress = $hp->qb_v_egress(); | ||
| 574 | if (defined $qb_v_egress and scalar($qb_v_egress->{$vlan})) { | ||
| 575 | |||
| 576 | # First, get the egress list of the VLAN we want to add to the port. | ||
| 577 | my $egressports = $qb_v_egress->{$vlan}; | ||
| 578 | |||
| 579 | # Since arrays are zero-based, we have to change the element at Index - 1 | ||
| 580 | $egressports->[$iid-1] = "1"; | ||
| 581 | |||
| 582 | # After changing, pack the array into a binary structure (expected by set_qb_v_egress) and set the new value on the device. | ||
| 583 | my $new_egresslist = pack("B*", join('', @$egressports)); | ||
| 584 | $rv = $hp->set_qb_v_egress($new_egresslist, $vlan); | ||
| 585 | return $rv; | ||
| 586 | } else { | ||
| 587 | $hp->error_throw(sprintf("Requested VLAN %s doesn't seem to exist on device...", $vlan)); | ||
| 588 | } | ||
| 589 | } | ||
| 590 | return; | ||
| 591 | } | ||
| 592 | |||
| 593 | sub agg_ports { return agg_ports_ifstack(@_) } | ||
| 594 | |||
| 595 | sub _agg_ports_walked { return qw/ifStackStatus ifType/ } | ||
| 596 | |||
| 597 | 1; | ||
| 598 | __END__ |