. * * @link https://www.librenms.org * * @copyright 2022 Andy Norwood * @author Andy Norwood(bonzo81)) */ namespace LibreNMS\Tests\Feature\SnmpTraps; use App\Models\Device; use App\Models\Port; use LibreNMS\Snmptrap\Dispatcher; use LibreNMS\Snmptrap\Trap; class CiscoErrDisableInterfaceEventTest extends SnmpTrapTestCase { /** * Test CiscoErrDisableInterfaceEvent trap handle * * @return void */ public function testErrDisableInterfaceEvent() { $device = Device::factory()->create(); /** @var Device $device */ $port = Port::factory()->make(); /** @var Port $port */ $device->ports()->save($port); $trapText = "$device->hostname UDP: [$device->ip]:57602->[10.0.0.1]:162 SNMPv2-MIB::sysUpTime.0 18:30:30.32 SNMPv2-MIB::snmpTrapOID.0 CISCO-ERR-DISABLE-MIB::cErrDisableInterfaceEventRev1 CISCO-ERR-DISABLE-MIB::cErrDisableIfStatusCause.$port->ifIndex.0 bpduGuard"; $trap = new Trap($trapText); $message = 'SNMP TRAP: bpduGuard error detected on ' . $port->ifName . ' (Description: ' . $port->ifDescr . '). ' . $port->ifName . ' in err-disable state.'; \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4); $this->assertTrue(Dispatcher::handle($trap), 'Could not handle testErrDisableInterfaceEvent trap'); } /** * Test CiscoErrDisableBadIfIndex trap handle * * @return void */ public function testErrDisableBadIfIndex() { $device = Device::factory()->create(); /** @var Device $device */ $port = Port::factory()->make(['ifIndex' => 1]); /** @var Port $port */ $device->ports()->save($port); $trapText = "$device->hostname UDP: [$device->ip]:57602->[10.0.0.1]:162 SNMPv2-MIB::sysUpTime.0 18:30:30.32 SNMPv2-MIB::snmpTrapOID.0 CISCO-ERR-DISABLE-MIB::cErrDisableInterfaceEventRev1 CISCO-ERR-DISABLE-MIB::cErrDisableIfStatusCause.10.0 bpduGuard"; $trap = new Trap($trapText); $message = 'SNMP TRAP: bpduGuard error detected on unknown port. Either ifIndex is not found in the trap, or it does not match a port on this device.'; \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4); $this->assertTrue(Dispatcher::handle($trap), 'Could not handle testErrDisableBadIfIndex trap'); } }