1<?php 2/** 3 * AdvaAtributeChange.php 4 * 5 * -Description- 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <https://www.gnu.org/licenses/>. 19 * 20 * Attribute change traps show changes to Adva configuration values after they are submitted. 21 * This handler only catches some of those changes and aims to provide the user with 22 * information about what configuration module was modified. 23 * 24 * @link https://www.librenms.org 25 * @copyright 2018 KanREN, Inc 26 * @author Heath Barnhart <hbarnhart@kanren.net> 27 */ 28 29namespace LibreNMS\Snmptrap\Handlers; 30 31use App\Models\Device; 32use LibreNMS\Interfaces\SnmptrapHandler; 33use LibreNMS\Snmptrap\Trap; 34use Log; 35 36class AdvaAttributeChange implements SnmptrapHandler 37{ 38 /** 39 * Handle snmptrap. 40 * Data is pre-parsed and delivered as a Trap. 41 * 42 * @param Device $device 43 * @param Trap $trap 44 * @return void 45 */ 46 public function handle(Device $device, Trap $trap) 47 { 48 if ($trap->findOid('CM-SYSTEM-MIB::sysLog')) { 49 $this->handleSyslogChg($device, $trap); 50 } elseif ($trap->findOid('CM-SYSTEM-MIB::aclEntry')) { 51 $this->handleAclChg($device, $trap); 52 } elseif ($trap->findOid('CM-SYSTEM-MIB::securityBanner')) { 53 Log::event('MOTD/Banner modified', $device->device_id, 'trap', 2); 54 } elseif ($trap->findOid('CM-SYSTEM-MIB::sysTimeOfDayType')) { 55 $this->handleTimeSrcChg($device, $trap); 56 } elseif ($trap->findOid('F3-TIMEZONE-MIB::f3TimeZone')) { 57 $this->handleTimeZoneChg($device, $trap); 58 } elseif ($trap->findOid('CM-SYSTEM-MIB::ntp')) { 59 $this->handleNtpChg($device, $trap); 60 } elseif ($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServer')) { 61 $this->handleAuthSvrChg($device, $trap); 62 } elseif ($trap->findOid('CM-ENTITY-MIB::ne')) { 63 $this->handleNeChg($device, $trap); 64 } elseif ($trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled')) { 65 $this->handleDyingGaspChg($device, $trap); 66 } elseif ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPort')) { 67 $this->handleNetPortChg($device, $trap); 68 } elseif ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPort')) { 69 $this->handleAccPortChg($device, $trap); 70 } elseif ($trap->findOid('CM-FACILITY-MIB::cmFlow')) { 71 $this->handleFlowChg($device, $trap); 72 } elseif ($trap->findOid('F3-LAG-MIB')) { 73 $this->handleLagChg($device, $trap); 74 } elseif ($trap->findOid('CM-FACILITY-MIB::cmQosFlow')) { 75 $this->handleQosFlowChg($device, $trap); 76 } elseif ($trap->findOid('CM-FACILITY-MIB::cmQosShaper')) { 77 $this->handleQosShaperChg($device, $trap); 78 } elseif ($trap->findOid('CM-FACILITY-MIB::cmAccPort')) { 79 $this->handleAccPortShaperChg($device, $trap); 80 } 81 } 82 83 public static function handleSyslogChg($device, $trap) 84 { 85 $syslogEntry = substr($trap->findOid('CM-SYSTEM-MIB::sysLog'), -1); 86 if ($trap->findOid('CM-SYSTEM-MIB::sysLogIpVersion')) { 87 $ipVer = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysLogIpVersion')); 88 Log::event("Syslog server $syslogEntry IP version set to $ipVer", $device->device_id, 'trap', 2); 89 } 90 if ($trap->findOid('CM-SYSTEM-MIB::sysLogIpAddress')) { 91 $ipAddr = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysLogIpAddress')); 92 Log::event("Syslog server $syslogEntry IP address changed to $ipAddr", $device->device_id, 'trap', 2); 93 } 94 if ($trap->findOid('CM-SYSTEM-MIB::sysLogIpv6Addr')) { 95 $ip6Addr = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysLogIpv6Addr')); 96 Log::event("Syslog server $syslogEntry IP address changed to $ip6Addr", $device->device_id, 'trap', 2); 97 } 98 if ($trap->findOid('CM-SYSTEM-MIB::sysLogPort')) { 99 $syslogPort = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysLogPort')); 100 Log::event("Syslog server $syslogEntry port changed to $syslogPort", $device->device_id, 'trap', 2); 101 } 102 } 103 104 public static function handleAclChg($device, $trap) 105 { 106 $aclEntry = substr($trap->findOid('CM-SYSTEM-MIB::aclEntry'), -1); 107 Log::event("ACL $aclEntry modified", $device->device_id, 'trap', 2); 108 } 109 110 public static function handleTimeSrcChg($device, $trap) 111 { 112 $timeSrc = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::sysTimeOfDayType')); 113 Log::event("Time source set to $timeSrc", $device->device_id, 'trap', 2); 114 } 115 116 public static function handleTimeZoneChg($device, $trap) 117 { 118 $enabled = $trap->getOidData($trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneDstControlEnabled')); 119 if ('true' === $enabled && $trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneDstControlEnabled')) { 120 Log::event('Daylight Savings Time enabled', $device->device_id, 'trap', 2); 121 } elseif ('false' === $enabled && $trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneDstControlEnabled')) { 122 Log::event('Daylight Savings Time disabled', $device->device_id, 'trap', 2); 123 } 124 if ($trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneUtcOffset')) { 125 $dstOffset = $trap->getOidData($trap->findOid('F3-TIMEZONE-MIB::f3TimeZoneUtcOffset')); 126 Log::event("UTC offset (timezone) change to $dstOffset", $device->device_id, 'trap', 2); 127 } 128 } 129 130 public static function handleNtpChg($device, $trap) 131 { 132 if ($trap->findOid('CM-SYSTEM-MIB::ntpPrimaryServer')) { 133 $primaryIP = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::ntpPrimaryServer')); 134 Log::event("Primary NTP server IP changed to $primaryIP", $device->device_id, 'trap', 2); 135 } 136 if ($trap->findOid('CM-SYSTEM-MIB::ntpBackupServer')) { 137 $backupIP = $trap->getOidData($trap->findOid('CM-SYSTEM-MIB::ntpBackupServer')); 138 Log::event("Backup NTP server IP changed to $backupIP", $device->device_id, 'trap', 2); 139 } 140 } 141 142 public static function handleAuthSvrChg($device, $trap) 143 { 144 if ($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerIpAddress')) { 145 $serverEntry = substr($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerIpAddress'), -1); 146 $serverIP = $trap->getOidData($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerIpAddress')); 147 Log::event("Authentication server $serverEntry IP changed to $serverIP", $device->device_id, 'trap', 2); 148 } 149 if ($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerSecret')) { 150 $serverEntry = substr($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerSecret'), -1); 151 Log::event("Authentication server $serverEntry secret changed", $device->device_id, 'trap', 2); 152 } 153 if ($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerEnabled')) { 154 $serverEntry = substr($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerEnabled'), -1); 155 $serverEnable = $trap->getOidData($trap->findOid('CM-SECURITY-MIB::cmRemoteAuthServerEnabled')); 156 if ('true' === $serverEnable) { 157 Log::event("Authentication server $serverEntry enabled", $device->device_id, 'trap', 2); 158 } else { 159 Log::event("Authentication server $serverEntry disabled", $device->device_id, 'trap', 2); 160 } 161 } 162 } 163 164 public static function handleNeChg($device, $trap) 165 { 166 if ($trap->findOid('CM-ENTITY-MIB::neName')) { 167 $neName = $trap->getOidData($trap->findOid('CM-ENTITY-MIB::neName')); 168 Log::event("Network Element name changed to $neName", $device->device_id, 'trap', 2); 169 } 170 if ($trap->findOid('CM-ENTITY-MIB::neCmdPromptPrefix')) { 171 $neCLI = $trap->getOidData($trap->findOid('CM-ENTITY-MIB::neCmdPromptPrefix')); 172 Log::event("Network Element prompt changed to $neCLI", $device->device_id, 'trap', 2); 173 } 174 } 175 176 public static function handleDyingGaspChg($device, $trap) 177 { 178 $nteSDGEnable = $trap->getOidData($trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled')); 179 if ('true' === $nteSDGEnable && $trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled')) { 180 Log::event('SNMP Dying Gasp is enabled', $device->device_id, 'trap', 2); 181 } elseif ('false' === $nteSDGEnable && $trap->findOid('CM-ENTITY-MIB::ethernetNTEGE114ProCardSnmpDyingGaspEnabled')) { 182 Log::event('SNMP Dying Gasp is disabled', $device->device_id, 'trap', 2); 183 } 184 } 185 186 public static function handleNetPortChg($device, $trap) 187 { 188 $netPort = substr($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPort'), -7); 189 $netPort = str_replace('.', '-', $netPort); 190 $neDefMessage = false; 191 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortConfigSpeed')) { 192 $netSpeed = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortConfigSpeed')); 193 Log::event("Network Port $netPort changed speed to $netSpeed", $device->device_id, 'trap', 2); 194 $neDefMessage = true; 195 } 196 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMediaType')) { 197 $netMedia = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMediaType')); 198 Log::event("Network Port $netPort changed media to $netMedia", $device->device_id, 'trap', 2); 199 $neDefMessage = true; 200 } 201 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMDIXType')) { 202 $netMDIX = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMDIXType')); 203 Log::event("Network Port $netPort changed MDIX to $netMDIX", $device->device_id, 'trap', 2); 204 $neDefMessage = true; 205 } 206 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortAutoDiagEnabled')) { 207 $netAutoDiag = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortAutoDiagEnabled')); 208 if ('true' === $netAutoDiag) { 209 $message = "Network Port $netPort AutoDiagnostic enabled"; 210 } else { 211 $message = "Network Port $netPort AutoDiagnostic disabled"; 212 } 213 Log::event($message, $device->device_id, 'trap', 2); 214 $neDefMessage = true; 215 } 216 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortAdminState')) { 217 $netAdminState = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortAdminState')); 218 Log::event("Network Port $netPort administrative state changed to $netAdminState", $device->device_id, 'trap', 2); 219 $neDefMessage = true; 220 } 221 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMTU')) { 222 $netMTU = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetNetPortMTU')); 223 Log::event("Network Port $netPort MTU changed to $netMTU bytes", $device->device_id, 'trap', 2); 224 $neDefMessage = true; 225 } 226 if ($neDefMessage === false) { 227 /* Catch all other Access Port changes and give a generic message */ 228 Log::event("Network Port $netPort modified", $device->device_id, 'trap', 2); 229 } 230 } 231 232 public static function handleAccPortChg($device, $trap) 233 { 234 $accPort = substr($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPort'), -7); 235 $accPort = str_replace('.', '-', $accPort); 236 $accDefMessage = false; 237 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortConfigSpeed')) { 238 $accSpeed = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortConfigSpeed')); 239 Log::event("Access Port $accPort changed speed to $accSpeed", $device->device_id, 'trap', 2); 240 $accDefMessage = true; 241 } 242 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMediaType')) { 243 $accMedia = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMediaType')); 244 Log::event("Access Port $accPort changed media to $accMedia", $device->device_id, 'trap', 2); 245 $accDefMessage = true; 246 } 247 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMDIXType')) { 248 $accMDIX = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMDIXType')); 249 Log::event("Access Port $accPort changed MDIX to $accMDIX", $device->device_id, 'trap', 2); 250 $accDefMessage = true; 251 } 252 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortAutoDiagEnabled')) { 253 $accAutoDiag = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortAutoDiagEnabled')); 254 if ('true' === $accAutoDiag) { 255 $message = "Access Port $accPort AutoDiagnostic enabled"; 256 } else { 257 $message = "Access Port $accPort AutoDiagnostic disabled"; 258 } 259 Log::event($message, $device->device_id, 'trap', 2); 260 $accDefMessage = true; 261 } 262 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortAdminState')) { 263 $accAdminState = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortAdminState')); 264 Log::event("Access Port $accPort administrative state changed to $accAdminState", $device->device_id, 'trap', 2); 265 $accDefMessage = true; 266 } 267 if ($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMTU')) { 268 $accMTU = $trap->getOidData($trap->findOid('CM-FACILITY-MIB::cmEthernetAccPortMTU')); 269 Log::event("Access Port $accPort MTU changed to $accMTU bytes", $device->device_id, 'trap', 2); 270 $accDefMessage = true; 271 } 272 if ($accDefMessage === false) { 273 /* Catch all other Access Port changes and give a generic message */ 274 Log::event("Access Port $accPort modified", $device->device_id, 'trap', 2); 275 } 276 } 277 278 public static function handleFlowChg($device, $trap) 279 { 280 $flowID = substr($trap->findOid('CM-FACILITY-MIB::cmFlow'), -9); 281 $flowID = str_replace('.', '-', $flowID); 282 Log::event("Access Flow $flowID modified", $device->device_id, 'trap', 2); 283 } 284 285 public static function handleLagChg($device, $trap) 286 { 287 $lagID = substr($trap->findOid('F3-LAG-MIB::f3'), -1); 288 Log::event("LAG $lagID modified", $device->device_id, 'trap', 2); 289 } 290 291 public static function handleQosFlowChg($device, $trap) 292 { 293 $flowID = substr($trap->findOid('CM-FACILITY-MIB::cmQosFlow'), -13, 9); 294 $flowID = str_replace('.', '-', $flowID); 295 Log::event("QoS on flow $flowID modified", $device->device_id, 'trap', 2); 296 } 297 298 public static function handleQosShaperChg($device, $trap) 299 { 300 $flowID = substr($trap->findOid('CM-FACILITY-MIB::cmQosShaper'), -13, 9); 301 $flowID = str_replace('.', '-', $flowID); 302 Log::event("QoS on flow $flowID modified", $device->device_id, 'trap', 2); 303 } 304 305 public static function handleAccPortShaperChg($device, $trap) 306 { 307 $shaperID = substr($trap->findOid('CM-FACILITY-MIB::cmAccPort'), -9); 308 $shaperID = str_replace('.', '-', $shaperID); 309 Log::event("Shaper modified on access port $shaperID modified", $device->device_id, 'trap', 2); 310 } 311} 312