1 | <?php |
||
2 | /** |
||
3 | * ApcPduOutletTest.php |
||
4 | * |
||
5 | * -Description- |
||
6 | * |
||
7 | * This program is free software: you can redistribute it and/or modify |
||
8 | * it under the terms of the GNU General Public License as published by |
||
9 | * the Free Software Foundation, either version 3 of the License, or |
||
10 | * (at your option) any later version. |
||
11 | * |
||
12 | * This program is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
15 | * GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License |
||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
19 | * |
||
20 | * @package LibreNMS |
||
21 | * @link http://librenms.org |
||
22 | */ |
||
23 | |||
24 | namespace LibreNMS\Tests\Feature\SnmpTraps; |
||
25 | |||
26 | use App\Models\Device; |
||
27 | use App\Models\Ipv4Address; |
||
28 | use Illuminate\Foundation\Testing\DatabaseTransactions; |
||
29 | use LibreNMS\Snmptrap\Dispatcher; |
||
30 | use LibreNMS\Snmptrap\Trap; |
||
31 | use LibreNMS\Tests\DBTestCase; |
||
32 | |||
33 | class ApcPduOutletTest extends DBTestCase |
||
34 | { |
||
35 | use DatabaseTransactions; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
36 | |||
37 | public function testOutletOff() |
||
38 | { |
||
39 | $device = factory(Device::class)->create(); |
||
40 | |||
41 | $trapText = "$device->hostname |
||
42 | UDP: [$device->ip]:161->[192.168.5.5]:162 |
||
43 | DISMAN-EVENT-MIB::sysUpTimeInstance 84:21:45:07.07 |
||
44 | SNMPv2-MIB::snmpTrapOID.0 PowerNet-MIB::outletOff |
||
45 | PowerNet-MIB::mtrapargsInteger.0 2 |
||
46 | PowerNet-MIB::mtrapargsString.0 \"An outlet has turned on. If the outlet number is 0, then all outlets have turned on.\" |
||
47 | SNMPv2-MIB::snmpTrapEnterprise.0 PowerNet-MIB::apc"; |
||
48 | |||
49 | $message = "APC PDU: Outlet has turned off: 2"; |
||
50 | \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4); |
||
51 | |||
52 | $trap = new Trap($trapText); |
||
53 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle outletOff trap'); |
||
54 | } |
||
55 | |||
56 | public function testOutletOn() |
||
57 | { |
||
58 | $device = factory(Device::class)->create(); |
||
59 | |||
60 | $trapText = "$device->hostname |
||
61 | UDP: [$device->ip]:161->[192.168.5.5]:162 |
||
62 | DISMAN-EVENT-MIB::sysUpTimeInstance 84:21:45:07.07 |
||
63 | SNMPv2-MIB::snmpTrapOID.0 PowerNet-MIB::outletOn |
||
64 | PowerNet-MIB::mtrapargsInteger.0 2 |
||
65 | PowerNet-MIB::mtrapargsString.0 \"An outlet has turned on. If the outlet number is 0, then all outlets have turned on.\" |
||
66 | SNMPv2-MIB::snmpTrapEnterprise.0 PowerNet-MIB::apc"; |
||
67 | |||
68 | $message = "APC PDU: Outlet has been turned on: 2"; |
||
69 | \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4); |
||
70 | |||
71 | $trap = new Trap($trapText); |
||
72 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle outletOn trap'); |
||
73 | } |
||
74 | |||
75 | public function testOutletReboot() |
||
76 | { |
||
77 | $device = factory(Device::class)->create(); |
||
78 | |||
79 | $trapText = "$device->hostname |
||
80 | UDP: [$device->ip]:161->[192.168.5.5]:162 |
||
81 | DISMAN-EVENT-MIB::sysUpTimeInstance 84:21:45:07.07 |
||
82 | SNMPv2-MIB::snmpTrapOID.0 PowerNet-MIB::outletReboot |
||
83 | PowerNet-MIB::mtrapargsInteger.0 2 |
||
84 | PowerNet-MIB::mtrapargsString.0 \"An outlet has rebooted. If the outlet number is 0, then all outlets have rebooted.\" |
||
85 | SNMPv2-MIB::snmpTrapEnterprise.0 PowerNet-MIB::apc"; |
||
86 | |||
87 | $message = "APC PDU: Outlet has rebooted: 2"; |
||
88 | \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4); |
||
89 | |||
90 | $trap = new Trap($trapText); |
||
91 | $this->assertTrue(Dispatcher::handle($trap), 'Could not handle outletReboot trap'); |
||
92 | } |
||
93 | } |
||
94 |