librenms-librenms/tests/Feature/SnmpTraps/RuckusSzEventTest.php
Jellyfrog 50c8033099 Laravel 8.x Shift (#12235)
* Shift HTTP kernel and middleware

* Shift service providers

* Shift console routes

* Shift to class based factories

* Namespace seeders

* Shift PSR-4 autoloading

* Default config files

In an effort to make upgrading the constantly changing config files
easier, Shift defaulted them. This allows you to review the commit
diff for once for customizations when you are done Shifting.

Moving forward, consider using ENV variables or create a separate
config file to allow the core config files to remain as default
as possible.

* Shift Laravel dependencies

* Shift return type of base TestCase methods

From the [PHPUnit 8 release notes][1], the `TestCase` methods below now declare a `void` return type:

- `setUpBeforeClass()`
- `setUp()`
- `assertPreConditions()`
- `assertPostConditions()`
- `tearDown()`
- `tearDownAfterClass()`
- `onNotSuccessfulTest()`

[1]: https://phpunit.de/announcements/phpunit-8.html

* Shift cleanup

* console routes

* composer update

* factories

* phpunit

* bootstrap pagination

* model factory

* wip

* Apply fixes from StyleCI (#12236)

* wip

* Apply fixes from StyleCI (#12238)

* wip

* wip

* wip

* wip

* Apply fixes from StyleCI (#12240)

* wip

* Apply fixes from StyleCI (#12242)

* composer update

* Bump to PHP 7.3 minimum

Co-authored-by: Laravel Shift <shift@laravelshift.com>
2020-11-03 10:18:31 -06:00

139 lines
5.8 KiB
PHP

<?php
/**
* RuckusSzEventTest.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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Tests Ruckus Wireless SmartZone Event trap handlers.
*
* @link http://librenms.org
* @copyright 2019 Heath Barnhart
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
class RuckusSzEventTest extends SnmpTrapTestCase
{
public function testSzApConf()
{
$device = Device::factory()->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 RUCKUS-SZ-EVENT-MIB::ruckusSZAPConfUpdatedTrap
RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity.0 \"Informational\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventCode.0 \"110\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventType.0 \"apConfUpdated\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPName.0 \"$device->hostname\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPMacAddr.0 \"de:ad:be:ef:33:40\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPIP.0 \"$device->ip\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPLocation.0 \"$device->location\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPDescription.0 \"$device->sysDescr\"
RUCKUS-SZ-EVENT-MIB::ruckusSZAPConfigID.0 \"2f860f70-6b88-11e9-a3c5-000000937916\"";
$trap = new Trap($trapText);
$message = "AP at location $device->location configuration updated with config-id 2f860f70-6b88-11e9-a3c5-000000937916";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle ruckusSZAPConfUpdatedTrap');
}
public function testSzApConnect()
{
$device = Device::factory()->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 RUCKUS-SZ-EVENT-MIB::ruckusSZAPConnectedTrap
RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity.0 \"Informational\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventCode.0 \"312\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventType.0 \"apConnected\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPName.0 \"$device->hostname\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPMacAddr.0 \"de:ad:be:ef:33:40\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPIP.0 \"$device->ip\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPLocation.0 \"$device->location\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPDescription.0 \"$device->sysDescr\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventReason.0 \"AP connected after rebooting\"";
$trap = new Trap($trapText);
$message = "AP at location $device->location has connected to the SmartZone with reason AP connected after rebooting";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle ruckusSZAPConnectedTrap');
}
public function testSzApMiscEvent()
{
$device = Device::factory()->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 RUCKUS-SZ-EVENT-MIB::ruckusSZAPMiscEventTrap
RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity.0 \"Minor\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventCode.0 \"322\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventType.0 \"apWLANStateChanged\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPName.0 \"$device->hostname\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPMacAddr.0 \"de:ad:be:ef:33:40\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPIP.0 \"$device->ip\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPLocation.0 \"$device->location\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPDescription.0 \"$device->sysDescr\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventDescription.0 \"Test AP event has occured\"";
$trap = new Trap($trapText);
$message = 'AP event: Test AP event has occured';
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle ruckusSZAPMiscEventTrap');
}
public function testSzApRebooted()
{
$device = Device::factory()->create();
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[192.168.5.5]:162
DISMAN-EVENT-MIB::sysUpTimeInstance 26:19:43:37.24
SNMPv2-MIB::snmpTrapOID.0 RUCKUS-SZ-EVENT-MIB::ruckusSZAPRebootTrap
RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity.0 \"Critical\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventCode.0 \"301\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventType.0 \"apRebootByUser\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPName.0 \"$device->hostname\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPMacAddr.0 \"de:ad:be:ef:33:40\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPIP.0 \"$device->ip\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPLocation.0 \"$device->location\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPDescription.0 \"$device->sysDescr\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventReason.0 \"AP rebooted by controller user\"";
$trap = new Trap($trapText);
$message = "AP at site $device->location rebooted with reason AP rebooted by controller user";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 5);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle ruckusSZAPRebootTrap');
}
}