mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 10:28:13 +00:00
Tripplite snmp trap handling (#12832)
* Tripplite snmp trap handling * remove extra import
This commit is contained in:
parent
e40e1069d5
commit
aa83e6aa1a
47
LibreNMS/Snmptrap/Handlers/Tripplite.php
Normal file
47
LibreNMS/Snmptrap/Handlers/Tripplite.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/*
|
||||
* Tripplite.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/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2021 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Snmptrap\Handlers;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
|
||||
class Tripplite
|
||||
{
|
||||
protected function getSeverity(Trap $trap): int
|
||||
{
|
||||
return Arr::get([
|
||||
'critical' => 5,
|
||||
'warning' => 4,
|
||||
'info' => 2,
|
||||
'status' => 3,
|
||||
], $trap->getOidData('TRIPPLITE-PRODUCTS::tlpAlarmType'), 4);
|
||||
}
|
||||
|
||||
protected function describe(Trap $trap): string
|
||||
{
|
||||
return 'Trap Alarm ' . $trap->getOidData('TRIPPLITE-PRODUCTS::tlpAlarmState') . ': ' . $trap->getOidData('TRIPPLITE-PRODUCTS::tlpAlarmDetail');
|
||||
}
|
||||
}
|
38
LibreNMS/Snmptrap/Handlers/TrippliteAlarmAdded.php
Normal file
38
LibreNMS/Snmptrap/Handlers/TrippliteAlarmAdded.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/*
|
||||
* TrippliteAlarmAdded.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/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2021 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Snmptrap\Handlers;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Interfaces\SnmptrapHandler;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
|
||||
class TrippliteAlarmAdded extends Tripplite implements SnmptrapHandler
|
||||
{
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
\Log::event($this->describe($trap), $device->device_id, 'trap', $this->getSeverity($trap));
|
||||
}
|
||||
}
|
38
LibreNMS/Snmptrap/Handlers/TrippliteAlarmRemoved.php
Normal file
38
LibreNMS/Snmptrap/Handlers/TrippliteAlarmRemoved.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/*
|
||||
* TrippliteAlarmRemoved.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/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2021 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Snmptrap\Handlers;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Interfaces\SnmptrapHandler;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
|
||||
class TrippliteAlarmRemoved extends Tripplite implements SnmptrapHandler
|
||||
{
|
||||
public function handle(Device $device, Trap $trap)
|
||||
{
|
||||
\Log::event($this->describe($trap), $device->device_id, 'trap', $this->getSeverity($trap));
|
||||
}
|
||||
}
|
@ -93,6 +93,8 @@ return [
|
||||
'SNMPv2-MIB::authenticationFailure' => \LibreNMS\Snmptrap\Handlers\AuthenticationFailure::class,
|
||||
'SNMPv2-MIB::coldStart' => \LibreNMS\Snmptrap\Handlers\ColdBoot::class,
|
||||
'SNMPv2-MIB::warmStart' => \LibreNMS\Snmptrap\Handlers\WarmBoot::class,
|
||||
'TRIPPLITE-PRODUCTS::tlpNotificationsAlarmEntryAdded' => \LibreNMS\Snmptrap\Handlers\TrippliteAlarmAdded::class,
|
||||
'TRIPPLITE-PRODUCTS::tlpNotificationsAlarmEntryRemoved' => \LibreNMS\Snmptrap\Handlers\TrippliteAlarmRemoved::class,
|
||||
'VMWARE-VMINFO-MIB::vmwVmHBDetected' => \LibreNMS\Snmptrap\Handlers\VmwVmHBDetected::class,
|
||||
'VMWARE-VMINFO-MIB::vmwVmHBLost' => \LibreNMS\Snmptrap\Handlers\VmwVmHBLost::class,
|
||||
'VMWARE-VMINFO-MIB::vmwVmPoweredOn' => \LibreNMS\Snmptrap\Handlers\VmwVmPoweredOn::class,
|
||||
|
35
mibs/poweralert/TRIPPLITE
Normal file
35
mibs/poweralert/TRIPPLITE
Normal file
@ -0,0 +1,35 @@
|
||||
-- ------------------------------------------------------
|
||||
-- TRIPP LITE MIB
|
||||
-- Copyright (c) 1999-2018 Tripp Lite
|
||||
-- All rights reserved
|
||||
--
|
||||
-- Revision History:
|
||||
-- 06/22/2016 Restructured Tripp Lite MIB files
|
||||
-- ------------------------------------------------------
|
||||
|
||||
-- TrippLite { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) tripplite(850) }
|
||||
|
||||
TRIPPLITE DEFINITIONS ::= BEGIN
|
||||
|
||||
IMPORTS
|
||||
MODULE-IDENTITY,
|
||||
enterprises
|
||||
FROM SNMPv2-SMI;
|
||||
|
||||
tripplite MODULE-IDENTITY
|
||||
LAST-UPDATED "201606221115Z"
|
||||
ORGANIZATION "Tripp Lite"
|
||||
CONTACT-INFO
|
||||
"Software Engineering
|
||||
Tripp Lite
|
||||
1111 W. 35th St.
|
||||
Chicago, IL 60609"
|
||||
DESCRIPTION
|
||||
"The base MIB module that defines the root objects from Tripp Lite's
|
||||
OID tree (850)."
|
||||
REVISION "201606221115Z"
|
||||
DESCRIPTION
|
||||
"Restructured Tripp Lite MIB files"
|
||||
::= { enterprises 850 }
|
||||
|
||||
END
|
File diff suppressed because it is too large
Load Diff
91
tests/Feature/SnmpTraps/TrippliteTrapTest.php
Normal file
91
tests/Feature/SnmpTraps/TrippliteTrapTest.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/*
|
||||
* TrippliteTrapTest.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/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2021 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Tests\Feature\SnmpTraps;
|
||||
|
||||
use App\Models\Device;
|
||||
use LibreNMS\Snmptrap\Dispatcher;
|
||||
use LibreNMS\Snmptrap\Trap;
|
||||
|
||||
class TrippliteTrapTest extends SnmpTrapTestCase
|
||||
{
|
||||
public function testTlpNotificationsAlarmEntryAdded()
|
||||
{
|
||||
$device = Device::factory()->create();
|
||||
|
||||
$trapText = "$device->hostname
|
||||
UDP: [$device->ip]:46024->[1.1.1.1]:162
|
||||
DISMAN-EVENT-MIB::sysUpTimeInstance 0:1:55:34.92
|
||||
SNMPv2-MIB::snmpTrapOID.0 TRIPPLITE-PRODUCTS::tlpNotificationsAlarmEntryAdded
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmId 6
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmDescr TRIPPLITE-PRODUCTS::tlpUpsAlarmOnBattery
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmTime 0:1:56:20.44
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmTableRef TRIPPLITE-PRODUCTS::tlpDeviceTable
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmTableRowRef TRIPPLITE-PRODUCTS::tlpDeviceIndex.1
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmDetail On Battery
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmType warning
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmState active
|
||||
TRIPPLITE-PRODUCTS::tlpDeviceName.1 $device->sysDescr
|
||||
TRIPPLITE-PRODUCTS::tlpDeviceLocation.1 $device->location
|
||||
TRIPPLITE-PRODUCTS::tlpAgentMAC.0 00:06:67:AE:BE:13
|
||||
TRIPPLITE-PRODUCTS::tlpAgentUuid.0 c94e376a-8080-44fb-96ad-0fe6583d1c4a";
|
||||
|
||||
$trap = new Trap($trapText);
|
||||
|
||||
$message = 'Trap Alarm active: On Battery';
|
||||
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 4);
|
||||
|
||||
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle tlpNotificationsAlarmEntryAdded');
|
||||
}
|
||||
|
||||
public function testTlpNotificationsAlarmEntryRemoved()
|
||||
{
|
||||
$device = Device::factory()->create();
|
||||
|
||||
$trapText = "$device->hostname
|
||||
UDP: [$device->ip]:46024->[1.1.1.1]:162
|
||||
DISMAN-EVENT-MIB::sysUpTimeInstance 0:1:56:40.26
|
||||
SNMPv2-MIB::snmpTrapOID.0 TRIPPLITE-PRODUCTS::tlpNotificationsAlarmEntryRemoved
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmId 6
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmDescr TRIPPLITE-PRODUCTS::tlpUpsAlarmOnBattery
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmTime 0:1:56:20.44
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmTableRef TRIPPLITE-PRODUCTS::tlpDeviceTable
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmTableRowRef TRIPPLITE-PRODUCTS::tlpDeviceIndex.1
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmDetail On Utility Power
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmType info
|
||||
TRIPPLITE-PRODUCTS::tlpAlarmState inactive
|
||||
TRIPPLITE-PRODUCTS::tlpDeviceName.1 $device->sysDescr
|
||||
TRIPPLITE-PRODUCTS::tlpDeviceLocation.1 $device->location
|
||||
TRIPPLITE-PRODUCTS::tlpAgentMAC.0 00:06:67:AE:BE:13
|
||||
TRIPPLITE-PRODUCTS::tlpAgentUuid.0 c94e376a-8080-44fb-96ad-0fe6583d1c4a";
|
||||
|
||||
$trap = new Trap($trapText);
|
||||
|
||||
$message = 'Trap Alarm inactive: On Utility Power';
|
||||
\Log::shouldReceive('event')->once()->with($message, $device->device_id, 'trap', 2);
|
||||
|
||||
$this->assertTrue(Dispatcher::handle($trap), 'Could not handle tlpNotificationsAlarmEntryRemoved');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user