mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
HP Fault Traps (#13254)
* HP Fault Trap * Add typehints * Fix style * Fix style * Try to fix wrong test * Next try
This commit is contained in:
38
LibreNMS/Snmptrap/Handlers/HpFault.php
Normal file
38
LibreNMS/Snmptrap/Handlers/HpFault.php
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LibreNMS\Snmptrap\Handlers;
|
||||||
|
|
||||||
|
use App\Models\Device;
|
||||||
|
use LibreNMS\Interfaces\SnmptrapHandler;
|
||||||
|
use LibreNMS\Snmptrap\Trap;
|
||||||
|
use Log;
|
||||||
|
|
||||||
|
class HpFault 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)
|
||||||
|
{
|
||||||
|
$type = $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfLogFaultType'));
|
||||||
|
switch ($type) {
|
||||||
|
case 'badXcvr':
|
||||||
|
Log::event('Fault - CRC Error ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), $device->device_id, $type, 4);
|
||||||
|
break;
|
||||||
|
case 'badCable':
|
||||||
|
Log::event('Fault - Bad Cable ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), $device->device_id, $type, 4);
|
||||||
|
break;
|
||||||
|
case 'bcastStorm':
|
||||||
|
Log::event('Fault - Broadcaststorm ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), $device->device_id, $type, 5);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log::event('Fault - Unhandled ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), $device->device_id, $type, 2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -105,5 +105,6 @@ return [
|
|||||||
'UPS-MIB::upsTraps.0.1' => \LibreNMS\Snmptrap\Handlers\UpsTrapsOnBattery::class,
|
'UPS-MIB::upsTraps.0.1' => \LibreNMS\Snmptrap\Handlers\UpsTrapsOnBattery::class,
|
||||||
'VEEAM-MIB::onBackupJobCompleted' => \LibreNMS\Snmptrap\Handlers\VeeamBackupJobCompleted::class,
|
'VEEAM-MIB::onBackupJobCompleted' => \LibreNMS\Snmptrap\Handlers\VeeamBackupJobCompleted::class,
|
||||||
'VEEAM-MIB::onVmBackupJobCompleted' => \LibreNMS\Snmptrap\Handlers\VeeamVmBackupJobCompleted::class,
|
'VEEAM-MIB::onVmBackupJobCompleted' => \LibreNMS\Snmptrap\Handlers\VeeamVmBackupJobCompleted::class,
|
||||||
|
'HP-ICF-FAULT-FINDER-MIB::hpicfFaultFinderTrap' => \LibreNMS\Snmptrap\Handlers\HpFault::class,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
96
tests/Feature/SnmpTraps/HpFaultTest.php
Normal file
96
tests/Feature/SnmpTraps/HpFaultTest.php
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* NetgearFailedUserLoginTest.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
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace LibreNMS\Tests\Feature\SnmpTraps;
|
||||||
|
|
||||||
|
use App\Models\Device;
|
||||||
|
use LibreNMS\Snmptrap\Dispatcher;
|
||||||
|
use LibreNMS\Snmptrap\Trap;
|
||||||
|
|
||||||
|
class HpFaultTest extends SnmpTrapTestCase
|
||||||
|
{
|
||||||
|
public function testBadCable(): void
|
||||||
|
{
|
||||||
|
$device = Device::factory()->create(); /** @var Device $device */
|
||||||
|
$trapText = "$device->hostname
|
||||||
|
UDP: [$device->ip]:44298->[192.168.5.5]:162
|
||||||
|
SNMPv2-MIB::snmpTrapOID.0 HP-ICF-FAULT-FINDER-MIB::hpicfFaultFinderTrap
|
||||||
|
DISMAN-EVENT-MIB::sysUpTimeInstance 133:19:41:09.17
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfLogFaultType.1510 badCable
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfLogAction.1510 warn
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfLogSeverity.1510 medium
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL.0.1510 http:\/\/$device->ip\/cgi\/fDetail?index=1510
|
||||||
|
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 $device->ip
|
||||||
|
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 public
|
||||||
|
SNMPv2-MIB::snmpTrapEnterprise.0 HP-ICF-OID::hpicfCommonTraps";
|
||||||
|
|
||||||
|
$message = "Fault - Bad Cable http:\/\/$device->ip\/cgi\/fDetail?index=1510";
|
||||||
|
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'badCable', 4);
|
||||||
|
|
||||||
|
$trap = new Trap($trapText);
|
||||||
|
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle HP-ICF-FAULT-FINDER-MIB::hpicfFaultFinderTrap trap');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBadDriver(): void
|
||||||
|
{
|
||||||
|
$device = Device::factory()->create(); /** @var Device $device */
|
||||||
|
$trapText = "$device->hostname
|
||||||
|
UDP: [$device->ip]:44298->[192.168.5.5]:162
|
||||||
|
SNMPv2-MIB::snmpTrapOID.0 HP-ICF-FAULT-FINDER-MIB::hpicfFaultFinderTrap
|
||||||
|
DISMAN-EVENT-MIB::sysUpTimeInstance 133:19:41:09.17
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfLogFaultType.1510 badDriver
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfLogAction.1510 warn
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfLogSeverity.1510 medium
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL.0.1510 http:\/\/$device->ip\/cgi\/fDetail?index=1510
|
||||||
|
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 $device->ip
|
||||||
|
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 public
|
||||||
|
SNMPv2-MIB::snmpTrapEnterprise.0 HP-ICF-OID::hpicfCommonTraps";
|
||||||
|
|
||||||
|
$message = "Fault - Unhandled http:\/\/$device->ip\/cgi\/fDetail?index=1510";
|
||||||
|
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'badDriver', 2);
|
||||||
|
|
||||||
|
$trap = new Trap($trapText);
|
||||||
|
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle HP-ICF-FAULT-FINDER-MIB::hpicfFaultFinderTrap trap');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBcastStorm(): void
|
||||||
|
{
|
||||||
|
$device = Device::factory()->create(); /** @var Device $device */
|
||||||
|
$trapText = "$device->hostname
|
||||||
|
UDP: [$device->ip]:44298->[192.168.5.5]:162
|
||||||
|
SNMPv2-MIB::snmpTrapOID.0 HP-ICF-FAULT-FINDER-MIB::hpicfFaultFinderTrap
|
||||||
|
DISMAN-EVENT-MIB::sysUpTimeInstance 133:19:41:09.17
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfLogFaultType.1510 bcastStorm
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfLogAction.1510 warn
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfLogSeverity.1510 medium
|
||||||
|
HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL.0.1510 http:\/\/$device->ip\/cgi\/fDetail?index=1510
|
||||||
|
SNMP-COMMUNITY-MIB::snmpTrapAddress.0 $device->ip
|
||||||
|
SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 public
|
||||||
|
SNMPv2-MIB::snmpTrapEnterprise.0 HP-ICF-OID::hpicfCommonTraps";
|
||||||
|
|
||||||
|
$message = "Fault - Broadcaststorm http:\/\/$device->ip\/cgi\/fDetail?index=1510";
|
||||||
|
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'bcastStorm', 5);
|
||||||
|
|
||||||
|
$trap = new Trap($trapText);
|
||||||
|
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle HP-ICF-FAULT-FINDER-MIB::hpicfFaultFinderTrap trap');
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user