1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MgmtTrapNmsEventTest.php |
4
|
|
|
* |
5
|
|
|
* -Description- |
6
|
|
|
* |
7
|
|
|
* Tests NMS Event 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 MgmtTrapNmsEventTest extends SnmpTrapTestCase |
38
|
|
|
{ |
39
|
|
|
public function testEvent() |
40
|
|
|
{ |
41
|
|
|
$device = Device::factory()->create(); /** @var Device $device */ |
42
|
|
|
$alarm = self::genEkiEvent(); |
43
|
|
|
$slotNum = $alarm['slotNum']; |
44
|
|
|
$srcPm = $alarm['srcPm']; |
45
|
|
|
$reason = $alarm['reason']; |
46
|
|
|
|
47
|
|
|
$trapText = "$device->hostname |
48
|
|
|
UDP: [$device->ip]:60057->[10.0.0.1]:162 |
49
|
|
|
DISMAN-EVENT-MIB::sysUpTimeInstance 159:19:33:14.42 |
50
|
|
|
SNMPv2-MIB::snmpTrapOID.0 EKINOPS-MGNT2-NMS-MIB::mgnt2TrapNMSEvent |
51
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogNotificationId 132 |
52
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogObjectClassIdentifier chassis |
53
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePm $srcPm |
54
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogBoardNumber $slotNum |
55
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePortType None |
56
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePortNumber 0 |
57
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogEventType activityLog |
58
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourceType event |
59
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogReason $reason |
60
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogAdditionalText |
61
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogTime 2020-8-10,14:22:5 |
62
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogNodeControllerIpAddress 0.0.0.0 |
63
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogChassisId $device->ip"; |
64
|
|
|
|
65
|
|
|
$trap = new Trap($trapText); |
66
|
|
|
|
67
|
|
|
$msg = "Event on slot $slotNum, $srcPm Reason: $reason"; |
68
|
|
|
|
69
|
|
|
\Log::shouldReceive('event')->once()->with($msg, $device->device_id, 'trap', 2); |
70
|
|
|
|
71
|
|
|
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle mgnt2TrapNMSEvent trap'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
//Test alarm with addtional text supplied. |
75
|
|
|
public function testEventAddText() |
76
|
|
|
{ |
77
|
|
|
$device = Device::factory()->create(); /** @var Device $device */ |
78
|
|
|
$alarm = self::genEkiEvent(); |
79
|
|
|
$slotNum = $alarm['slotNum']; |
80
|
|
|
$srcPm = $alarm['srcPm']; |
81
|
|
|
$reason = $alarm['reason']; |
82
|
|
|
$add = $alarm['addText']; |
83
|
|
|
|
84
|
|
|
$trapText = "$device->hostname |
85
|
|
|
UDP: [$device->ip]:60057->[10.0.0.1]:162 |
86
|
|
|
DISMAN-EVENT-MIB::sysUpTimeInstance 159:19:33:14.42 |
87
|
|
|
SNMPv2-MIB::snmpTrapOID.0 EKINOPS-MGNT2-NMS-MIB::mgnt2TrapNMSEvent |
88
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogNotificationId 132 |
89
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogObjectClassIdentifier chassis |
90
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePm $srcPm |
91
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogBoardNumber $slotNum |
92
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePortType None |
93
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePortNumber 0 |
94
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogEventType activityLog |
95
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourceType event |
96
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogReason $reason |
97
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogAdditionalText $add |
98
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogTime 2020-8-10,14:22:5 |
99
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogNodeControllerIpAddress 0.0.0.0 |
100
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogChassisId $device->ip"; |
101
|
|
|
|
102
|
|
|
$trap = new Trap($trapText); |
103
|
|
|
|
104
|
|
|
$msg = "Event on slot $slotNum, $srcPm Reason: $reason Additional info: $add"; |
105
|
|
|
|
106
|
|
|
\Log::shouldReceive('event')->once()->with($msg, $device->device_id, 'trap', 2); |
107
|
|
|
|
108
|
|
|
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle mgnt2TrapNMSEvent trap with additional text'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
//Event trap on a specific port |
112
|
|
|
public function testEventPort() |
113
|
|
|
{ |
114
|
|
|
$device = Device::factory()->create(); /** @var Device $device */ |
115
|
|
|
$alarm = self::genEkiEvent(); |
116
|
|
|
$slotNum = $alarm['slotNum']; |
117
|
|
|
$srcPm = $alarm['srcPm']; |
118
|
|
|
$reason = $alarm['reason']; |
119
|
|
|
$add = $alarm['addText']; |
|
|
|
|
120
|
|
|
$portType = $alarm['portType']; |
121
|
|
|
$portNum = $alarm['portNum']; |
122
|
|
|
|
123
|
|
|
$trapText = "$device->hostname |
124
|
|
|
UDP: [$device->ip]:60057->[10.0.0.1]:162 |
125
|
|
|
DISMAN-EVENT-MIB::sysUpTimeInstance 159:19:33:14.42 |
126
|
|
|
SNMPv2-MIB::snmpTrapOID.0 EKINOPS-MGNT2-NMS-MIB::mgnt2TrapNMSEvent |
127
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogNotificationId 132 |
128
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogObjectClassIdentifier port |
129
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePm $srcPm |
130
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogBoardNumber $slotNum |
131
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePortType $portType |
132
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourcePortNumber $portNum |
133
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogEventType activityLog |
134
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogSourceType event |
135
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogReason $reason |
136
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogAdditionalText |
137
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogTime 2020-8-10,14:22:5 |
138
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogNodeControllerIpAddress 0.0.0.0 |
139
|
|
|
EKINOPS-MGNT2-NMS-MIB::mgnt2EventLogChassisId $device->ip"; |
140
|
|
|
|
141
|
|
|
$trap = new Trap($trapText); |
142
|
|
|
|
143
|
|
|
$msg = "Event on slot $slotNum, $srcPm Port: $portType $portNum. Reason: $reason"; |
144
|
|
|
|
145
|
|
|
\Log::shouldReceive('event')->once()->with($msg, $device->device_id, 'trap', 2); |
146
|
|
|
|
147
|
|
|
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle mgnt2TrapNMSEvent trap with a specficied port'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public static function genEkiEvent() |
151
|
|
|
{ |
152
|
|
|
$alarm['slotNum'] = rand(1, 32); |
|
|
|
|
153
|
|
|
$alarm['srcPm'] = str_shuffle('0123456789abcdefg'); |
154
|
|
|
$alarm['reason'] = str_shuffle('0123456789abcdefg'); |
155
|
|
|
$alarm['portType'] = str_shuffle('0123456789abcdefg'); |
156
|
|
|
$alarm['portNum'] = rand(1, 32); |
157
|
|
|
$alarm['addText'] = str_shuffle('0123456789abcdefg'); |
158
|
|
|
|
159
|
|
|
return $alarm; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|