Files

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

93 lines
3.5 KiB
PHP
Raw Permalink Normal View History

2019-03-12 23:59:03 -05:00
<?php
/**
* BgpTrapTest.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\BgpPeer;
use App\Models\Device;
2022-11-05 14:43:54 -05:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Config;
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;
2023-10-04 10:17:34 -05:00
use LibreNMS\Util\AutonomousSystem;
2019-03-12 23:59:03 -05:00
2020-04-03 17:13:18 -05:00
class BgpTrapTest extends SnmpTrapTestCase
2019-03-12 23:59:03 -05:00
{
2022-11-05 14:43:54 -05:00
use RequiresDatabase;
use DatabaseTransactions;
public function testBgpUp(): void
2019-03-12 23:59:03 -05:00
{
// Cache it to avoid DNS Lookup
Config::set('astext.1', 'PHPUnit ASTEXT');
2022-11-05 14:43:54 -05:00
$device = Device::factory()->create();
/** @var Device $device */
$bgppeer = BgpPeer::factory()->make(['bgpPeerState' => 'idle', 'bgpPeerRemoteAs' => 1]);
/** @var BgpPeer $bgppeer */
2019-03-12 23:59:03 -05:00
$device->bgppeers()->save($bgppeer);
2022-11-05 14:43:54 -05:00
$this->assertTrapLogsMessage("{{ hostname }}
UDP: [{{ ip }}]:57602->[192.168.5.5]:162
2019-03-12 23:59:03 -05:00
DISMAN-EVENT-MIB::sysUpTimeInstance 302:12:56:24.81
SNMPv2-MIB::snmpTrapOID.0 BGP4-MIB::bgpEstablished
BGP4-MIB::bgpPeerLastError.$bgppeer->bgpPeerIdentifier \"04 00 \"
2022-11-05 14:43:54 -05:00
BGP4-MIB::bgpPeerState.$bgppeer->bgpPeerIdentifier established\n",
2023-10-04 10:17:34 -05:00
"SNMP Trap: BGP Up $bgppeer->bgpPeerIdentifier " . AutonomousSystem::get($bgppeer->bgpPeerRemoteAs)->name() . ' is now established',
2022-11-05 14:43:54 -05:00
'Could not handle bgpEstablished',
2023-08-05 12:12:36 -05:00
[Severity::Ok, 'bgpPeer', $bgppeer->bgpPeerIdentifier],
2022-11-05 14:43:54 -05:00
$device,
);
2019-03-12 23:59:03 -05:00
$bgppeer = $bgppeer->fresh(); // refresh from database
$this->assertEquals($bgppeer->bgpPeerState, 'established');
}
2022-11-05 14:43:54 -05:00
public function testBgpDown(): void
2019-03-12 23:59:03 -05:00
{
// Cache it to avoid DNS Lookup
Config::set('astext.1', 'PHPUnit ASTEXT');
2022-11-05 14:43:54 -05:00
$device = Device::factory()->create();
/** @var Device $device */
$bgppeer = BgpPeer::factory()->make(['bgpPeerState' => 'established', 'bgpPeerRemoteAs' => 1]);
/** @var BgpPeer $bgppeer */
2019-03-12 23:59:03 -05:00
$device->bgppeers()->save($bgppeer);
2022-11-05 14:43:54 -05:00
$this->assertTrapLogsMessage("{{ hostname }}
UDP: [{{ ip }}]:57602->[185.29.68.52]:162
2019-03-12 23:59:03 -05:00
DISMAN-EVENT-MIB::sysUpTimeInstance 302:12:55:33.47
SNMPv2-MIB::snmpTrapOID.0 BGP4-MIB::bgpBackwardTransition
BGP4-MIB::bgpPeerLastError.$bgppeer->bgpPeerIdentifier \"04 00 \"
2022-11-05 14:43:54 -05:00
BGP4-MIB::bgpPeerState.$bgppeer->bgpPeerIdentifier idle\n",
2023-10-04 10:17:34 -05:00
"SNMP Trap: BGP Down $bgppeer->bgpPeerIdentifier " . AutonomousSystem::get($bgppeer->bgpPeerRemoteAs)->name() . ' is now idle',
2022-11-05 14:43:54 -05:00
'Could not handle bgpBackwardTransition',
2023-08-05 12:12:36 -05:00
[Severity::Error, 'bgpPeer', $bgppeer->bgpPeerIdentifier],
2022-11-05 14:43:54 -05:00
$device,
);
2019-03-12 23:59:03 -05:00
$bgppeer = $bgppeer->fresh(); // refresh from database
$this->assertEquals($bgppeer->bgpPeerState, 'idle');
}
}