| 1 | # SNMP::Info::Layer3::Scalance - SNMP Interface to Siemens Scalance | ||
| 2 | # | ||
| 3 | # Copyright (c) 2019 Christoph Handel GSI Helmholtzzentrum fuer | ||
| 4 | # Schwerionenforschung | ||
| 5 | # | ||
| 6 | # Copyright (c) 2008-2009 Max Baker changes from version 0.8 and beyond. | ||
| 7 | # | ||
| 8 | # Copyright (c) 2002,2003 Regents of the University of California | ||
| 9 | # | ||
| 10 | # All rights reserved. | ||
| 11 | # | ||
| 12 | # Redistribution and use in source and binary forms, with or without | ||
| 13 | # modification, are permitted provided that the following conditions are met: | ||
| 14 | # | ||
| 15 | # * Redistributions of source code must retain the above copyright notice, | ||
| 16 | # this list of conditions and the following disclaimer. | ||
| 17 | # * Redistributions in binary form must reproduce the above copyright | ||
| 18 | # notice, this list of conditions and the following disclaimer in the | ||
| 19 | # documentation and/or other materials provided with the distribution. | ||
| 20 | # * Neither the name of the University of California, Santa Cruz , | ||
| 21 | # the GSI Helmholtzzentrum fuer Schwerionenforschung, nor the | ||
| 22 | # names of its contributors may be used to endorse or promote products | ||
| 23 | # derived from this software without specific prior written permission | ||
| 24 | # | ||
| 25 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 26 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 27 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 28 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 29 | # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 30 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 31 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 32 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 33 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 34 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 35 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 36 | # | ||
| 37 | |||
| 38 | package SNMP::Info::Layer3::Scalance; | ||
| 39 | |||
| 40 | use strict; | ||
| 41 | use warnings; | ||
| 42 | use Exporter; | ||
| 43 | use Socket; | ||
| 44 | use SNMP::Info::Layer3; | ||
| 45 | use SNMP::Info::MAU; | ||
| 46 | |||
| 47 | @SNMP::Info::Layer3::Scalance::ISA = qw/ | ||
| 48 | SNMP::Info::Layer3 | ||
| 49 | SNMP::Info::MAU | ||
| 50 | Exporter | ||
| 51 | /; | ||
| 52 | @SNMP::Info::Layer3::Scalance::EXPORT_OK = qw//; | ||
| 53 | |||
| 54 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %PORTSTAT, %MODEL_MAP, %MUNGE); | ||
| 55 | |||
| 56 | $VERSION = '3.985003'; | ||
| 57 | |||
| 58 | %MIBS = ( | ||
| 59 | %SNMP::Info::Layer3::MIBS, | ||
| 60 | %SNMP::Info::MAU::MIBS, | ||
| 61 | 'SN-MSPS-SCX-MIB' => 'snMsps', | ||
| 62 | 'AUTOMATION-SYSTEM-MIB' => 'automationManufacturerId', | ||
| 63 | ); | ||
| 64 | |||
| 65 | %GLOBALS = ( | ||
| 66 | %SNMP::Info::Layer3::GLOBALS, | ||
| 67 | %SNMP::Info::MAU::GLOBALS, | ||
| 68 | 'serial1' => 'automationSerialNumber.0', | ||
| 69 | 'ps1_status' => 'snMspsPowerSupply1State.0', | ||
| 70 | 'ps2_status' => 'snMspsPowerSupply2State.0', | ||
| 71 | 'os_ver' => 'automationSwRevision.0', | ||
| 72 | ); | ||
| 73 | |||
| 74 | %FUNCS = ( | ||
| 75 | %SNMP::Info::Layer3::FUNCS, | ||
| 76 | %SNMP::Info::MAU::FUNCS, | ||
| 77 | ); | ||
| 78 | |||
| 79 | %MUNGE = ( | ||
| 80 | # Inherit all the built in munging | ||
| 81 | %SNMP::Info::Layer3::MUNGE, | ||
| 82 | %SNMP::Info::MAU::MUNGE, | ||
| 83 | ); | ||
| 84 | |||
| 85 | sub layers { | ||
| 86 | # at least x500 reports value 72, which is layer 4+7 | ||
| 87 | # but it sure is a bridge and can do 2 and 3 | ||
| 88 | return '00000111'; | ||
| 89 | } | ||
| 90 | |||
| 91 | sub os { | ||
| 92 | return 'scalance'; | ||
| 93 | } | ||
| 94 | |||
| 95 | sub vendor { | ||
| 96 | return 'siemens'; | ||
| 97 | } | ||
| 98 | |||
| 99 | sub model { | ||
| 100 | my $scalance = shift; | ||
| 101 | # object id is only the general class (x500, x400, etc) | ||
| 102 | # extract something meaningful from the description | ||
| 103 | # my $id = $scalance->id(); | ||
| 104 | my $description = $scalance->description(); | ||
| 105 | # Siemens, SIMATIC NET, SCALANCE XR524-8C 2PS, 6GK5 524-8GS00-4AR2, HW: Version 1,... | ||
| 106 | $description =~ s/.*?(SCALANCE .*?),.*/$1/; | ||
| 107 | return $description; | ||
| 108 | } | ||
| 109 | |||
| 110 | sub mac { | ||
| 111 | # use dot1dBaseBridgeAddress | ||
| 112 | my $scalance = shift; | ||
| 113 | return $scalance->b_mac(); | ||
| 114 | } | ||
| 115 | |||
| 116 | sub os_ver { | ||
| 117 | # clean up os_ver string | ||
| 118 | my $scalance = shift; | ||
| 119 | my $result = $scalance->SUPER::os_ver(); | ||
| 120 | $result =~ s/^V//; | ||
| 121 | return $result; | ||
| 122 | } | ||
| 123 | |||
| 124 | sub i_description { | ||
| 125 | # munge interface descriptions, from | ||
| 126 | # | ||
| 127 | # Siemens, SIMATIC NET, SCALANCE XR524-8C 2PS, 6GK5 524-8GS00-4AR2, | ||
| 128 | # HW: Version 1, FW: Version V06.02.02, SERIAL, Ethernet Port, R0/S0/X1 P16 | ||
| 129 | # | ||
| 130 | # to | ||
| 131 | # | ||
| 132 | # R0/S0/X1 P16 | ||
| 133 | |||
| 134 | my $scalance = shift; | ||
| 135 | |||
| 136 | my $orig = $scalance->SUPER::i_description(); | ||
| 137 | my %result; | ||
| 138 | foreach my $iid ( keys %$orig ) { | ||
| 139 | my $descr = $orig->{$iid}; | ||
| 140 | my $short; | ||
| 141 | ($short) = $descr =~ /.*(?:Port, |VLAN, )(.*)$/; | ||
| 142 | if ( ! $short ) { | ||
| 143 | # splitting at VLAN/PORT failed, just the part after the last comma | ||
| 144 | ($short) = $descr =~ /.*, (.*)$/; | ||
| 145 | } | ||
| 146 | $result{$iid} = $short; | ||
| 147 | } | ||
| 148 | return \%result; | ||
| 149 | } | ||
| 150 | |||
| 151 | # Earlier firmware advertises no management address, so resolve the | ||
| 152 | # neighbor's system name instead. The inherited 0.0.0.0 for a MAC chassis | ||
| 153 | # ID counts as no address, so a name that resolves replaces it. | ||
| 154 | sub lldp_ip { | ||
| 155 | my $scalance = shift; | ||
| 156 | my $partial = shift; | ||
| 157 | |||
| 158 | my $lldp_ip = $scalance->SUPER::lldp_ip($partial) || {}; | ||
| 159 | my $sysnames = $scalance->lldp_rem_sysname($partial) || {}; | ||
| 160 | |||
| 161 | foreach my $key ( keys %$sysnames ) { | ||
| 162 | next unless defined $sysnames->{$key}; | ||
| 163 | next if ( $lldp_ip->{$key} // '0.0.0.0' ) ne '0.0.0.0'; | ||
| 164 | my $packed = gethostbyname( $sysnames->{$key} ); | ||
| 165 | $lldp_ip->{$key} = inet_ntoa($packed) if $packed; | ||
| 166 | } | ||
| 167 | return $lldp_ip; | ||
| 168 | } | ||
| 169 | |||
| 170 | |||
| 171 | 1; | ||
| 172 | __END__ |