Add APC SmartAvrReducing trap handlers (#13839)

* add new classes

* add AvrReducing handler

* Add AvrReducing Test

* add AvrReducingOff handler

* add AvrReducingOff Test
This commit is contained in:
Andy Norwood
2022-03-10 20:13:09 +00:00
committed by GitHub
parent 48e68ec1dd
commit 20e64d792c
5 changed files with 206 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
<?php
/**
* ApcSmartAvrReducing.php
*
* APC UPS Compensating for a high input voltage.
*
* -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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @author Andy Norwood(bonzo81)
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class ApcSmartAvrReducing 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)
{
$message = $trap->getOidData($trap->findOid('PowerNet-MIB::mtrapargsString'));
Log::event($message, $device->device_id, 'trap', 3);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* ApcSmartAvrReducingOff.php
*
* APC UPS No longer compensating for a high input voltage.
*
* -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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @author Andy Norwood(bonzo81)
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class ApcSmartAvrReducingOff 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)
{
$message = $trap->getOidData($trap->findOid('PowerNet-MIB::mtrapargsString'));
Log::event($message, $device->device_id, 'trap', 1);
}
}

View File

@@ -100,6 +100,8 @@ return [
'PowerNet-MIB::rPDUNearOverloadCleared' => \LibreNMS\Snmptrap\Handlers\ApcPduNearOverloadCleared::class,
'PowerNet-MIB::rPDUOverload' => \LibreNMS\Snmptrap\Handlers\ApcPduOverload::class,
'PowerNet-MIB::rPDUOverloadCleared' => \LibreNMS\Snmptrap\Handlers\ApcPduOverloadCleared::class,
'PowerNet-MIB::smartAvrReducing' => \LibreNMS\Snmptrap\Handlers\ApcSmartAvrReducing::class,
'PowerNet-MIB::smartAvrReducingOff' => \LibreNMS\Snmptrap\Handlers\ApcSmartAvrReducingOff::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,

View File

@@ -0,0 +1,53 @@
<?php
/**
* ApcSmartAvrReducingOffTest.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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @author Andy Norwood(bonzo81)
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
class ApcSmartAvrReducingOffTest extends SnmpTrapTestCase
{
/**
* Test ApcSmartAvrReducingOff handle
*
* @return void
*/
public function testApcSmartAvrReducingOff()
{
$device = Device::factory()->create(); /** @var Device $device */
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[10.0.0.1]:162
SNMPv2-MIB::sysUpTime.0 459:20:47:26.90
SNMPv2-MIB::snmpTrapOID.0 PowerNet-MIB::smartAvrReducingOff
PowerNet-MIB::mtrapargsString \"UPS: No longer compensating for a high input voltage.\"
SNMPv2-MIB::snmpTrapEnterprise.0 PowerNet-MIB::apc";
$trap = new Trap($trapText);
$message = 'UPS: No longer compensating for a high input voltage.';
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 1);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle testApcSmartAvrReducingOff trap');
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* ApcSmartAvrReducingTest.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 <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @author Andy Norwood(bonzo81)
*/
namespace LibreNMS\Tests\Feature\SnmpTraps;
use App\Models\Device;
use LibreNMS\Snmptrap\Dispatcher;
use LibreNMS\Snmptrap\Trap;
class ApcSmartAvrReducingTest extends SnmpTrapTestCase
{
/**
* Test ApcSmartAvrReducing handle
*
* @return void
*/
public function testApcSmartAvrReducing()
{
$device = Device::factory()->create(); /** @var Device $device */
$trapText = "$device->hostname
UDP: [$device->ip]:57602->[10.0.0.1]:162
SNMPv2-MIB::sysUpTime.0 459:20:47:26.90
SNMPv2-MIB::snmpTrapOID.0 PowerNet-MIB::smartAvrReducing
PowerNet-MIB::mtrapargsString \"UPS: Compensating for a high input voltage.\"
SNMPv2-MIB::snmpTrapEnterprise.0 PowerNet-MIB::apc";
$trap = new Trap($trapText);
$message = 'UPS: Compensating for a high input voltage.';
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 3);
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle testApcSmartAvrReducing trap');
}
}