1 | <?php |
||
2 | /** |
||
3 | * JnxLdpLspTest.php |
||
4 | * -Description- |
||
5 | * |
||
6 | * This program is free software: you can redistribute it and/or modify |
||
7 | * it under the terms of the GNU General Public License as published by |
||
8 | * the Free Software Foundation, either version 3 of the License, or |
||
9 | * (at your option) any later version. |
||
10 | * |
||
11 | * This program is distributed in the hope that it will be useful, |
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
14 | * GNU General Public License for more details. |
||
15 | * |
||
16 | * You should have received a copy of the GNU General Public License |
||
17 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
18 | * |
||
19 | * |
||
20 | * Tests JnxLdpLspDown and JnxLdpLspUp traps from Juniper devices. |
||
21 | * |
||
22 | * @link https://www.librenms.org |
||
23 | * |
||
24 | * @copyright 2019 KanREN, Inc |
||
25 | * @author Heath Barnhart <[email protected]> |
||
26 | */ |
||
27 | |||
28 | namespace LibreNMS\Tests\Feature\SnmpTraps; |
||
29 | |||
30 | use App\Models\Device; |
||
31 | use App\Models\Ipv4Address; |
||
32 | use LibreNMS\Snmptrap\Dispatcher; |
||
33 | use LibreNMS\Snmptrap\Trap; |
||
34 | |||
35 | class JnxLdpLspTest extends SnmpTrapTestCase |
||
36 | { |
||
37 | public function testLdpLspDownTrap() |
||
38 | { |
||
39 | $device = Device::factory()->create(); /** @var Device $device */ |
||
40 | $ipv4 = Ipv4Address::factory()->make(); /** @var Ipv4Address $ipv4 */ |
||
41 | $trapText = "$device->hostname |
||
42 | UDP: [$device->ip]:64610->[192.168.5.5]:162 |
||
43 | DISMAN-EVENT-MIB::sysUpTimeInstance 198:2:10:48.91 |
||
44 | SNMPv2-MIB::snmpTrapOID.0 JUNIPER-LDP-MIB::jnxLdpLspDown |
||
45 | JUNIPER-LDP-MIB::jnxLdpLspFec.0 $ipv4->ipv4_address |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
46 | JUNIPER-LDP-MIB::jnxLdpRtrid.0 $device->ip |
||
47 | JUNIPER-LDP-MIB::jnxLdpLspDownReason.0 topologyChanged |
||
48 | JUNIPER-LDP-MIB::jnxLdpLspFecLen.0 32 |
||
49 | JUNIPER-LDP-MIB::jnxLdpInstanceName.0 \"test instance down\" |
||
50 | SNMPv2-MIB::snmpTrapEnterprise.0 JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameMX480"; |
||
51 | |||
52 | $trap = new Trap($trapText); |
||
53 | $message = "LDP session test instance down from $device->ip to $ipv4->ipv4_address has gone down due to topologyChanged"; |
||
54 | \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4); |
||
55 | |||
56 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle JnxLdpLspDown trap'); |
||
57 | } |
||
58 | |||
59 | public function testLdpLspUpTrap() |
||
60 | { |
||
61 | $device = Device::factory()->create(); /** @var Device $device */ |
||
62 | $ipv4 = Ipv4Address::factory()->make(); /** @var Ipv4Address $ipv4 */ |
||
63 | $trapText = "$device->hostname |
||
64 | UDP: [$device->ip]:64610->[192.168.5.5]:162 |
||
65 | DISMAN-EVENT-MIB::sysUpTimeInstance 198:2:10:48.91 |
||
66 | SNMPv2-MIB::snmpTrapOID.0 JUNIPER-LDP-MIB::jnxLdpLspUp |
||
67 | JUNIPER-LDP-MIB::jnxLdpLspFec.0 $ipv4->ipv4_address |
||
0 ignored issues
–
show
The property
ipv4_address does not exist on App\Models\Ipv4Address . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
68 | JUNIPER-LDP-MIB::jnxLdpRtrid.0 $device->ip |
||
69 | JUNIPER-LDP-MIB::jnxLdpLspFecLen.0 32 |
||
70 | JUNIPER-LDP-MIB::jnxLdpInstanceName.0 \"test instance up\" |
||
71 | SNMPv2-MIB::snmpTrapEnterprise.0 JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameMX480"; |
||
72 | |||
73 | $trap = new Trap($trapText); |
||
74 | $message = "LDP session test instance up from $device->ip to $ipv4->ipv4_address is now up."; |
||
75 | \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 1); |
||
76 | |||
77 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle JnxLdpLspUp trap'); |
||
78 | } |
||
79 | } |
||
80 |