. * * * Tests JnxLdpSesDown and JnxLdpSesUp traps from Juniper devices. * * @package LibreNMS * @link http://librenms.org * @copyright 2019 KanREN, Inc * @author Heath Barnhart */ namespace LibreNMS\Tests\Feature\SnmpTraps; use App\Models\Device; use App\Models\Port; use LibreNMS\Snmptrap\Dispatcher; use LibreNMS\Snmptrap\Trap; use LibreNMS\Tests\Feature\SnmpTraps\SnmpTrapTestCase; class JnxLdpSesTest extends SnmpTrapTestCase { public function testJnxLdpSesDownTrap() { $device = factory(Device::class)->create(); $port = factory(Port::class)->make(['ifAdminStatus' => 'up', 'ifOperStatus' => 'up']); $device->ports()->save($port); $trapText = "$device->hostname UDP: [$device->ip]:64610->[192.168.5.5]:162 DISMAN-EVENT-MIB::sysUpTimeInstance 198:2:10:48.91 SNMPv2-MIB::snmpTrapOID.0 JUNIPER-LDP-MIB::jnxLdpSesDown JUNIPER-MPLS-LDP-MIB::jnxMplsLdpSesState.'.q.j..'.1.'.q.p..' nonexistent JUNIPER-LDP-MIB::jnxLdpSesDownReason.0 allAdjacenciesDown JUNIPER-LDP-MIB::jnxLdpSesDownIf.0 $port->ifIndex SNMPv2-MIB::snmpTrapEnterprise.0 JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameMX480"; \Log::shouldReceive('warning')->never()->with("Snmptrap LdpSesDown: Could not find port at ifIndex $port->ifIndex for device: $device->hostname"); $trap = new Trap($trapText); $message = "LDP session on interface $port->ifDescr is nonexistent due to allAdjacenciesDown"; \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4); $this->assertTrue(Dispatcher::handle($trap), 'Could not handle JnxLdpSesDown trap'); } public function testJnxLdpSesUpTrap() { $device = factory(Device::class)->create(); $port = factory(Port::class)->make(['ifAdminStatus' => 'up', 'ifOperStatus' => 'up']); $device->ports()->save($port); $trapText = "$device->hostname UDP: [$device->ip]:64610->[192.168.5.5]:162 DISMAN-EVENT-MIB::sysUpTimeInstance 198:2:10:48.91 SNMPv2-MIB::snmpTrapOID.0 JUNIPER-LDP-MIB::jnxLdpSesUp JUNIPER-MPLS-LDP-MIB::jnxMplsLdpSesState.'.q.d..'.1.'.q.p..' operational JUNIPER-LDP-MIB::jnxLdpSesUpIf.0 $port->ifIndex SNMPv2-MIB::snmpTrapEnterprise.0 JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameMX960"; \Log::shouldReceive('warning')->never()->with("Snmptrap LdpSesUp: Could not find port at ifIndex $port->ifIndex for device: $device->hostname"); $trap = new Trap($trapText); $message = "LDP session on interface $port->ifDescr is operational"; \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 1); $this->assertTrue(Dispatcher::handle($trap), 'Could not handle JnxLdpSesUp trap'); } }