SNMP Trap Handlers for Ruckus Wireless (#10175)

* pushing handlers and AP event tests

* adding tests for SZ events

* Fixed state handler, added state handler tests

* Style checks and cleanup

* fixed a style issue in RuckusSzClusterInMaintenance.php

* removed SNMP Cold Start trap

* fixed snmptraps.php to remove unhandled traps
This commit is contained in:
Heath Barnhart
2019-05-13 17:53:56 -05:00
committed by Tony Murray
parent 8cc988a162
commit b7053ad064
14 changed files with 851 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?php
/**
* RuckusAssocTrap.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/>.
*
* ruckusEventAssocTrap is sent when a client associated to the AP.
* Contains the clients MAC addr.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class RuckusAssocTrap implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$macRaw = $trap->getOidData($trap->findOid('RUCKUS-EVENT-MIB::ruckusEventClientMacAddr'));
$mac = substr($macRaw, 0, 17);
Log::event("Client $mac associated", $device->device_id, 'trap', 2);
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* RuckusDiassocTrap.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/>.
*
* ruckusEventDiassocTrap is sent when a client disassociates from the AP.
* Contains the clients MAC addr.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class RuckusDiassocTrap implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$macRaw = $trap->getOidData($trap->findOid('RUCKUS-EVENT-MIB::ruckusEventClientMacAddr'));
$mac = substr($macRaw, 0, 17);
Log::event("Client $mac disassociated", $device->device_id, 'trap', 2);
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* RuckusSetError.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/>.
*
* ruckusEventSetErrorTrap is sent when there is error setting a
* value via SNMP. Contains the OID that is errored.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class RuckusSetError implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$errorOidDirty = $trap->getOidData($trap->findOid('RUCKUS-EVENT-MIB::ruckusEventSetErrorOID'));
$errorOid = substr($errorOidDirty, 43);
Log::event("SNMP set error on oid $errorOid", $device->device_id, 'trap', 2);
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* RuckusSzApConf.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/>.
*
* ruckusSZAPConfUpdatedTrap is sent when the SmartZone updates the
* configuration of an access point. Contains a configuration ID
* number string.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Snmptrap\Handlers\RuckusSzSeverity;
use Log;
class RuckusSzApConf implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$location = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPLocation'));
$configId = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZAPConfigID'));
$severity = RuckusSzSeverity::getSeverity($trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity')));
Log::event("AP at location $location configuration updated with config-id $configId", $device->device_id, 'trap', $severity);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* RuckusSzApConnect.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/>.
*
* Ruckus ruckusSZAPConnectedTrap is sent when an access point connects
* to a Smartzone controller.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Snmptrap\Handlers\RuckusSzSeverity;
use Log;
class RuckusSzApConnect implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$location = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPLocation'));
$reason = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventReason'));
$severity = RuckusSzSeverity::getSeverity($trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity')));
Log::event("AP at location $location has connected to the SmartZone with reason $reason", $device->device_id, 'trap', $severity);
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* RuckusSzApMiscEvent.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/>.
*
* Ruckus ruckusSZAPMiscEventTrap occurs when the SmartZone receives
* an event from a connected access point.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Snmptrap\Handlers\RuckusSzSeverity;
use Log;
class RuckusSzApMiscEvent implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$severity = RuckusSzSeverity::getSeverity($trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity')));
$eventDescr = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventDescription'));
Log::event("AP event: $eventDescr", $device->device_id, 'trap', $severity);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* RuckusSzApReboot.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/>.
*
* Ruckus ruckusSZAPRebootTrap occurs when an access point connected
* to the SmartZone reboots.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Snmptrap\Handlers\RuckusSzSeverity;
use Log;
class RuckusSzApReboot implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$location = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventAPLocation'));
$reason = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventReason'));
$severity = RuckusSzSeverity::getSeverity($trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity')));
Log::event("AP at site $location rebooted with reason $reason", $device->device_id, 'trap', $severity);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* RuckusSzClusterInMaintenance.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/>.
*
* Ruckus ruckusSZClusterInMaintenanceStateTrap is sent whtn a
* Virtual Smartzone cluster state changed to "in service" *
*
* Ruckus ruckusSZClusterInMaintenanceStateTrap is sent when the
* Smartzone Cluster enters a maintenance state.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class RuckusSzClusterInMaintenance implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$clusterName = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZClusterName'));
Log::event("Smartzone cluster $clusterName state changed to maintenance", $device->device_id, 'trap', 3);
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* RuckusSzClusterInService.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/>.
*
* Ruckus ruckusSZClusterInServiceStateTrap is sent whtn a
* Virtual Smartzone cluster state changed to "in service"
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class RuckusSzClusterInService implements SnmptrapHandler
{
/**
* Handle snmptrap.
* Data is pre-parsed and delivered as a Trap.
*
* @param Device $device
* @param Trap $trap
* @return void
*/
public function handle(Device $device, Trap $trap)
{
$clusterName = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZClusterName'));
Log::event("Smartzone cluster $clusterName is now in service", $device->device_id, 'trap', 2);
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* RuckusSzSeverity.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/>.
*
* Sets the LibreNMS alert level based on ruckusSZEventSeverity in the
* trap.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2019 KanREN, Inc.
* @author Heath Barnhart <hbarnhart@kanren.net>
*/
namespace LibreNMS\Snmptrap\Handlers;
class RuckusSzSeverity
{
public static function getSeverity($severity)
{
switch ($severity) {
case 'Critical':
$severityNum = 5;
break;
case 'Major':
$severityNum = 4;
break;
case 'Minor':
$severityNum = 4;
break;
case 'Warning':
$severityNum = 3;
break;
case 'Informational':
$severityNum = 2;
break;
default:
$severityNum = 2;
break;
}
return $severityNum;
}
}

View File

@@ -59,6 +59,15 @@ return [
'PowerNet-MIB::outletOff' => \LibreNMS\Snmptrap\Handlers\ApcPduOutletOff::class,
'PowerNet-MIB::outletOn' => \LibreNMS\Snmptrap\Handlers\ApcPduOutletOn::class,
'PowerNet-MIB::outletReboot' => \LibreNMS\Snmptrap\Handlers\ApcPduOutletReboot::class,
'RUCKUS-EVENT-MIB::ruckusEventAssocTrap' => \LibreNMS\Snmptrap\Handlers\RuckusAssocTrap::class,
'RUCKUS-EVENT-MIB::ruckusEventDiassocTrap' => \LibreNMS\Snmptrap\Handlers\RuckusDiassocTrap::class,
'RUCKUS-EVENT-MIB::ruckusEventSetErrorTrap' => \LibreNMS\Snmptrap\Handlers\RuckusSetError::class,
'RUCKUS-SZ-EVENT-MIB::ruckusSZAPMiscEventTrap' => \LibreNMS\Snmptrap\Handlers\RuckusSzApMiscEvent::class,
'RUCKUS-SZ-EVENT-MIB::ruckusSZAPConfUpdatedTrap' => \LibreNMS\Snmptrap\Handlers\RuckusSzApConf::class,
'RUCKUS-SZ-EVENT-MIB::ruckusSZAPRebootTrap' => \LibreNMS\Snmptrap\Handlers\RuckusSzApReboot::class,
'RUCKUS-SZ-EVENT-MIB::ruckusSZAPConnectedTrap' => \LibreNMS\Snmptrap\Handlers\RuckusSzApConnect::class,
'RUCKUS-SZ-EVENT-MIB::ruckusSZClusterInMaintenanceStateTrap' => \LibreNMS\Snmptrap\Handlers\RuckusSzClusterInMaintenance::class,
'RUCKUS-SZ-EVENT-MIB::ruckusSZClusterBackToInServiceTrap' => \LibreNMS\Snmptrap\Handlers\RuckusSzClusterInService::class,
'SNMPv2-MIB::authenticationFailure' => \LibreNMS\Snmptrap\Handlers\AuthenticationFailure::class,
'SNMPv2-MIB::coldStart' => \LibreNMS\Snmptrap\Handlers\ColdBoot::class,
]

View File

@@ -0,0 +1,90 @@
<?php
/**
* RuckusEventTest.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 generic Ruckus Wireless event trap handlers.
*
* @package LibreNMS
* @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;
use LibreNMS\Tests\LaravelTestCase;
class RuckusEventTrap extends LaravelTestCase
{
public function testRuckusAssocTrap()
{
$device = factory(Device::class)->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-EVENT-MIB::ruckusEventAssocTrap
RUCKUS-EVENT-MIB::ruckusEventClientMacAddr \"de:ad:be:ef:11:221.0.5.1.1.1.2.2\"";
$trap = new Trap($trapText);
$message = "Client de:ad:be:ef:11:22 associated";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle ruckusEventAssocTrap');
}
public function testRuckusDiassocTrap()
{
$device = factory(Device::class)->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-EVENT-MIB::ruckusEventDiassocTrap
RUCKUS-EVENT-MIB::ruckusEventClientMacAddr \"de:ad:be:ef:33:441.0.5.1.1.1.2.2\"";
$trap = new Trap($trapText);
$message = "Client de:ad:be:ef:33:44 disassociated";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle ruckusEventDiassocTrap');
}
public function testRuckusSetErrorTrap()
{
$device = factory(Device::class)->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-EVENT-MIB::ruckusEventSetErrorTrap
RUCKUS-EVENT-MIB::ruckusEventSetErrorOID Wrong Type (should be OBJECT IDENTIFIER): \"1.3.6.1.2.1.25.1.1.0.5.1.1.1.2.2\"";
$trap = new Trap($trapText);
$message = "SNMP set error on oid 1.3.6.1.2.1.25.1.1.0.5.1.1.1.2.2";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle ruckusEventSetErrorTrap');
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* RuckusSzClusterStateTest.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 cluster state trap handlers..
*
* @package LibreNMS
* @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;
use LibreNMS\Tests\LaravelTestCase;
class RuckusSzClusterStateTest extends LaravelTestCase
{
public function testClusterInMaintenance()
{
$device = factory(Device::class)->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::ruckusSZClusterInMaintenanceStateTrap
RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity.0 \"Critical\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventCode.0 \"807\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventType.0 \"clusterInMaintenanceState\"
RUCKUS-SZ-EVENT-MIB::ruckusSZClusterName.0 \"$device->hostname\"";
$trap = new Trap($trapText);
$message = "Smartzone cluster $device->hostname state changed to maintenance";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 3);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle ruckusSZClusterInMaintenanceStateTrap');
}
public function testClusterInService()
{
$device = factory(Device::class)->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::ruckusSZClusterBackToInServiceTrap
RUCKUS-SZ-EVENT-MIB::ruckusSZEventSeverity.0 \"Informational\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventCode.0 \"808\"
RUCKUS-SZ-EVENT-MIB::ruckusSZEventType.0 \"clusterBackToInService\"
RUCKUS-SZ-EVENT-MIB::ruckusSZClusterName.0 \"$device->hostname\"";
$trap = new Trap($trapText);
$message = "Smartzone cluster $device->hostname is now in service";
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle ruckusSZClusterBackToInServiceTrap');
}
}

View File

@@ -0,0 +1,140 @@
<?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.
*
* @package LibreNMS
* @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;
use LibreNMS\Tests\LaravelTestCase;
class RuckusSzEventTest extends LaravelTestCase
{
public function testSzApConf()
{
$device = factory(Device::class)->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 = factory(Device::class)->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 = factory(Device::class)->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 = factory(Device::class)->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');
}
}