| 1 | # SNMP::Info::Layer3::Altiga | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008 Jeroen van Ingen Schenau | ||
| 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::Layer3::Altiga; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use warnings; | ||
| 34 | use Exporter; | ||
| 35 | use SNMP::Info::Layer3; | ||
| 36 | |||
| 37 | @SNMP::Info::Layer3::Altiga::ISA = qw/SNMP::Info::Layer3 Exporter/; | ||
| 38 | @SNMP::Info::Layer3::Altiga::EXPORT_OK = qw//; | ||
| 39 | |||
| 40 | our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE, | ||
| 41 | $int_include_vpn, $fake_idx, $type_class); | ||
| 42 | |||
| 43 | $VERSION = '3.985003'; | ||
| 44 | |||
| 45 | %MIBS = ( | ||
| 46 | %SNMP::Info::Layer3::MIBS, | ||
| 47 | 'ALTIGA-VERSION-STATS-MIB' => 'alVersionString', | ||
| 48 | 'ALTIGA-SESSION-STATS-MIB' => 'alActiveSessionCount', | ||
| 49 | 'ALTIGA-HARDWARE-STATS-MIB' => 'alHardwarePs1Type', | ||
| 50 | ); | ||
| 51 | |||
| 52 | %GLOBALS = ( | ||
| 53 | %SNMP::Info::Layer3::GLOBALS, | ||
| 54 | # From ALTIGA-VERSION-STATS-MIB | ||
| 55 | 'os_ver' => 'alVersionString', | ||
| 56 | # From ALTIGA-SESSION-STATS-MIB | ||
| 57 | 'vpn_act_sess' => 'alActiveSessionCount', | ||
| 58 | 'vpn_total_sess' => 'alTotalSessionCount', | ||
| 59 | 'vpn_max_sess' => 'alMaxSessionCount', | ||
| 60 | 'vpn_l2l_sess' => 'alActiveLanToLanSessionCount', | ||
| 61 | 'vpn_mgmt_sess' => 'alActiveManagementSessionCount', | ||
| 62 | 'vpn_ras_sess' => 'alActiveRemoteAccessSessionCount', | ||
| 63 | # From ALTIGA-HARDWARE-STATS-MIB | ||
| 64 | 'ps1_type' => 'alHardwarePs1Type', | ||
| 65 | 'ps1_3v_alarm' => 'alHardwarePs1Voltage3vAlarm', | ||
| 66 | 'ps1_5v_alarm' => 'alHardwarePs1Voltage5vAlarm', | ||
| 67 | 'ps2_type' => 'alHardwarePs2Type', | ||
| 68 | 'ps2_3v_alarm' => 'alHardwarePs2Voltage3vAlarm', | ||
| 69 | 'ps2_5v_alarm' => 'alHardwarePs2Voltage5vAlarm', | ||
| 70 | 'fan1_alarm' => 'alHardwareFan1RpmAlarm', | ||
| 71 | 'fan2_alarm' => 'alHardwareFan2RpmAlarm', | ||
| 72 | 'fan3_alarm' => 'alHardwareFan3RpmAlarm', | ||
| 73 | |||
| 74 | ); | ||
| 75 | |||
| 76 | %FUNCS = ( | ||
| 77 | %SNMP::Info::Layer3::FUNCS, | ||
| 78 | 'i_type2' => 'ifType', | ||
| 79 | 'i_lastchange2' => 'ifLastChange', | ||
| 80 | 'vpn_sess_status' => 'alActiveSessionRowStatus', | ||
| 81 | 'vpn_sess_user' => 'alActiveSessionUserName', | ||
| 82 | 'vpn_sess_peer_ip' => 'alActiveSessionIpAddress', | ||
| 83 | 'vpn_sess_protocol' => 'alActiveSessionProtocol', | ||
| 84 | 'vpn_sess_encr' => 'alActiveSessionEncrType', | ||
| 85 | 'vpn_sess_start' => 'alActiveSessionStartTime', | ||
| 86 | 'vpn_sess_conntime' => 'alActiveSessionConnectTime', | ||
| 87 | 'vpn_sess_out_oct' => 'alActiveSessionOctetsSent', | ||
| 88 | 'vpn_sess_in_oct' => 'alActiveSessionOctetsRcvd', | ||
| 89 | 'vpn_sess_group' => 'alActiveSessionGroupName', | ||
| 90 | 'vpn_sess_gid' => 'alActiveSessionGroupId', | ||
| 91 | 'vpn_sess_rem_ip' => 'alActiveSessionPublicIpAddress', | ||
| 92 | ); | ||
| 93 | |||
| 94 | %MUNGE = ( | ||
| 95 | %SNMP::Info::Layer3::MUNGE, | ||
| 96 | 'ps1_3v_alarm' => \&munge_alarm, | ||
| 97 | 'ps1_5v_alarm' => \&munge_alarm, | ||
| 98 | 'ps2_3v_alarm' => \&munge_alarm, | ||
| 99 | 'ps2_5v_alarm' => \&munge_alarm, | ||
| 100 | 'fan1_alarm' => \&munge_alarm, | ||
| 101 | 'fan2_alarm' => \&munge_alarm, | ||
| 102 | 'fan3_alarm' => \&munge_alarm, | ||
| 103 | |||
| 104 | ); | ||
| 105 | |||
| 106 | # Variable to modify behaviour of "interfaces" subroutine. | ||
| 107 | # * When set to 0, "interfaces" returns only fixed interfaces from the IF-MIB, | ||
| 108 | # * When set to 1, "interfaces" returns fixed interfaces from IF-MIB and LAN-to-LAN tunnels from ALTIGA-SESSION-MIB | ||
| 109 | # TODO: This should be an instance method, not a class global | ||
| 110 | $int_include_vpn = 1; | ||
| 111 | |||
| 112 | # Variable to prepended to each tunnel index when tunnel is added to %interfaces, to avoid overwriting "real" ifIndex entries | ||
| 113 | $fake_idx = 3076; | ||
| 114 | |||
| 115 | # Variable to classify session types into categories: 0 - unclassified, 1 - LAN-to-LAN or fixed, 2 - RAS or dynamic, 3 - administrative | ||
| 116 | $type_class = { | ||
| 117 | 'pptp' => 2, | ||
| 118 | 'l2tp' => 2, | ||
| 119 | 'ipsec' => 2, | ||
| 120 | 'http' => 3, | ||
| 121 | 'ftp' => 3, | ||
| 122 | 'telnet' => 3, | ||
| 123 | 'snmp' => 3, | ||
| 124 | 'tftp' => 3, | ||
| 125 | 'console' => 3, | ||
| 126 | 'debugTelnet' => 3, | ||
| 127 | 'debugConsole' => 3, | ||
| 128 | 'other' => 3, | ||
| 129 | 'ike' => 0, | ||
| 130 | 'l2tpOverIpSec' => 2, | ||
| 131 | 'ipsecLanToLan' => 1, | ||
| 132 | 'ipsecOverUdp' => 2, | ||
| 133 | 'ssh' => 3, | ||
| 134 | 'vcaLanToLan' => 1, | ||
| 135 | 'ipsecOverTcp' => 2, | ||
| 136 | 'pppoe' => 2, | ||
| 137 | 'ipsecOverNatT' => 2, | ||
| 138 | 'ipsecLan2LanOverNatT' => 1, | ||
| 139 | 'l2tpOverIpsecOverNatT' => 2, | ||
| 140 | 'userHttps' => 2, | ||
| 141 | 'pop3s' => 2, | ||
| 142 | 'imap4s' => 2, | ||
| 143 | 'smtps' => 2, | ||
| 144 | 'httpsTunnel' => 2, | ||
| 145 | }; | ||
| 146 | |||
| 147 | sub vendor { | ||
| 148 | return 'altiga'; | ||
| 149 | } | ||
| 150 | |||
| 151 | sub os { | ||
| 152 | return 'altiga'; | ||
| 153 | } | ||
| 154 | |||
| 155 | # $altiga->interfaces() - Map the Interfaces to their physical names | ||
| 156 | # Add interface number to interface name to prevent duplicate ifDescr | ||
| 157 | # Included statically configured VPN tunnels if ($int_include_vpn) | ||
| 158 | sub interfaces { | ||
| 159 | my $altiga = shift; | ||
| 160 | my $partial = shift; | ||
| 161 | |||
| 162 | my $interfaces = $altiga->i_index($partial); | ||
| 163 | my $descriptions = $altiga->i_description($partial); | ||
| 164 | |||
| 165 | my %int_rev = (); | ||
| 166 | my %interfaces = (); | ||
| 167 | foreach my $iid (sort {$a cmp $b} keys %$interfaces) { | ||
| 168 | my $desc = $descriptions->{$iid}; | ||
| 169 | next unless defined $desc; | ||
| 170 | if (!exists $int_rev{$desc}) { | ||
| 171 | $interfaces{$iid} = $desc; | ||
| 172 | $int_rev{$desc} = $iid; | ||
| 173 | } else { | ||
| 174 | my $done = 0; | ||
| 175 | my $unique_desc; | ||
| 176 | my $cnt = 1; | ||
| 177 | until ($done) { | ||
| 178 | $cnt++; | ||
| 179 | $unique_desc = sprintf("%s (%d)", $desc, $cnt); | ||
| 180 | if (!exists $int_rev{$unique_desc}) { | ||
| 181 | $done++; | ||
| 182 | } | ||
| 183 | } | ||
| 184 | $int_rev{$unique_desc} = $iid; | ||
| 185 | $interfaces{$iid} = $unique_desc; | ||
| 186 | $interfaces{ $int_rev{$desc} } = sprintf("%s (%d)", $desc, 1); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | if ($int_include_vpn) { | ||
| 190 | my $tun_type = $altiga->vpn_sess_protocol(); | ||
| 191 | my $peer = $altiga->vpn_sess_peer_ip(); | ||
| 192 | my $remote = $altiga->vpn_sess_rem_ip(); | ||
| 193 | my $group = $altiga->vpn_sess_gid(); | ||
| 194 | foreach my $tunnel (keys %$tun_type) { | ||
| 195 | if ($type_class->{$tun_type->{$tunnel}} eq 1) { | ||
| 196 | $interfaces{"$fake_idx.$tunnel"} = sprintf("%s VPN to %s", uc($tun_type->{$tunnel}), $remote->{$tunnel}); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | } | ||
| 200 | |||
| 201 | return \%interfaces; | ||
| 202 | } | ||
| 203 | |||
| 204 | sub i_type { | ||
| 205 | my $altiga = shift; | ||
| 206 | my $partial = shift; | ||
| 207 | my $types = $altiga->i_type2(); | ||
| 208 | if ($int_include_vpn) { | ||
| 209 | my $tun_type = $altiga->vpn_sess_protocol(); | ||
| 210 | foreach my $tunnel (keys %$tun_type) { | ||
| 211 | $types->{"$fake_idx.$tunnel"} = $tun_type->{$tunnel}; | ||
| 212 | } | ||
| 213 | } | ||
| 214 | return $types; | ||
| 215 | } | ||
| 216 | |||
| 217 | sub i_lastchange { | ||
| 218 | my $altiga = shift; | ||
| 219 | my $partial = shift; | ||
| 220 | |||
| 221 | # TODO: This is what munges are for. | ||
| 222 | my $lastchange = $altiga->i_lastchange2(); | ||
| 223 | if ($int_include_vpn) { | ||
| 224 | my $tun_start = $altiga->vpn_sess_start(); | ||
| 225 | foreach my $tunnel (keys %$tun_start) { | ||
| 226 | $lastchange->{"$fake_idx.$tunnel"} = $tun_start->{$tunnel}; | ||
| 227 | } | ||
| 228 | } | ||
| 229 | return $lastchange; | ||
| 230 | } | ||
| 231 | |||
| 232 | sub ps1_status { | ||
| 233 | my $altiga = shift; | ||
| 234 | my $alarm_3v = $altiga->ps1_3v_alarm() || ""; | ||
| 235 | my $alarm_5v = $altiga->ps1_5v_alarm() || ""; | ||
| 236 | return sprintf("3V: %s, 5V: %s", $alarm_3v, $alarm_5v); | ||
| 237 | } | ||
| 238 | |||
| 239 | sub ps2_status { | ||
| 240 | my $altiga = shift; | ||
| 241 | my $alarm_3v = $altiga->ps2_3v_alarm() || ""; | ||
| 242 | my $alarm_5v = $altiga->ps2_5v_alarm() || ""; | ||
| 243 | return sprintf("3V: %s, 5V: %s", $alarm_3v, $alarm_5v); | ||
| 244 | } | ||
| 245 | |||
| 246 | sub fan { | ||
| 247 | my $altiga = shift; | ||
| 248 | my $alarm_fan1 = $altiga->fan1_alarm() || ""; | ||
| 249 | my $alarm_fan2 = $altiga->fan2_alarm() || ""; | ||
| 250 | my $alarm_fan3 = $altiga->fan3_alarm() || ""; | ||
| 251 | return sprintf("Fan 1: %s, Fan 2: %s, Fan 3: %s", $alarm_fan1, $alarm_fan2, $alarm_fan3); | ||
| 252 | } | ||
| 253 | |||
| 254 | sub munge_alarm { | ||
| 255 | my $alarm = shift; | ||
| 256 | if ($alarm eq 'false') { | ||
| 257 | return 'OK'; | ||
| 258 | } elsif ($alarm eq 'true') { | ||
| 259 | return 'FAIL'; | ||
| 260 | } else { | ||
| 261 | return "(n/a)"; | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | 1; | ||
| 266 | __END__ |