Passed
Push — master ( 0baeb0...d4017c )
by Tony
19:18 queued 08:55
created

SnmpTraps/AdvaAccThresholdCrossingAlertTest.php (1 issue)

1
<?php
2
/**
3
 * AdvaAccThreholdCrossingAlertTest.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
 * @copyright  2019 Heath Barnhart
23
 * @author     Heath Barnhart <[email protected]>
24
 */
25
26
namespace LibreNMS\Tests\Feature\SnmpTraps;
27
28
use App\Models\Device;
29
use Illuminate\Foundation\Testing\DatabaseTransactions;
30
use LibreNMS\Snmptrap\Dispatcher;
31
use LibreNMS\Snmptrap\Trap;
32
use LibreNMS\Tests\LaravelTestCase;
33
34
class AdvaAccThresholdCrossingAlertTest extends LaravelTestCase
35
{
36
    use DatabaseTransactions;
0 ignored issues
show
The trait Illuminate\Foundation\Testing\DatabaseTransactions requires the property $connectionsToTransact which is not provided by LibreNMS\Tests\Feature\S...esholdCrossingAlertTest.
Loading history...
37
38
    public function testAccThresholdTrap()
39
    {
40
        $device = factory(Device::class)->create();
41
42
        $trapText = "$device->hostname
43
UDP: [$device->ip]:57602->[192.168.5.5]:162
44
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
45
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert
46
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdIndex.1.1.1.2.1.37 37
47
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval.1.1.1.2.1.37 interval-15min
48
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable.1.1.1.2.1.37 CM-PERFORMANCE-MIB::cmEthernetAccPortStatsUAS.1.1.1.2.1
49
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueLo.1.1.1.2.1.37 10
50
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueHi.1.1.1.2.1.37 0
51
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdMonValue.1.1.1.2.1.37 10
52
IF-MIB::ifName.2 Access PORT-1-1-1-2
53
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
54
ADVA-MIB::neEventLogIndex.79 79
55
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
56
57
        $trap = new Trap($trapText);
58
59
        $message = "Access PORT-1-1-1-2 unavailable seconds threshold exceeded for interval-15min";
60
        \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
61
62
        $this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetAccPortThresholdCrossingAlert UAS');
63
64
        $trapText = "$device->hostname
65
UDP: [$device->ip]:57602->[192.168.5.5]:162
66
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
67
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert
68
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdIndex.1.1.1.2.1.37 37
69
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval.1.1.1.2.1.37 interval-1day
70
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable.1.1.1.2.1.37 CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESBP.1.1.1.2.1
71
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueLo.1.1.1.2.1.37 20
72
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueHi.1.1.1.2.1.37 0
73
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdMonValue.1.1.1.2.1.37 20
74
IF-MIB::ifName.2 Access PORT-1-1-1-2
75
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
76
ADVA-MIB::neEventLogIndex.79 79
77
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
78
79
        $trap = new Trap($trapText);
80
81
        $message = 'Access PORT-1-1-1-2 broadcast frames received threshold exceeded for interval-1day';
82
        \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
83
84
        $this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetAccPortThresholdCrossingAlert broadcast framesent');
85
86
        $trapText = "$device->hostname
87
UDP: [$device->ip]:57602->[192.168.5.5]:162
88
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
89
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert
90
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdIndex.1.1.1.3.1.37 37
91
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval.1.1.1.3.1.37 interval-1day
92
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable.1.1.1.3.1.37 CM-PERFORMANCE-MIB::cmEthernetAccPortStatsESUP.1.1.1.2.1
93
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueLo.1.1.1.3.1.37 20
94
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdValueHi.1.1.1.3.1.37 0
95
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdMonValue.1.1.1.3.1.37 20
96
IF-MIB::ifName.2 Access PORT-1-1-1-3
97
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
98
ADVA-MIB::neEventLogIndex.79 79
99
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
100
101
        $trap = new Trap($trapText);
102
103
        $message = "Access PORT-1-1-1-3 unicast frames received threshold exceeded for interval-1day";
104
        \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
105
106
        $this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetAccPortThresholdCrossingAlert unicast frames sent');
107
108
        $trapText = "$device->hostname
109
UDP: [$device->ip]:57602->[192.168.5.5]:162
110
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
111
SNMPv2-MIB::snmpTrapOID.0 CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdCrossingAlert
112
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdIndex.1.1.1.3.1.37 37
113
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdInterval.1.1.1.3.1.37 interval-1day
114
CM-PERFORMANCE-MIB::cmEthernetAccPortThresholdVariable.1.1.1.3.1.37 CM-PERFORMANCE-MIB::defaultThresholdTest.1.1.1.3.1
115
IF-MIB::ifName.2 Access PORT-1-1-1-3
116
RMON2-MIB::probeDateTime.0 \"07 E2 0C 0A 0B 2D 0A 00 2D 06 00 \"
117
ADVA-MIB::neEventLogIndex.79 79
118
ADVA-MIB::neEventLogTimeStamp.79 2018-12-10,11:45:10.8,-6:0";
119
120
        $trap = new Trap($trapText);
121
122
        $message = "Access PORT-1-1-1-3 unknown threshold exceeded for interval-1day";
123
        \Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
124
125
        $this->assertTrue(Dispatcher::handle($trap), 'Could not handle cmEthernetAccPortThresholdCrossingAlert unknown threshold');
126
    }
127
}
128