Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
4.0 KiB
PHP
Raw Permalink Normal View History

2019-03-12 23:59:03 -05:00
<?php
/**
* PortsTrapTest.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2021-02-09 00:29:04 +01:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2019-03-12 23:59:03 -05:00
*
2021-02-09 00:29:04 +01:00
* @link https://www.librenms.org
2021-09-10 20:09:53 +02:00
*
2019-03-12 23:59:03 -05:00
* @copyright 2019 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use App\Models\Port;
2022-11-05 14:43:54 -05:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
2023-08-05 12:12:36 -05:00
use LibreNMS\Enum\Severity;
2022-11-05 14:43:54 -05:00
use LibreNMS\Tests\Traits\RequiresDatabase;
2019-03-12 23:59:03 -05:00
2019-10-13 13:40:38 +00:00
class PortsTrapTest extends SnmpTrapTestCase
2019-03-12 23:59:03 -05:00
{
2022-11-05 14:43:54 -05:00
use RequiresDatabase;
use DatabaseTransactions;
public function testLinkDown(): void
2019-03-12 23:59:03 -05:00
{
// make a device and associate a port with it
2021-07-13 16:35:43 -05:00
$device = Device::factory()->create(); /** @var Device $device */
$port = Port::factory()->make(['ifAdminStatus' => 'up', 'ifOperStatus' => 'up']); /** @var Port $port */
2019-03-12 23:59:03 -05:00
$device->ports()->save($port);
2022-11-05 14:43:54 -05:00
$this->assertTrapLogsMessage("<UNKNOWN>
2019-03-12 23:59:03 -05:00
UDP: [$device->ip]:57123->[192.168.4.4]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 2:15:07:12.87
SNMPv2-MIB::snmpTrapOID.0 IF-MIB::linkDown
IF-MIB::ifIndex.$port->ifIndex $port->ifIndex
IF-MIB::ifAdminStatus.$port->ifIndex down
IF-MIB::ifOperStatus.$port->ifIndex down
IF-MIB::ifDescr.$port->ifIndex GigabitEthernet0/5
IF-MIB::ifType.$port->ifIndex ethernetCsmacd
2022-11-05 14:43:54 -05:00
OLD-CISCO-INTERFACES-MIB::locIfReason.$port->ifIndex \"down\"\n",
[
'SNMP Trap: linkDown down/down ' . $port->ifDescr,
"Interface Disabled : $port->ifDescr (TRAP)",
"Interface went Down : $port->ifDescr (TRAP)",
],
'Could not handle linkDown',
[
2023-08-05 12:12:36 -05:00
[Severity::Error, 'interface', $port->port_id],
[Severity::Notice, 'interface', $port->port_id],
[Severity::Error, 'interface', $port->port_id],
2022-11-05 14:43:54 -05:00
],
$device,
);
2019-03-12 23:59:03 -05:00
$port = $port->fresh(); // refresh from database
$this->assertEquals($port->ifAdminStatus, 'down');
$this->assertEquals($port->ifOperStatus, 'down');
}
2022-11-05 14:43:54 -05:00
public function testLinkUp(): void
2019-03-12 23:59:03 -05:00
{
// make a device and associate a port with it
2021-07-13 16:35:43 -05:00
$device = Device::factory()->create(); /** @var Device $device */
$port = Port::factory()->make(['ifAdminStatus' => 'down', 'ifOperStatus' => 'down']); /** @var Port $port */
2019-03-12 23:59:03 -05:00
$device->ports()->save($port);
2022-11-05 14:43:54 -05:00
$this->assertTrapLogsMessage("<UNKNOWN>
2019-03-12 23:59:03 -05:00
UDP: [$device->ip]:57123->[185.29.68.52]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 2:15:07:18.21
SNMPv2-MIB::snmpTrapOID.0 IF-MIB::linkUp
IF-MIB::ifIndex.$port->ifIndex $port->ifIndex
IF-MIB::ifAdminStatus.$port->ifIndex up
IF-MIB::ifOperStatus.$port->ifIndex up
IF-MIB::ifDescr.$port->ifIndex GigabitEthernet0/5
IF-MIB::ifType.$port->ifIndex ethernetCsmacd
2022-11-05 14:43:54 -05:00
OLD-CISCO-INTERFACES-MIB::locIfReason.$port->ifIndex \"up\"\n",
[
'SNMP Trap: linkUp up/up ' . $port->ifDescr,
"Interface Enabled : $port->ifDescr (TRAP)",
"Interface went Up : $port->ifDescr (TRAP)",
],
'Could not handle linkUp',
[
2023-08-05 12:12:36 -05:00
[Severity::Ok, 'interface', $port->port_id],
[Severity::Notice, 'interface', $port->port_id],
[Severity::Ok, 'interface', $port->port_id],
2022-11-05 14:43:54 -05:00
],
$device,
);
2019-03-12 23:59:03 -05:00
$port = $port->fresh(); // refresh from database
$this->assertEquals($port->ifAdminStatus, 'up');
$this->assertEquals($port->ifOperStatus, 'up');
}
}