1 | <?php |
||
2 | /** |
||
3 | * OspfNbrStateChangeTest.php |
||
4 | * |
||
5 | * -Description- |
||
6 | * |
||
7 | * Unit test for the OspfNbStateChange SNMP trap handler. Will verify |
||
8 | * trap is properly logged and ospf_nbrs.ospfNbrState is updated in the |
||
9 | * database. |
||
10 | * |
||
11 | * This program is free software: you can redistribute it and/or modify |
||
12 | * it under the terms of the GNU General Public License as published by |
||
13 | * the Free Software Foundation, either version 3 of the License, or |
||
14 | * (at your option) any later version. |
||
15 | * |
||
16 | * This program is distributed in the hope that it will be useful, |
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
19 | * GNU General Public License for more details. |
||
20 | * |
||
21 | * You should have received a copy of the GNU General Public License |
||
22 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
23 | * |
||
24 | * @link https://www.librenms.org |
||
25 | * |
||
26 | * @copyright 2020 KanREN, Inc |
||
27 | * @author Heath Barnhart <[email protected]> |
||
28 | */ |
||
29 | |||
30 | namespace LibreNMS\Tests\Feature\SnmpTraps; |
||
31 | |||
32 | use App\Models\Device; |
||
33 | use App\Models\OspfNbr; |
||
34 | use LibreNMS\Snmptrap\Dispatcher; |
||
35 | use LibreNMS\Snmptrap\Trap; |
||
36 | |||
37 | class OspfNbrStateChangeTest extends SnmpTrapTestCase |
||
38 | { |
||
39 | //Test OSPF neighbor state down trap |
||
40 | public function testOspfNbrDown() |
||
41 | { |
||
42 | $device = Device::factory()->create(); /** @var Device $device */ |
||
43 | $ospfNbr = OspfNbr::factory()->make(['device_id' => $device->device_id, 'ospfNbrState' => 'full']); /** @var OspfNbr $ospfNbr */ |
||
44 | $ospfNbr->ospf_nbr_id = "$ospfNbr->ospfNbrIpAddr.$ospfNbr->ospfNbrAddressLessIndex"; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
The property
ospfNbrIpAddr does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
The property
ospf_nbr_id does not exist on App\Models\OspfNbr . Since you implemented __set , consider adding a @property annotation.
Loading history...
|
|||
45 | $device->ospfNbrs()->save($ospfNbr); |
||
46 | |||
47 | $trapText = "$device->hostname |
||
48 | UDP: [$device->ip]:57602->[192.168.5.5]:162 |
||
49 | DISMAN-EVENT-MIB::sysUpTimeInstance 0:1:07:16.06 |
||
50 | SNMPv2-MIB::snmpTrapOID.0 OSPF-TRAP-MIB::ospfNbrStateChange |
||
51 | OSPF-MIB::ospfRouterId.0 $device->ip |
||
52 | OSPF-MIB::ospfNbrIpAddr.$ospfNbr->ospf_nbr_id $ospfNbr->ospfNbrIpAddr |
||
0 ignored issues
–
show
The property
ospf_nbr_id does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
53 | OSPF-MIB::ospfNbrAddressLessIndex.$ospfNbr->ospf_nbr_id $ospfNbr->ospfNbrAddressLessIndex |
||
54 | OSPF-MIB::ospfNbrRtrId.$ospfNbr->ospf_nbr_id $ospfNbr->ospfNbrRtrId |
||
0 ignored issues
–
show
The property
ospfNbrRtrId does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
55 | OSPF-MIB::ospfNbrState.$ospfNbr->ospf_nbr_id down |
||
56 | SNMPv2-MIB::snmpTrapEnterprise.0 JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameSRX240 "; |
||
57 | |||
58 | $trap = new Trap($trapText); |
||
59 | |||
60 | $message = "OSPF neighbor $ospfNbr->ospfNbrRtrId changed state to down"; |
||
61 | |||
62 | \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 5); |
||
63 | |||
64 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle ospfNbrStateChange down'); |
||
65 | |||
66 | $ospfNbr = $ospfNbr->fresh(); |
||
67 | $this->assertEquals($ospfNbr->ospfNbrState, 'down'); |
||
0 ignored issues
–
show
The property
ospfNbrState does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
68 | } |
||
69 | |||
70 | //Test OSPF neighbor state full trap |
||
71 | public function testOspfNbrFull() |
||
72 | { |
||
73 | $device = Device::factory()->create(); /** @var Device $device */ |
||
74 | $ospfNbr = OspfNbr::factory()->make(['device_id' => $device->device_id, 'ospfNbrState' => 'down']); /** @var OspfNbr $ospfNbr */ |
||
75 | $ospfNbr->ospf_nbr_id = "$ospfNbr->ospfNbrIpAddr.$ospfNbr->ospfNbrAddressLessIndex"; |
||
0 ignored issues
–
show
The property
ospfNbrIpAddr does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
The property
ospf_nbr_id does not exist on App\Models\OspfNbr . Since you implemented __set , consider adding a @property annotation.
Loading history...
The property
ospfNbrAddressLessIndex does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
76 | $device->ospfNbrs()->save($ospfNbr); |
||
77 | |||
78 | $trapText = "$device->hostname |
||
79 | UDP: [$device->ip]:57602->[192.168.5.5]:162 |
||
80 | DISMAN-EVENT-MIB::sysUpTimeInstance 0:1:07:16.06 |
||
81 | SNMPv2-MIB::snmpTrapOID.0 OSPF-TRAP-MIB::ospfNbrStateChange |
||
82 | OSPF-MIB::ospfRouterId.0 $device->ip |
||
83 | OSPF-MIB::ospfNbrIpAddr.$ospfNbr->ospf_nbr_id $ospfNbr->ospfNbrIpAddr |
||
0 ignored issues
–
show
The property
ospf_nbr_id does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
84 | OSPF-MIB::ospfNbrAddressLessIndex.$ospfNbr->ospf_nbr_id $ospfNbr->ospfNbrAddressLessIndex |
||
85 | OSPF-MIB::ospfNbrRtrId.$ospfNbr->ospf_nbr_id $ospfNbr->ospfNbrRtrId |
||
0 ignored issues
–
show
The property
ospfNbrRtrId does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
86 | OSPF-MIB::ospfNbrState.$ospfNbr->ospf_nbr_id full |
||
87 | SNMPv2-MIB::snmpTrapEnterprise.0 JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameSRX240 "; |
||
88 | |||
89 | $trap = new Trap($trapText); |
||
90 | |||
91 | $message = "OSPF neighbor $ospfNbr->ospfNbrRtrId changed state to full"; |
||
92 | |||
93 | \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 1); |
||
94 | |||
95 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle ospfNbrStateChange full'); |
||
96 | |||
97 | $ospfNbr = $ospfNbr->fresh(); |
||
98 | $this->assertEquals($ospfNbr->ospfNbrState, 'full'); |
||
0 ignored issues
–
show
The property
ospfNbrState does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
99 | } |
||
100 | |||
101 | //Test OSPF neighbor state trap any other state |
||
102 | public function testOspfNbrOther() |
||
103 | { |
||
104 | $device = Device::factory()->create(); /** @var Device $device */ |
||
105 | $ospfNbr = OspfNbr::factory()->make(['device_id' => $device->device_id, 'ospfNbrState' => 'full']); /** @var OspfNbr $ospfNbr */ |
||
106 | $ospfNbr->ospf_nbr_id = "$ospfNbr->ospfNbrIpAddr.$ospfNbr->ospfNbrAddressLessIndex"; |
||
0 ignored issues
–
show
The property
ospf_nbr_id does not exist on App\Models\OspfNbr . Since you implemented __set , consider adding a @property annotation.
Loading history...
The property
ospfNbrAddressLessIndex does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
The property
ospfNbrIpAddr does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
107 | $device->ospfNbrs()->save($ospfNbr); |
||
108 | |||
109 | $trapText = "$device->hostname |
||
110 | UDP: [$device->ip]:57602->[192.168.5.5]:162 |
||
111 | DISMAN-EVENT-MIB::sysUpTimeInstance 0:1:07:16.06 |
||
112 | SNMPv2-MIB::snmpTrapOID.0 OSPF-TRAP-MIB::ospfNbrStateChange |
||
113 | OSPF-MIB::ospfRouterId.0 $device->ip |
||
114 | OSPF-MIB::ospfNbrIpAddr.$ospfNbr->ospf_nbr_id $ospfNbr->ospfNbrIpAddr |
||
0 ignored issues
–
show
The property
ospf_nbr_id does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
115 | OSPF-MIB::ospfNbrAddressLessIndex.$ospfNbr->ospf_nbr_id $ospfNbr->ospfNbrAddressLessIndex |
||
116 | OSPF-MIB::ospfNbrRtrId.$ospfNbr->ospf_nbr_id $ospfNbr->ospfNbrRtrId |
||
0 ignored issues
–
show
The property
ospfNbrRtrId does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
117 | OSPF-MIB::ospfNbrState.$ospfNbr->ospf_nbr_id exstart |
||
118 | SNMPv2-MIB::snmpTrapEnterprise.0 JUNIPER-CHASSIS-DEFINES-MIB::jnxProductNameSRX240 "; |
||
119 | |||
120 | $trap = new Trap($trapText); |
||
121 | |||
122 | $message = "OSPF neighbor $ospfNbr->ospfNbrRtrId changed state to exstart"; |
||
123 | |||
124 | \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4); |
||
125 | |||
126 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle ospfNbrStateChange exstart'); |
||
127 | |||
128 | $ospfNbr = $ospfNbr->fresh(); |
||
129 | $this->assertEquals($ospfNbr->ospfNbrState, 'exstart'); |
||
0 ignored issues
–
show
The property
ospfNbrState does not exist on App\Models\OspfNbr . Since you implemented __get , consider adding a @property annotation.
Loading history...
|
|||
130 | } |
||
131 | } |
||
132 |