1 | <?php |
||
2 | /** |
||
3 | * MgmtTrapNmsAlarmTest.php |
||
4 | * |
||
5 | * -Description- |
||
6 | * |
||
7 | * Tests NMS Alarm Traps sent by Ekinops Optical Networking products. |
||
8 | * |
||
9 | * This program is free software: you can redistribute it and/or modify |
||
10 | * it under the terms of the GNU General Public License as published by |
||
11 | * the Free Software Foundation, either version 3 of the License, or |
||
12 | * (at your option) any later version. |
||
13 | * |
||
14 | * This program is distributed in the hope that it will be useful, |
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
17 | * GNU General Public License for more details. |
||
18 | * |
||
19 | * You should have received a copy of the GNU General Public License |
||
20 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
21 | * |
||
22 | * |
||
23 | * Tests JnxVpnPwDown and JnxVpnPwUp traps from Juniper devices. |
||
24 | * |
||
25 | * @link https://www.librenms.org |
||
26 | * |
||
27 | * @copyright 2020 KanREN, Inc |
||
28 | * @author Heath Barnhart <[email protected]> |
||
29 | */ |
||
30 | |||
31 | namespace LibreNMS\Tests\Feature\SnmpTraps; |
||
32 | |||
33 | use App\Models\Device; |
||
34 | use LibreNMS\Snmptrap\Dispatcher; |
||
35 | use LibreNMS\Snmptrap\Trap; |
||
36 | |||
37 | class MgmtTrapNmsAlarmTest extends SnmpTrapTestCase |
||
38 | { |
||
39 | public function testAlarmClear() |
||
40 | { |
||
41 | $device = Device::factory()->create(); /** @var Device $device */ |
||
42 | $alarm = self::genEkiAlarm(); |
||
43 | $slotNum = $alarm['slotNum']; |
||
44 | $srcPm = $alarm['srcPm']; |
||
45 | $specific = $alarm['specific']; |
||
46 | |||
47 | $trapText = "$device->hostname |
||
48 | UDP: [$device->ip]:60057->[192.168.1.100]:162 |
||
49 | DISMAN-EVENT-MIB::sysUpTimeInstance 168:19:32:11.62 |
||
50 | SNMPv2-MIB::snmpTrapOID.0 EKINOPS-MGNT2-NMS-MIB::mgnt2TrapNMSAlarm |
||
51 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogNotificationId 566098 |
||
52 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogObjectClassIdentifier module |
||
53 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePm $srcPm |
||
54 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogBoardNumber $slotNum |
||
55 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePortType Other |
||
56 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePortNumber 0 |
||
57 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogProbableCause other |
||
58 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSeverity cleared |
||
59 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSpecificProblem $specific |
||
60 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogAdditionalText |
||
61 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogAlarmType synthesisAlarm |
||
62 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogTime 2020-8-19,14:21:2.0 |
||
63 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogNodeControllerIpAddress 0.0.0.0 |
||
64 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogChassisId $device->ip"; |
||
65 | |||
66 | $trap = new Trap($trapText); |
||
67 | |||
68 | $msg = "Alarm on slot $slotNum, $srcPm Issue: $specific Possible Cause: Unknown"; |
||
69 | |||
70 | \Log::shouldReceive('event')->once()->with($msg, $device->device_id, 'trap', 1); |
||
71 | |||
72 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle mgnt2TrapNMSAlarm trap CLEARED'); |
||
73 | } |
||
74 | |||
75 | //Test alarm with addtional text supplied. |
||
76 | public function testAlarmAddText() |
||
77 | { |
||
78 | $device = Device::factory()->create(); /** @var Device $device */ |
||
79 | $alarm = self::genEkiAlarm(); |
||
80 | $slotNum = $alarm['slotNum']; |
||
81 | $srcPm = $alarm['srcPm']; |
||
82 | $specific = $alarm['specific']; |
||
83 | $add = $alarm['addText']; |
||
84 | |||
85 | $trapText = "$device->hostname |
||
86 | UDP: [$device->ip]:60057->[192.168.1.100]:162 |
||
87 | DISMAN-EVENT-MIB::sysUpTimeInstance 168:19:32:11.62 |
||
88 | SNMPv2-MIB::snmpTrapOID.0 EKINOPS-MGNT2-NMS-MIB::mgnt2TrapNMSAlarm |
||
89 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogNotificationId 566098 |
||
90 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogObjectClassIdentifier module |
||
91 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePm $srcPm |
||
92 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogBoardNumber $slotNum |
||
93 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePortType Other |
||
94 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePortNumber 0 |
||
95 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogProbableCause other |
||
96 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSeverity cleared |
||
97 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSpecificProblem $specific |
||
98 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogAdditionalText $add |
||
99 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogAlarmType synthesisAlarm |
||
100 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogTime 2020-8-19,14:21:2.0 |
||
101 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogNodeControllerIpAddress 0.0.0.0 |
||
102 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogChassisId $device->ip"; |
||
103 | |||
104 | $trap = new Trap($trapText); |
||
105 | |||
106 | $msg = "Alarm on slot $slotNum, $srcPm Issue: $specific Additional info: $add Possible Cause: Unknown"; |
||
107 | |||
108 | \Log::shouldReceive('event')->once()->with($msg, $device->device_id, 'trap', 1); |
||
109 | |||
110 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle mgnt2TrapNMSAlarm trap with additional text'); |
||
111 | } |
||
112 | |||
113 | //Alarm is on a specific port |
||
114 | public function testAlarmPort() |
||
115 | { |
||
116 | $device = Device::factory()->create(); /** @var Device $device */ |
||
117 | $alarm = self::genEkiAlarm(); |
||
118 | $slotNum = $alarm['slotNum']; |
||
119 | $srcPm = $alarm['srcPm']; |
||
120 | $specific = $alarm['specific']; |
||
121 | $probCause = $alarm['probCause']; |
||
122 | $portType = $alarm['portType']; |
||
123 | $portNum = $alarm['portNum']; |
||
124 | $add = $alarm['addText']; |
||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
125 | |||
126 | $trapText = "$device->hostname |
||
127 | UDP: [$device->ip]:60057->[192.168.1.100]:162 |
||
128 | DISMAN-EVENT-MIB::sysUpTimeInstance 168:19:32:03.51 |
||
129 | SNMPv2-MIB::snmpTrapOID.0 EKINOPS-MGNT2-NMS-MIB::mgnt2TrapNMSAlarm |
||
130 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogNotificationId 566097 |
||
131 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogObjectClassIdentifier port |
||
132 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePm $srcPm |
||
133 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogBoardNumber $slotNum |
||
134 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePortType $portType |
||
135 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSourcePortNumber $portNum |
||
136 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogProbableCause $probCause |
||
137 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSeverity critical |
||
138 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogSpecificProblem $specific |
||
139 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogAdditionalText |
||
140 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogAlarmType integrityViolation |
||
141 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogTime 2020-8-19,14:20:54.0 |
||
142 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogNodeControllerIpAddress 0.0.0.0 |
||
143 | EKINOPS-MGNT2-NMS-MIB::mgnt2AlmLogChassisId $device->ip"; |
||
144 | |||
145 | $trap = new Trap($trapText); |
||
146 | |||
147 | $msg = "Alarm on slot $slotNum, $srcPm Port: $portType $portNum Issue: $specific Possible Cause: $probCause"; |
||
148 | |||
149 | \Log::shouldReceive('event')->once()->with($msg, $device->device_id, 'trap', 5); |
||
150 | |||
151 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle mgnt2TrapNMSAlarm trap with additional text'); |
||
152 | } |
||
153 | |||
154 | public static function genEkiAlarm() |
||
155 | { |
||
156 | $alarm['slotNum'] = rand(1, 32); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
157 | $alarm['srcPm'] = str_shuffle('0123456789abcdefg'); |
||
158 | $alarm['specific'] = str_shuffle('0123456789abcdefg'); |
||
159 | $alarm['portType'] = str_shuffle('0123456789abcdefg'); |
||
160 | $alarm['probCause'] = str_shuffle('0123456789abcdefg'); |
||
161 | $alarm['portNum'] = rand(1, 32); |
||
162 | $alarm['addText'] = str_shuffle('0123456789abcdefg'); |
||
163 | |||
164 | return $alarm; |
||
165 | } |
||
166 | } |
||
167 |