Added snmp trap OnBattery for UPS-MIB

This commit is contained in:
TheGreatDoc
2020-06-04 08:10:05 +02:00
parent b6875b73c7
commit 71e87975fe
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?php
/**
* UpsTrapsOnBattery.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
* @author TheGreatDoc
*/
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
class UpsTrapsOnBattery 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)
{
$remaining = $trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining.0'));
$time = $trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery.0'));
Log::event("UPS running on battery for $time seconds. Estimated $remaining minutes remaining", $device->device_id, 'trap', 5);
}
}

View File

@@ -101,5 +101,6 @@ return [
'VMWARE-VMINFO-MIB::vmwVmSuspended' => \LibreNMS\Snmptrap\Handlers\VmwVmSuspended::class,
'OSPF-TRAP-MIB::ospfIfStateChange' => \LibreNMS\Snmptrap\Handlers\OspfIfStateChange::class,
'OSPF-TRAP-MIB::ospfNbrStateChange' => \LibreNMS\Snmptrap\Handlers\OspfNbrStateChange::class,
'UPS-MIB::upsTraps.0.1' => \LibreNMS\Snmptrap\Handlers\UpsTrapsOnBattery::class,
]
];