Severity Enum (#14620)

* Severity Enum
Replace old Alert constants

* Fix whitespace

* Additional uses

* style fixes

* Fix test too

* More missed locations

* More
This commit is contained in:
Tony Murray 2023-08-05 12:12:36 -05:00 committed by GitHub
parent 9382959c8c
commit d1b7004fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
172 changed files with 591 additions and 473 deletions

View File

@ -34,8 +34,8 @@ use App\Facades\DeviceCache;
use App\Models\AlertTransport;
use App\Models\Eventlog;
use LibreNMS\Config;
use LibreNMS\Enum\Alert;
use LibreNMS\Enum\AlertState;
use LibreNMS\Enum\Severity;
use LibreNMS\Exceptions\AlertTransportDeliveryException;
use LibreNMS\Polling\ConnectivityHelper;
use LibreNMS\Util\Time;
@ -449,7 +449,7 @@ class RunAlerts
if ($this->isParentDown($alert['device_id'])) {
$noiss = true;
Eventlog::log('Skipped alerts because all parent devices are down', $alert['device_id'], 'alert', 1);
Eventlog::log('Skipped alerts because all parent devices are down', $alert['device_id'], 'alert', Severity::Ok);
}
if ($alert['state'] == AlertState::RECOVERED && $rextra['recovery'] == false) {
@ -511,7 +511,7 @@ class RunAlerts
$tmp = $instance->deliverAlert($obj, $item['opts'] ?? []);
$this->alertLog($tmp, $obj, $obj['transport']);
} catch (AlertTransportDeliveryException $e) {
Eventlog::log($e->getMessage(), $obj['device_id'], 'alert', Alert::ERROR);
Eventlog::log($e->getMessage(), $obj['device_id'], 'alert', Severity::Error);
$this->alertLog($e->getMessage(), $obj, $obj['transport']);
} catch (\Exception $e) {
$this->alertLog($e, $obj, $obj['transport']);
@ -537,25 +537,22 @@ class RunAlerts
AlertState::BETTER => 'got better',
];
if ($obj['state'] == AlertState::RECOVERED) {
$severity = Alert::OK;
} elseif ($obj['state'] == AlertState::ACTIVE) {
$severity = Alert::SEVERITIES[$obj['severity']] ?? Alert::UNKNOWN;
} elseif ($obj['state'] == AlertState::ACKNOWLEDGED) {
$severity = Alert::NOTICE;
} else {
$severity = Alert::UNKNOWN;
}
$severity = match ($obj['state']) {
AlertState::RECOVERED => Severity::Ok,
AlertState::ACTIVE => Severity::tryFrom((int) $obj['severity']) ?? Severity::Unknown,
AlertState::ACKNOWLEDGED => Severity::Notice,
default => Severity::Unknown,
};
if ($result === true) {
echo 'OK';
Eventlog::log('Issued ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "'", $obj['device_id'], 'alert', $severity);
} elseif ($result === false) {
echo 'ERROR';
Eventlog::log('Could not issue ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "'", $obj['device_id'], null, Alert::ERROR);
Eventlog::log('Could not issue ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "'", $obj['device_id'], null, Severity::Error);
} else {
echo "ERROR: $result\r\n";
Eventlog::log('Could not issue ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "' Error: " . $result, $obj['device_id'], 'error', Alert::ERROR);
Eventlog::log('Could not issue ' . $prefix[$obj['state']] . " for rule '" . $obj['name'] . "' to transport '" . $transport . "' Error: " . $result, $obj['device_id'], 'error', Severity::Error);
}
}

View File

@ -29,6 +29,7 @@ use App\Models\ComponentPref;
use App\Models\ComponentStatusLog;
use App\Models\Eventlog;
use Illuminate\Support\Arr;
use LibreNMS\Enum\Severity;
use Log;
class Component
@ -242,7 +243,7 @@ class Component
}
$component->save();
Eventlog::log($message, $component->device_id, 'component', 3, $component->id);
Eventlog::log($message, $component->device_id, 'component', Severity::Notice, $component->id);
}
// update preferences
@ -258,18 +259,18 @@ class Component
$invalid->forget($existing->id);
$existing->fill(['value' => $value]);
if ($existing->isDirty()) {
Eventlog::log("Component: $component->type($component->id). Attribute: $attribute, was modified from: " . $existing->getOriginal('value') . ", to: $value", $device_id, 'component', 3, $component->id);
Eventlog::log("Component: $component->type($component->id). Attribute: $attribute, was modified from: " . $existing->getOriginal('value') . ", to: $value", $device_id, 'component', Severity::Notice, $component->id);
$existing->save();
}
} else {
$component->prefs()->save(new ComponentPref(['attribute' => $attribute, 'value' => $value]));
Eventlog::log("Component: $component->type($component->id). Attribute: $attribute, was added with value: $value", $component->device_id, 'component', 3, $component->id);
Eventlog::log("Component: $component->type($component->id). Attribute: $attribute, was added with value: $value", $component->device_id, 'component', Severity::Notice, $component->id);
}
}
foreach ($invalid as $pref) {
$pref->delete();
Eventlog::log("Component: $component->type($component->id). Attribute: $pref->attribute, was deleted.", $component->device_id, 'component', 4);
Eventlog::log("Component: $component->type($component->id). Attribute: $pref->attribute, was deleted.", $component->device_id, 'component', Severity::Warning);
}
});

View File

@ -32,7 +32,7 @@ use DeviceCache;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Enum\Alert;
use LibreNMS\Enum\Severity;
use LibreNMS\Util\Debug;
use LibreNMS\Util\Oid;
use LibreNMS\Util\Rewrite;
@ -467,9 +467,9 @@ class NetSnmpQuery implements SnmpQueryInterface
{
if ($code) {
if (Str::startsWith($error, 'Invalid authentication protocol specified')) {
Eventlog::log('Unsupported SNMP authentication algorithm - ' . $code, $this->device, 'poller', Alert::ERROR);
Eventlog::log('Unsupported SNMP authentication algorithm - ' . $code, $this->device, 'poller', Severity::Error);
} elseif (Str::startsWith($error, 'Invalid privacy protocol specified')) {
Eventlog::log('Unsupported SNMP privacy algorithm - ' . $code, $this->device, 'poller', Alert::ERROR);
Eventlog::log('Unsupported SNMP privacy algorithm - ' . $code, $this->device, 'poller', Severity::Error);
}
Log::debug('Exitcode: ' . $code, [$error]);
}

View File

@ -0,0 +1,13 @@
<?php
namespace LibreNMS\Enum;
enum Severity: int
{
case Unknown = 0;
case Ok = 1;
case Info = 2;
case Notice = 3;
case Warning = 4;
case Error = 5;
}

View File

@ -29,6 +29,7 @@ use App\Models\Device;
use App\Models\Eventlog;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\Module;
use LibreNMS\OS;
use LibreNMS\RRD\RrdDefinition;
@ -61,7 +62,7 @@ class Core implements Module
]);
foreach ($device->getDirty() as $attribute => $value) {
Eventlog::log($value . ' -> ' . $device->$attribute, $device, 'system', 3);
Eventlog::log($value . ' -> ' . $device->$attribute, $device, 'system', Severity::Notice);
$os->getDeviceArray()[$attribute] = $value; // update device array
}
@ -69,7 +70,7 @@ class Core implements Module
$device->os = self::detectOS($device, false);
if ($device->isDirty('os')) {
Eventlog::log('Device OS changed: ' . $device->getOriginal('os') . ' -> ' . $device->os, $device, 'system', 3);
Eventlog::log('Device OS changed: ' . $device->getOriginal('os') . ' -> ' . $device->os, $device, 'system', Severity::Notice);
$os->getDeviceArray()['os'] = $device->os;
echo 'Changed ';
@ -272,7 +273,7 @@ class Core implements Module
// set it if unless it is wrong
if ($uptime > 0) {
if ($uptime < $device->uptime) {
Eventlog::log('Device rebooted after ' . Time::formatInterval($device->uptime) . " -> {$uptime}s", $device, 'reboot', 4, $device->uptime);
Eventlog::log('Device rebooted after ' . Time::formatInterval($device->uptime) . " -> {$uptime}s", $device, 'reboot', Severity::Warning, $device->uptime);
if (Config::get('discovery_on_reboot')) {
$device->last_discovered = null;
$device->save();

View File

@ -27,7 +27,7 @@ use App\Observers\ModuleModelObserver;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use LibreNMS\DB\SyncsModels;
use LibreNMS\Enum\Alert;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\Module;
use LibreNMS\OS;
use LibreNMS\RRD\RrdDefinition;
@ -98,7 +98,7 @@ class PrinterSupplies implements Module
'Toner ' . $toner['supply_descr'] . ' is empty',
$os->getDevice(),
'toner',
Alert::ERROR,
Severity::Error,
$toner['supply_id']
);
}
@ -109,7 +109,7 @@ class PrinterSupplies implements Module
'Toner ' . $toner['supply_descr'] . ' was replaced (new level: ' . $tonerperc . '%)',
$os->getDevice(),
'toner',
Alert::NOTICE,
Severity::Notice,
$toner['supply_id']
);
}

View File

@ -28,6 +28,7 @@ namespace LibreNMS\OS;
use App\Models\Eventlog;
use App\Models\TnmsneInfo;
use App\Observers\ModuleModelObserver;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\Polling\OSPolling;
class Coriant extends \LibreNMS\OS implements OSPolling
@ -58,7 +59,7 @@ class Coriant extends \LibreNMS\OS implements OSPolling
if ($ne->isDirty()) {
$ne->save();
Eventlog::log("Coriant enmsNETable Hardware $ne->neType : $ne->neName ($index) at $ne->neLocation Discovered", $this->getDevice(), 'system', 2);
Eventlog::log("Coriant enmsNETable Hardware $ne->neType : $ne->neName ($index) at $ne->neLocation Discovered", $this->getDevice(), 'system');
}
$c_list[] = $index;
}
@ -66,7 +67,7 @@ class Coriant extends \LibreNMS\OS implements OSPolling
foreach (TnmsneInfo::where('device_id', $this->getDeviceId())->whereNotIn('neID', $c_list)->get() as $ne) {
/** @var TnmsneInfo $ne */
$ne->delete();
Eventlog::log("Coriant enmsNETable Hardware $ne->neName at $ne->neLocation Removed", $this->getDevice(), 'system', $ne->neID);
Eventlog::log("Coriant enmsNETable Hardware $ne->neName at $ne->neLocation Removed", $this->getDevice(), 'system', Severity::Info, $ne->neID);
}
}
}

View File

@ -34,7 +34,7 @@ use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use LibreNMS\Enum\Alert;
use LibreNMS\Enum\Severity;
use LibreNMS\Exceptions\PollerException;
use LibreNMS\Polling\ConnectivityHelper;
use LibreNMS\RRD\RrdDefinition;
@ -146,7 +146,7 @@ class Poller
// check if the poll took too long and log an event
if ($measurement->getDuration() > Config::get('rrd.step')) {
\App\Models\Eventlog::log('Polling took longer than ' . round(Config::get('rrd.step') / 60, 2) .
' minutes! This will cause gaps in graphs.', $this->device, 'system', 5);
' minutes! This will cause gaps in graphs.', $this->device, 'system', Severity::Error);
}
}
@ -188,7 +188,7 @@ class Poller
} catch (Throwable $e) {
// isolate module exceptions so they don't disrupt the polling process
$this->logger->error("%rError polling $module module for {$this->device->hostname}.%n $e", ['color' => true]);
\App\Models\Eventlog::log("Error polling $module module. Check log file for more details.", $this->device, 'poller', Alert::ERROR);
\App\Models\Eventlog::log("Error polling $module module. Check log file for more details.", $this->device, 'poller', Severity::Error);
report($e);
}

View File

@ -31,6 +31,7 @@ use App\Models\Eventlog;
use LibreNMS\Config;
use LibreNMS\Data\Source\Fping;
use LibreNMS\Data\Source\FpingResponse;
use LibreNMS\Enum\Severity;
use LibreNMS\RRD\RrdDefinition;
use SnmpQuery;
use Symfony\Component\Process\Process;
@ -124,7 +125,7 @@ class ConnectivityHelper
);
if ($status->duplicates > 0) {
Eventlog::log('Duplicate ICMP response detected! This could indicate a network issue.', $this->device, 'icmp', 4);
Eventlog::log('Duplicate ICMP response detected! This could indicate a network issue.', $this->device, 'icmp', Severity::Warning);
$status->exit_code = 0; // when duplicate is detected fping returns 1. The device is up, but there is another issue. Clue admins in with above event.
}

View File

@ -29,6 +29,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -45,23 +46,13 @@ class AdvaNetworkElementAlmTrap implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$alSeverity = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmNetworkElementAlmNotifCode'));
switch ($alSeverity) {
case 'critical':
$logSeverity = 5;
break;
case 'major':
$logSeverity = 4;
break;
case 'minor':
$logSeverity = 3;
break;
case 'cleared':
$logSeverity = 1;
break;
default:
$logSeverity = 2;
break;
}
$logSeverity = match ($alSeverity) {
'critical' => Severity::Error,
'major' => Severity::Warning,
'minor' => Severity::Notice,
'cleared' => Severity::Ok,
default => Severity::Info,
};
$almDescr = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmNetworkElementAlmDescr'));
$almObjName = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmNetworkElementAlmObjectName'));

View File

@ -29,6 +29,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class AdvaSnmpDyingGaspTrap implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('Dying Gasp received', 5);
$trap->log('Dying Gasp received', Severity::Error);
}
}

View File

@ -29,6 +29,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -45,23 +46,13 @@ class AdvaSysAlmTrap implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$alSeverity = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmSysAlmNotifCode'));
switch ($alSeverity) {
case 'critical':
$logSeverity = 5;
break;
case 'major':
$logSeverity = 4;
break;
case 'minor':
$logSeverity = 3;
break;
case 'cleared':
$logSeverity = 1;
break;
default:
$logSeverity = 2;
break;
}
$logSeverity = match ($alSeverity) {
'critical' => Severity::Error,
'major' => Severity::Warning,
'minor' => Severity::Notice,
'cleared' => Severity::Ok,
default => Severity::Info,
};
$sysAlmDescr = $trap->getOidData($trap->findOid('CM-ALARM-MIB::cmSysAlmDescr'));
$trap->log("System Alarm: $sysAlmDescr Status: $alSeverity", $logSeverity);

View File

@ -31,6 +31,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -50,6 +51,6 @@ class Aos6LbdStateChangeForAutoRecovery implements SnmptrapHandler
$current = $trap->getOidData($trap->findOid('ALCATEL-IND1-LBD-MIB::alaLbdCurrentStateAutoRecovery'));
$ifIndex = $trap->getOidData($trap->findOid('ALCATEL-IND1-LBD-MIB::alaLbdPortIfIndex'));
$port = $device->ports()->where('ifIndex', $ifIndex)->first();
$trap->log("Loopback detection has been recovered on the port $port->ifDescr. Status of the port before was $before and now is $current.", 1);
$trap->log("Loopback detection has been recovered on the port $port->ifDescr. Status of the port before was $before and now is $current.", Severity::Ok);
}
}

View File

@ -31,6 +31,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -51,6 +52,6 @@ class Aos6LbdStateChangeToShutdown implements SnmptrapHandler
$ifDescr = $trap->getOidData($trap->findOid('IF-MIB::ifDescr'));
$ifIndex = $trap->getOidData($trap->findOid('ALCATEL-IND1-LBD-MIB::alaLbdPortIfIndex'));
$port = $device->ports()->where('ifIndex', $ifIndex)->first();
$trap->log("There has been a loop detected on the port $port->ifDescr. Status of the port before was $before and now is $current.", 5);
$trap->log("There has been a loop detected on the port $port->ifDescr. Status of the port before was $before and now is $current.", Severity::Error);
}
}

View File

@ -31,6 +31,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -47,6 +48,6 @@ class Aos6StackMgrDuplicateSlot implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$slot_nr = $trap->getOidData($trap->findOid('ALCATEL-IND1-STACK-MANAGER-MIB::alaStackMgrSlotNINumber'));
$trap->log("Stack member $slot_nr is duplicated.", 5);
$trap->log("Stack member $slot_nr is duplicated.", Severity::Error);
}
}

View File

@ -31,6 +31,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -51,6 +52,6 @@ class Aos7portViolation implements SnmptrapHandler
$ifDescr = $trap->getOidData($trap->findOid('IF-MIB::ifDescr'));
$ifIndex = $trap->getOidData($trap->findOid('IF-MIB::ifIndex'));
$port = $device->ports()->where('ifIndex', $ifIndex)->first();
$trap->log("There has been a loop detected on the port $port->ifDescr. The source code of the violation is: $reason and the current status code is: $current.", 5);
$trap->log("There has been a loop detected on the port $port->ifDescr. The source code of the violation is: $reason and the current status code is: $current.", Severity::Error);
}
}

View File

@ -31,6 +31,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -50,6 +51,6 @@ class Aos7portViolationNotification implements SnmptrapHandler
$ifDescr = $trap->getOidData($trap->findOid('IF-MIB::ifDescr'));
$ifIndex = $trap->getOidData($trap->findOid('IF-MIB::ifIndex'));
$port = $device->ports()->where('ifIndex', $ifIndex)->first();
$trap->log("There has been a loop detected on the port $port->ifDescr. The current status code is: $reason.", 5);
$trap->log("There has been a loop detected on the port $port->ifDescr. The current status code is: $reason.", Severity::Error);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -41,6 +42,6 @@ class Aos7stpNewRoot implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: Device ' . $device->displayName() . ' was elected as new root on one of its Spanning Tree Instances', 3, 'stp');
$trap->log('SNMP Trap: Device ' . $device->displayName() . ' was elected as new root on one of its Spanning Tree Instances', Severity::Notice, 'stp');
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -41,6 +42,6 @@ class Aos7stpRootPortChange implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: A root port has changed for a spanning tree bridge. The root port is the port that offers the lowest cost path from this bridge to the root bridge.', 3, 'stp');
$trap->log('SNMP Trap: A root port has changed for a spanning tree bridge. The root port is the port that offers the lowest cost path from this bridge to the root bridge.', Severity::Notice, 'stp');
}
}

View File

@ -27,6 +27,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -43,6 +44,6 @@ class ApcOnBattery implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$message = $trap->getOidData($trap->findOid('PowerNet-MIB::mtrapargsString'));
$trap->log($message, 4);
$trap->log($message, Severity::Warning);
}
}

View File

@ -31,6 +31,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -50,6 +51,6 @@ class ApcPduNearOverload implements SnmptrapHandler
$pdu_id = ApcTrapUtil::getPduIdentName($trap);
$phase_num = ApcTrapUtil::getPduPhaseNum($trap);
$alarm_str = ApcTrapUtil::getApcTrapString($trap);
$trap->log("$pdu_id phase $phase_num $alarm_str", 4);
$trap->log("$pdu_id phase $phase_num $alarm_str", Severity::Warning);
}
}

View File

@ -31,6 +31,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -50,6 +51,6 @@ class ApcPduNearOverloadCleared implements SnmptrapHandler
$pdu_id = ApcTrapUtil::getPduIdentName($trap);
$phase_num = ApcTrapUtil::getPduPhaseNum($trap);
$alarm_str = ApcTrapUtil::getApcTrapString($trap);
$trap->log("$pdu_id phase $phase_num $alarm_str", 1);
$trap->log("$pdu_id phase $phase_num $alarm_str", Severity::Ok);
}
}

View File

@ -23,6 +23,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -39,6 +40,6 @@ class ApcPduOutletOff implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$outlet = $trap->getOidData($trap->findOid('PowerNet-MIB::mtrapargsInteger.0'));
$trap->log("APC PDU: Outlet has turned off: $outlet", 4);
$trap->log("APC PDU: Outlet has turned off: $outlet", Severity::Warning);
}
}

View File

@ -23,6 +23,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -39,6 +40,6 @@ class ApcPduOutletOn implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$outlet = $trap->getOidData($trap->findOid('PowerNet-MIB::mtrapargsInteger.0'));
$trap->log("APC PDU: Outlet has been turned on: $outlet", 4);
$trap->log("APC PDU: Outlet has been turned on: $outlet", Severity::Warning);
}
}

View File

@ -23,6 +23,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -39,6 +40,6 @@ class ApcPduOutletReboot implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$outlet = $trap->getOidData($trap->findOid('PowerNet-MIB::mtrapargsInteger.0'));
$trap->log("APC PDU: Outlet has rebooted: $outlet", 4);
$trap->log("APC PDU: Outlet has rebooted: $outlet", Severity::Warning);
}
}

View File

@ -31,6 +31,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -50,6 +51,6 @@ class ApcPduOverload implements SnmptrapHandler
$pdu_id = ApcTrapUtil::getPduIdentName($trap);
$phase_num = ApcTrapUtil::getPduPhaseNum($trap);
$alarm_str = ApcTrapUtil::getApcTrapString($trap);
$trap->log("$pdu_id phase $phase_num $alarm_str", 5);
$trap->log("$pdu_id phase $phase_num $alarm_str", Severity::Error);
}
}

View File

@ -31,6 +31,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -50,6 +51,6 @@ class ApcPduOverloadCleared implements SnmptrapHandler
$pdu_id = ApcTrapUtil::getPduIdentName($trap);
$phase_num = ApcTrapUtil::getPduPhaseNum($trap);
$alarm_str = ApcTrapUtil::getApcTrapString($trap);
$trap->log("$pdu_id phase $phase_num $alarm_str", 1);
$trap->log("$pdu_id phase $phase_num $alarm_str", Severity::Ok);
}
}

View File

@ -27,6 +27,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -43,6 +44,6 @@ class ApcPowerRestored implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$message = $trap->getOidData($trap->findOid('PowerNet-MIB::mtrapargsString'));
$trap->log($message, 1);
$trap->log($message, Severity::Ok);
}
}

View File

@ -27,6 +27,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -43,6 +44,6 @@ class ApcSmartAvrReducing implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$message = $trap->getOidData($trap->findOid('PowerNet-MIB::mtrapargsString'));
$trap->log($message, 3);
$trap->log($message, Severity::Notice);
}
}

View File

@ -27,6 +27,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -43,6 +44,6 @@ class ApcSmartAvrReducingOff implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$message = $trap->getOidData($trap->findOid('PowerNet-MIB::mtrapargsString'));
$trap->log($message, 1);
$trap->log($message, Severity::Ok);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -41,6 +42,6 @@ class AuthenticationFailure implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: Authentication Failure: ' . $device->displayName(), 3, 'auth');
$trap->log('SNMP Trap: Authentication Failure: ' . $device->displayName(), Severity::Notice, 'auth');
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -56,7 +57,8 @@ class BgpBackwardTransition implements SnmptrapHandler
$bgpPeer->bgpPeerState = $trap->getOidData($state_oid);
if ($bgpPeer->isDirty('bgpPeerState')) {
$trap->log('SNMP Trap: BGP Down ' . $bgpPeer->bgpPeerIdentifier . ' ' . get_astext($bgpPeer->bgpPeerRemoteAs) . ' is now ' . $bgpPeer->bgpPeerState, 5, 'bgpPeer', $bgpPeerIp);
$trap->log('SNMP Trap: BGP Down ' . $bgpPeer->bgpPeerIdentifier . ' ' . get_astext($bgpPeer->bgpPeerRemoteAs) . ' is now ' . $bgpPeer->bgpPeerState, severity: Severity::Error, type: 'bgpPeer',
reference: $bgpPeerIp);
}
$bgpPeer->save();

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -56,7 +57,7 @@ class BgpEstablished implements SnmptrapHandler
$bgpPeer->bgpPeerState = $trap->getOidData($state_oid);
if ($bgpPeer->isDirty('bgpPeerState')) {
$trap->log('SNMP Trap: BGP Up ' . $bgpPeer->bgpPeerIdentifier . ' ' . get_astext($bgpPeer->bgpPeerRemoteAs) . ' is now ' . $bgpPeer->bgpPeerState, 1, 'bgpPeer', $bgpPeerIp);
$trap->log('SNMP Trap: BGP Up ' . $bgpPeer->bgpPeerIdentifier . ' ' . get_astext($bgpPeer->bgpPeerRemoteAs) . ' is now ' . $bgpPeer->bgpPeerState, Severity::Ok, 'bgpPeer', $bgpPeerIp);
}
$bgpPeer->save();

View File

@ -23,6 +23,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -38,6 +39,6 @@ class BridgeNewRoot implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: Device ' . $device->displayName() . ' was elected as new root on one of its Spanning Tree Instances', 3, 'stp');
$trap->log('SNMP Trap: Device ' . $device->displayName() . ' was elected as new root on one of its Spanning Tree Instances', Severity::Notice, 'stp');
}
}

View File

@ -23,6 +23,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -38,6 +39,6 @@ class BridgeTopologyChanged implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: Topology of Spanning Tree Instance on device ' . $device->displayName() . ' was changed', 3, 'stp');
$trap->log('SNMP Trap: Topology of Spanning Tree Instance on device ' . $device->displayName() . ' was changed', Severity::Notice, 'stp');
}
}

View File

@ -29,6 +29,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -48,6 +49,6 @@ class CiscoDHCPServerFreeAddressHigh implements SnmptrapHandler
$oid = $trap->findOid($oid_prefix);
$pool = str_replace($oid_prefix, '', $oid);
$value = $trap->getOidData($oid);
$trap->log("SNMP Trap: DHCP pool $pool address space high. Free addresses: '$value' addresses.", 2);
$trap->log("SNMP Trap: DHCP pool $pool address space high. Free addresses: '$value' addresses.", Severity::Info);
}
}

View File

@ -29,6 +29,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -48,6 +49,6 @@ class CiscoDHCPServerFreeAddressLow implements SnmptrapHandler
$oid = $trap->findOid($oid_prefix);
$pool = str_replace($oid_prefix, '', $oid);
$value = $trap->getOidData($oid);
$trap->log("SNMP Trap: DHCP pool $pool address space low. Free addresses: '$value' addresses.", 5);
$trap->log("SNMP Trap: DHCP pool $pool address space low. Free addresses: '$value' addresses.", Severity::Error);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -41,6 +42,6 @@ class CiscoDHCPServerStart implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: Device DHCP service started.', 2);
$trap->log('SNMP Trap: Device DHCP service started.', Severity::Info);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -41,6 +42,6 @@ class CiscoDHCPServerStop implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: Device DHCP service stopped.', 5);
$trap->log('SNMP Trap: Device DHCP service stopped.', Severity::Error);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -47,10 +48,10 @@ class CiscoErrDisableInterfaceEvent implements SnmptrapHandler
$cause = $trap->getOidData($trap->findOid('CISCO-ERR-DISABLE-MIB::cErrDisableIfStatusCause.' . $ifIndex[1] . '.0'));
if (! $port) {
$trap->log('SNMP TRAP: ' . $cause . ' error detected on unknown port. Either ifIndex is not found in the trap, or it does not match a port on this device.', 4);
$trap->log('SNMP TRAP: ' . $cause . ' error detected on unknown port. Either ifIndex is not found in the trap, or it does not match a port on this device.', Severity::Warning);
return;
}
$trap->log('SNMP TRAP: ' . $cause . ' error detected on ' . $port->ifName . ' (Description: ' . $port->ifDescr . '). ' . $port->ifName . ' in err-disable state.', 4);
$trap->log('SNMP TRAP: ' . $cause . ' error detected on ' . $port->ifName . ' (Description: ' . $port->ifDescr . '). ' . $port->ifName . ' in err-disable state.', Severity::Warning);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CiscoMacViolation implements SnmptrapHandler
$ifName = $trap->getOidData($trap->findOid('IF-MIB::ifName'));
$mac = $trap->getOidData($trap->findOid('CISCO-PORT-SECURITY-MIB::cpsIfSecureLastMacAddress'));
$trap->log("SNMP Trap: Secure MAC Address Violation on port $ifName. Last MAC address: $mac", 4);
$trap->log("SNMP Trap: Secure MAC Address Violation on port $ifName. Last MAC address: $mac", Severity::Warning);
}
}

View File

@ -23,6 +23,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -38,6 +39,6 @@ class ColdBoot implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: Device ' . $device->displayName() . ' cold booted', 4, 'reboot');
$trap->log('SNMP Trap: Device ' . $device->displayName() . ' cold booted', Severity::Warning, 'reboot');
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpLowBattery implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$battery = CyberPowerUtil::getMessage($trap);
$trap->log("$battery", 4);
$trap->log("$battery", Severity::Warning);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpPowerRestored implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$power = CyberPowerUtil::getMessage($trap);
$trap->log("$power", 1);
$trap->log("$power", Severity::Ok);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpRtnDischarge implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$returnInfo = CyberPowerUtil::getMessage($trap);
$trap->log("$returnInfo", 1);
$trap->log("$returnInfo", Severity::Ok);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpRtnLowBattery implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$battery = CyberPowerUtil::getMessage($trap);
$trap->log("$battery", 1);
$trap->log("$battery", Severity::Ok);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsChargerFailure implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$chargeInfo = CyberPowerUtil::getMessage($trap);
$trap->log("$chargeInfo", 4);
$trap->log("$chargeInfo", Severity::Warning);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsDiagFailed implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$diagInfo = CyberPowerUtil::getMessage($trap);
$trap->log("$diagInfo", 5);
$trap->log("$diagInfo", Severity::Error);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsOnBattery implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$battery = CyberPowerUtil::getMessage($trap);
$trap->log("$battery", 4);
$trap->log("$battery", Severity::Warning);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsOverTemp implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$temp = CyberPowerUtil::getMessage($trap);
$trap->log("$temp", 5);
$trap->log("$temp", Severity::Error);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsOverload implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$overload = CyberPowerUtil::getMessage($trap);
$trap->log("$overload", 5);
$trap->log("$overload", Severity::Error);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsRebootStarted implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$status = CyberPowerUtil::getMessage($trap);
$trap->log("$status", 4);
$trap->log("$status", Severity::Warning);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsRtnChargerFailure implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$chargeInfo = CyberPowerUtil::getMessage($trap);
$trap->log("$chargeInfo", 1);
$trap->log("$chargeInfo", Severity::Ok);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsRtnOverTemp implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$temp = CyberPowerUtil::getMessage($trap);
$trap->log("$temp", 1);
$trap->log("$temp", Severity::Ok);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsRtnOverload implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$overload = CyberPowerUtil::getMessage($trap);
$trap->log("$overload", 1);
$trap->log("$overload", Severity::Ok);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsSleeping implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$status = CyberPowerUtil::getMessage($trap);
$trap->log("$status", 4);
$trap->log("$status", Severity::Warning);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsTurnedOff implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$status = CyberPowerUtil::getMessage($trap);
$trap->log("$status", 4);
$trap->log("$status", Severity::Warning);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class CpUpsWokeUp implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$status = CyberPowerUtil::getMessage($trap);
$trap->log("$status", 1);
$trap->log("$status", Severity::Ok);
}
}

View File

@ -23,6 +23,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -38,6 +39,6 @@ class EntityDatabaseConfigChanged implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: Configuration of Entity Database on device ' . $device->displayName() . ' was changed', 3, 'system');
$trap->log('SNMP Trap: Configuration of Entity Database on device ' . $device->displayName() . ' was changed', Severity::Notice, 'system');
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -47,14 +48,14 @@ class EquipStatusTrap implements SnmptrapHandler
$trap->log('SNMP Trap: Equipment Status ' . $state, $severity, 'state');
}
private function getSeverity(string $state): int
private function getSeverity(string $state): Severity
{
return match ($state) {
'warning', '3', 'major', '5' => 4,
'critical', '4' => 5,
'minor', '2' => 3,
'nonAlarmed', '1' => 1,
default => 0,
'warning', '3', 'major', '5' => Severity::Warning,
'critical', '4' => Severity::Error,
'minor', '2' => Severity::Notice,
'nonAlarmed', '1' => Severity::Ok,
default => Severity::Unknown,
};
}
}

View File

@ -23,6 +23,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -38,6 +39,6 @@ class FailedUserLogin implements SnmptrapHandler
*/
public function handle(Device $device, Trap $trap)
{
$trap->log('SNMP Trap: Failed User Login: ' . $device->displayName(), 4, 'auth');
$trap->log('SNMP Trap: Failed User Login: ' . $device->displayName(), Severity::Warning, 'auth');
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -45,6 +46,6 @@ class FgTrapIpsAnomaly implements SnmptrapHandler
{
$srcIp = $trap->getOidData($trap->findOid('FORTINET-FORTIGATE-MIB::fgIpsTrapSrcIp'));
$proto = $trap->getOidData($trap->findOid('FORTINET-FORTIGATE-MIB::fgIpsTrapSigMsg'));
$trap->log("DDoS prevention triggered. Source: $srcIp Protocol: $proto", 4);
$trap->log("DDoS prevention triggered. Source: $srcIp Protocol: $proto", Severity::Warning);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -46,6 +47,6 @@ class FgTrapIpsSignature implements SnmptrapHandler
$srcIp = $trap->getOidData($trap->findOid('FORTINET-FORTIGATE-MIB::fgIpsTrapSrcIp'));
$sigNum = $trap->getOidData($trap->findOid('FORTINET-FORTIGATE-MIB::fgIpsTrapSigId'));
$sigName = $trap->getOidData($trap->findOid('FORTINET-FORTIGATE-MIB::fgIpsTrapSigMsg'));
$trap->log("IPS signature $sigName detected from $srcIp with Fortiguard ID $sigNum", 4);
$trap->log("IPS signature $sigName detected from $srcIp with Fortiguard ID $sigNum", Severity::Warning);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -45,6 +46,6 @@ class FgTrapVpnTunDown implements SnmptrapHandler
{
$remoteGw = $trap->getOidData($trap->findOid('FORTIGATE-MIB::fgVpnTrapRemoteGateway'));
$tunName = $trap->getOidData($trap->findOid('FORTIGATE-MIB::fgVpnTrapPhase1Name'));
$trap->log("VPN tunnel $tunName to $remoteGw is down", 3);
$trap->log("VPN tunnel $tunName to $remoteGw is down", Severity::Notice);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -45,6 +46,6 @@ class FgTrapVpnTunUp implements SnmptrapHandler
{
$remoteGw = $trap->getOidData($trap->findOid('FORTIGATE-MIB::fgVpnTrapRemoteGateway'));
$tunName = $trap->getOidData($trap->findOid('FORTIGATE-MIB::fgVpnTrapPhase1Name'));
$trap->log("VPN tunnel $tunName to $remoteGw is up", 1);
$trap->log("VPN tunnel $tunName to $remoteGw is up", Severity::Ok);
}
}

View File

@ -29,6 +29,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -46,6 +47,6 @@ class FmTrapLogRateThreshold implements SnmptrapHandler
{
$logRate = $trap->getOidData($trap->findOid('FORTINET-FORTIMANAGER-FORTIANALYZER-MIB::fmLogRate'));
$logThresh = $trap->getOidData($trap->findOid('FORTINET-FORTIMANAGER-FORTIANALYZER-MIB::fmLogRateThreshold'));
$trap->log("Recommended log rate exceeded. Current Rate: $logRate Recommended Rate: $logThresh", 3);
$trap->log("Recommended log rate exceeded. Current Rate: $logRate Recommended Rate: $logThresh", Severity::Notice);
}
}

View File

@ -3,6 +3,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -21,16 +22,16 @@ class HpFault implements SnmptrapHandler
$type = $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfLogFaultType'));
switch ($type) {
case 'badXcvr':
$trap->log('Fault - CRC Error ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), 4, $type);
$trap->log('Fault - CRC Error ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), Severity::Warning, $type);
break;
case 'badCable':
$trap->log('Fault - Bad Cable ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), 4, $type);
$trap->log('Fault - Bad Cable ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), Severity::Warning, $type);
break;
case 'bcastStorm':
$trap->log('Fault - Broadcaststorm ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), 5, $type);
$trap->log('Fault - Broadcaststorm ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), Severity::Error, $type);
break;
default:
$trap->log('Fault - Unhandled ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), 2, $type);
$trap->log('Fault - Unhandled ' . $trap->getOidData($trap->findOid('HP-ICF-FAULT-FINDER-MIB::hpicfFfFaultInfoURL')), Severity::Info, $type);
break;
}
}

View File

@ -30,6 +30,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Util\IP;
@ -61,7 +62,7 @@ class JnxBgpM2BackwardTransition implements SnmptrapHandler
$bgpPeer->bgpPeerState = $peerState;
if ($bgpPeer->isDirty('bgpPeerState')) {
$trap->log("BGP Peer $peerAddr is now in the $peerState state", 5);
$trap->log("BGP Peer $peerAddr is now in the $peerState state", Severity::Error);
}
$bgpPeer->save();

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use LibreNMS\Util\IP;
@ -57,7 +58,7 @@ class JnxBgpM2Established implements SnmptrapHandler
$bgpPeer->bgpPeerState = $peerState;
if ($bgpPeer->isDirty('bgpPeerState')) {
$trap->log("BGP Peer $peerAddr is now in the $peerState state", 1);
$trap->log("BGP Peer $peerAddr is now in the $peerState state", Severity::Ok);
}
$bgpPeer->save();

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class JnxDomAlarmCleared implements SnmptrapHandler
$currentAlarm = $trap->getOidData($trap->findOid('JUNIPER-DOM-MIB::jnxDomCurrentAlarms'));
$ifDescr = $trap->getOidData($trap->findOid('IF-MIB::ifDescr'));
$alarmList = JnxDomAlarmId::getAlarms($currentAlarm);
$trap->log("DOM alarm cleared for interface $ifDescr. Cleared alarm(s): $alarmList", 1);
$trap->log("DOM alarm cleared for interface $ifDescr. Cleared alarm(s): $alarmList", Severity::Ok);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class JnxDomAlarmSet implements SnmptrapHandler
$currentAlarm = $trap->getOidData($trap->findOid('JUNIPER-DOM-MIB::jnxDomCurrentAlarms'));
$ifDescr = $trap->getOidData($trap->findOid('IF-MIB::ifDescr'));
$alarmList = JnxDomAlarmId::getAlarms($currentAlarm);
$trap->log("DOM alarm set for interface $ifDescr. Current alarm(s): $alarmList", 5);
$trap->log("DOM alarm set for interface $ifDescr. Current alarm(s): $alarmList", Severity::Error);
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -56,6 +57,6 @@ class JnxDomLaneAlarmCleared implements SnmptrapHandler
return;
}
$trap->log("DOM lane alarm cleared on interface $port->ifDescr lane $lane. Current alarm(s): $alarmList", 1);
$trap->log("DOM lane alarm cleared on interface $port->ifDescr lane $lane. Current alarm(s): $alarmList", Severity::Ok);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -54,6 +55,6 @@ class JnxDomLaneAlarmSet implements SnmptrapHandler
return;
}
$trap->log("DOM lane alarm on interface $port->ifDescr lane $lane. Current alarm(s): $alarmList", 5);
$trap->log("DOM lane alarm on interface $port->ifDescr lane $lane. Current alarm(s): $alarmList", Severity::Error);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -46,6 +47,6 @@ class JnxLdpLspDown implements SnmptrapHandler
$reason = $trap->getOidData($trap->findOid('JUNIPER-LDP-MIB::jnxLdpLspDownReason'));
$instanceName = $trap->getOidData($trap->findOid('JUNIPER-LDP-MIB::jnxLdpInstanceName'));
$trap->log("LDP session $instanceName from $routerID to $lspForward has gone down due to $reason", 4);
$trap->log("LDP session $instanceName from $routerID to $lspForward has gone down due to $reason", Severity::Warning);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -45,6 +46,6 @@ class JnxLdpLspUp implements SnmptrapHandler
$routerID = $trap->getOidData($trap->findOid('JUNIPER-LDP-MIB::jnxLdpRtrid'));
$instanceName = $trap->getOidData($trap->findOid('JUNIPER-LDP-MIB::jnxLdpInstanceName'));
$trap->log("LDP session $instanceName from $routerID to $lspForward is now up.", 1);
$trap->log("LDP session $instanceName from $routerID to $lspForward is now up.", Severity::Ok);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -53,6 +54,6 @@ class JnxLdpSesDown implements SnmptrapHandler
return;
}
$trap->log("LDP session on interface $port->ifDescr is $state due to $reason", 4);
$trap->log("LDP session on interface $port->ifDescr is $state due to $reason", Severity::Warning);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -52,6 +53,6 @@ class JnxLdpSesUp implements SnmptrapHandler
return;
}
$trap->log("LDP session on interface $port->ifDescr is $state", 1);
$trap->log("LDP session on interface $port->ifDescr is $state", Severity::Ok);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -43,6 +44,6 @@ class JnxPowerSupplyFailure implements SnmptrapHandler
{
$powerSupply = $trap->getOidData($trap->findOid('JUNIPER-MIB::jnxContentsDescr'));
$state = $trap->getOidData($trap->findOid('JUNIPER-MIB::jnxOperatingState'));
$trap->log("Power Supply $powerSupply is $state", 5);
$trap->log("Power Supply $powerSupply is $state", Severity::Error);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -42,6 +43,6 @@ class JnxPowerSupplyOk implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$powerSupply = $trap->getOidData($trap->findOid('JUNIPER-MIB::jnxContentsDescr'));
$trap->log("Power Supply $powerSupply is OK", 1);
$trap->log("Power Supply $powerSupply is OK", Severity::Ok);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class JnxVpnIfDown implements SnmptrapHandler
$vpnType = $trap->getOidData($trap->findOid('JUNIPER-VPN-MIB::jnxVpnIfVpnType'));
$vpnName = $trap->getOidData($trap->findOid('JUNIPER-VPN-MIB::jnxVpnIfVpnName'));
$trap->log("$vpnType on interface $vpnName has gone down", 4);
$trap->log("$vpnType on interface $vpnName has gone down", Severity::Warning);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -46,9 +47,9 @@ class JnxVpnIfUp implements SnmptrapHandler
if (substr($vpnName, 0, 6) === 'vt/lsi') {
$vpnDevice = substr($vpnName, 7, 15);
$trap->log("$vpnType to device $vpnDevice is now connected", 1);
$trap->log("$vpnType to device $vpnDevice is now connected", Severity::Ok);
} else {
$trap->log("$vpnType on interface $vpnName is now connected", 1);
$trap->log("$vpnType on interface $vpnName is now connected", Severity::Ok);
}
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class JnxVpnPwDown implements SnmptrapHandler
$vpnType = $trap->getOidData($trap->findOid('JUNIPER-VPN-MIB::jnxVpnPwVpnType'));
$vpnName = $trap->getOidData($trap->findOid('JUNIPER-VPN-MIB::jnxVpnPwVpnName'));
$trap->log("$vpnType on a pseudowire belonging to $vpnName has gone down", 4);
$trap->log("$vpnType on a pseudowire belonging to $vpnName has gone down", Severity::Warning);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -44,6 +45,6 @@ class JnxVpnPwUp implements SnmptrapHandler
$vpnType = $trap->getOidData($trap->findOid('JUNIPER-VPN-MIB::jnxVpnPwVpnType'));
$vpnName = $trap->getOidData($trap->findOid('JUNIPER-VPN-MIB::jnxVpnPwVpnName'));
$trap->log("$vpnType on a pseudowire belonging to $vpnName is now connected", 1);
$trap->log("$vpnType on a pseudowire belonging to $vpnName is now connected", Severity::Ok);
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -58,14 +59,14 @@ class LinkDown implements SnmptrapHandler
if ($trapAdminStatus) {
$port->ifAdminStatus = $trapAdminStatus;
}
$trap->log("SNMP Trap: linkDown $port->ifAdminStatus/$port->ifOperStatus " . $port->ifDescr, 5, 'interface', $port->port_id);
$trap->log("SNMP Trap: linkDown $port->ifAdminStatus/$port->ifOperStatus " . $port->ifDescr, Severity::Error, 'interface', $port->port_id);
if ($port->isDirty('ifAdminStatus')) {
$trap->log("Interface Disabled : $port->ifDescr (TRAP)", 3, 'interface', $port->port_id);
$trap->log("Interface Disabled : $port->ifDescr (TRAP)", Severity::Notice, 'interface', $port->port_id);
}
if ($port->isDirty('ifOperStatus')) {
$trap->log("Interface went Down : $port->ifDescr (TRAP)", 5, 'interface', $port->port_id);
$trap->log("Interface went Down : $port->ifDescr (TRAP)", Severity::Error, 'interface', $port->port_id);
}
$port->save();

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -55,14 +56,14 @@ class LinkUp implements SnmptrapHandler
$port->ifOperStatus = $trap->getOidData("IF-MIB::ifOperStatus.$ifIndex") ?: 'up';
$port->ifAdminStatus = $trap->getOidData("IF-MIB::ifAdminStatus.$ifIndex") ?: 'up'; // If we receive LinkUp trap, we can safely assume that the ifAdminStatus is also up.
$trap->log("SNMP Trap: linkUp $port->ifAdminStatus/$port->ifOperStatus " . $port->ifDescr, 1, 'interface', $port->port_id);
$trap->log("SNMP Trap: linkUp $port->ifAdminStatus/$port->ifOperStatus " . $port->ifDescr, Severity::Ok, 'interface', $port->port_id);
if ($port->isDirty('ifAdminStatus')) {
$trap->log("Interface Enabled : $port->ifDescr (TRAP)", 3, 'interface', $port->port_id);
$trap->log("Interface Enabled : $port->ifDescr (TRAP)", Severity::Notice, 'interface', $port->port_id);
}
if ($port->isDirty('ifOperStatus')) {
$trap->log("Interface went Up : $port->ifDescr (TRAP)", 1, 'interface', $port->port_id);
$trap->log("Interface went Up : $port->ifDescr (TRAP)", Severity::Ok, 'interface', $port->port_id);
}
$port->save();

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -54,14 +55,14 @@ class LogTrap implements SnmptrapHandler
$trap->log('SNMP Trap: Log ' . $logName . ' ' . $logEvent . ' ' . $logPC . ' ' . $logAI . ' ' . $state, $severity, 'log');
}
private function getSeverity(string $state): int
private function getSeverity(string $state): Severity
{
return match ($state) {
'warning', '3', 'major', '5' => 4,
'critical', '4' => 5,
'minor', '2' => 3,
'nonAlarmed', '1' => 1,
default => 0,
'warning', '3', 'major', '5' => Severity::Warning,
'critical', '4' => Severity::Error,
'minor', '2' => Severity::Notice,
'nonAlarmed', '1' => Severity::Ok,
default => Severity::Unknown,
};
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -69,29 +70,13 @@ class Mgnt2TrapNmsAlarm implements SnmptrapHandler
$msg = "Alarm on slot $slot, $sourcePm Issue: $probSpecific Possible Cause: $probCause";
}
switch ($alarmSeverity) {
case 'cleared':
$severity = 1;
break;
case 'critical':
$severity = 5;
break;
case 'major':
$severity = 5;
break;
case 'minor':
$severity = 4;
break;
case 'warning':
$severity = 4;
break;
case 'indeterminate':
$severity = 0;
break;
default:
$severity = 2;
break;
}
$severity = match ($alarmSeverity) {
'cleared' => Severity::Ok,
'critical', 'major' => Severity::Error,
'minor', 'warning' => Severity::Warning,
'indeterminate' => Severity::Unknown,
default => Severity::Info,
};
$trap->log($msg, $severity);
}

View File

@ -29,6 +29,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -58,32 +59,12 @@ class OspfIfStateChange implements SnmptrapHandler
$ospfPort->ospfIfState = $trap->getOidData($trap->findOid('OSPF-MIB::ospfIfState'));
switch ($ospfPort->ospfIfState) {
case 'down':
$severity = 5;
break;
case 'designatedRouter':
$severity = 1;
break;
case 'backupDesignatedRouter':
$severity = 1;
break;
case 'otherDesignatedRouter':
$severity = 1;
break;
case 'pointToPoint':
$severity = 1;
break;
case 'waiting':
$severity = 4;
break;
case 'loopback':
$severity = 4;
break;
default:
$severity = 0;
break;
}
$severity = match ($ospfPort->ospfIfState) {
'down' => Severity::Error,
'designatedRouter', 'backupDesignatedRouter', 'otherDesignatedRouter', 'pointToPoint' => Severity::Ok,
'waiting', 'loopback' => Severity::Warning,
default => Severity::Unknown,
};
$trap->log("OSPF interface $port->ifName is $ospfPort->ospfIfState", $severity);

View File

@ -29,6 +29,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -49,13 +50,11 @@ class OspfNbrStateChange implements SnmptrapHandler
$ospfNbr->ospfNbrState = $trap->getOidData($trap->findOid('OSPF-MIB::ospfNbrState'));
$severity = 4;
if ($ospfNbr->ospfNbrState == 'full') {
$severity = 1;
} elseif ($ospfNbr->ospfNbrState == 'down') {
$severity = 5;
}
$severity = match ($ospfNbr->ospfNbrState) {
'full' => Severity::Ok,
'down' => Severity::Error,
default => Severity::Warning,
};
$trap->log("OSPF neighbor $ospfNbrIpAddr changed state to $ospfNbr->ospfNbrState", $severity);

View File

@ -32,6 +32,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
@ -48,6 +49,6 @@ class RuckusSzClusterInMaintenance implements SnmptrapHandler
public function handle(Device $device, Trap $trap)
{
$clusterName = $trap->getOidData($trap->findOid('RUCKUS-SZ-EVENT-MIB::ruckusSZClusterName'));
$trap->log("Smartzone cluster $clusterName state changed to maintenance", 3);
$trap->log("Smartzone cluster $clusterName state changed to maintenance", Severity::Notice);
}
}

View File

@ -28,15 +28,17 @@
namespace LibreNMS\Snmptrap\Handlers;
use LibreNMS\Enum\Severity;
class RuckusSzSeverity
{
public static function getSeverity(string $severity): int
public static function getSeverity(string $severity): Severity
{
return match ($severity) {
'Critical' => 5,
'Major', 'Minor' => 4,
'Warning' => 3,
default => 2 // Informational
'Critical' => Severity::Error,
'Major', 'Minor' => Severity::Warning,
'Warning' => Severity::Notice,
default => Severity::Info,
};
}
}

View File

@ -25,19 +25,20 @@
namespace LibreNMS\Snmptrap\Handlers;
use Illuminate\Support\Arr;
use LibreNMS\Enum\Severity;
use LibreNMS\Snmptrap\Trap;
class Tripplite
{
protected function getSeverity(Trap $trap): int
protected function getSeverity(Trap $trap): Severity
{
return Arr::get([
'critical' => 5,
'warning' => 4,
'info' => 2,
'status' => 3,
], $trap->getOidData('TRIPPLITE-PRODUCTS::tlpAlarmType'), 4);
return match ($trap->getOidData('TRIPPLITE-PRODUCTS::tlpAlarmType')) {
'critical' => Severity::Error,
'warning' => Severity::Warning,
'info' => Severity::Info,
'status' => Severity::Notice,
default => Severity::Warning,
};
}
protected function describe(Trap $trap): string

View File

@ -26,6 +26,7 @@ namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use Illuminate\Support\Str;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -44,7 +45,7 @@ class UpsTrapOnBattery implements SnmptrapHandler
{
$min_remaining = (int) Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsEstimatedMinutesRemaining')), ' ');
$sec_time = (int) Str::before($trap->getOidData($trap->findOid('UPS-MIB::upsSecondsOnBattery')), ' ');
$trap->log("UPS running on battery for $sec_time seconds. Estimated $min_remaining minutes remaining", 5);
$trap->log("UPS running on battery for $sec_time seconds. Estimated $min_remaining minutes remaining", Severity::Error);
$sensor_remaining = $device->sensors()->where('sensor_index', '200')->where('sensor_type', 'rfc1628')->first();
if (! $sensor_remaining) {
Log::warning("Snmptrap upsTrapOnBattery: Could not find matching sensor \'Estimated battery time remaining\' for device: " . $device->hostname);

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -50,6 +51,6 @@ class UpsmgUtilityFailure implements SnmptrapHandler
}
$sensor->sensor_current = 1;
$sensor->save();
$trap->log('UPS power failed, state sensor ' . $sensor->sensor_descr . ' has changed to ' . $sensor->sensor_current . '.', 5, 'Power');
$trap->log('UPS power failed, state sensor ' . $sensor->sensor_descr . ' has changed to ' . $sensor->sensor_current . '.', Severity::Error, 'Power');
}
}

View File

@ -24,6 +24,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -48,6 +49,6 @@ class UpsmgUtilityRestored implements SnmptrapHandler
}
$sensor->sensor_current = 2;
$sensor->save();
$trap->log('UPS power restored, state sensor ' . $sensor->sensor_descr . ' has changed to ' . $sensor->sensor_current . '.', 1, 'Power');
$trap->log('UPS power restored, state sensor ' . $sensor->sensor_descr . ' has changed to ' . $sensor->sensor_current . '.', Severity::Ok, 'Power');
}
}

View File

@ -6,7 +6,7 @@ use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
class VeeamBackupJobCompleted implements SnmptrapHandler
class VeeamBackupJobCompleted extends VeeamTrap implements SnmptrapHandler
{
/**
* Handle snmptrap.
@ -21,8 +21,8 @@ class VeeamBackupJobCompleted implements SnmptrapHandler
$name = $trap->getOidData('VEEAM-MIB::backupJobName');
$comment = $trap->getOidData('VEEAM-MIB::backupJobComment');
$result = $trap->getOidData('VEEAM-MIB::backupJobResult');
$color = ['Success' => 1, 'Warning' => 4, 'Failed' => 5];
$severity = $this->getResultSeverity($result);
$trap->log('SNMP Trap: Backup Job ' . $result . ' - ' . $name . ' - ' . $comment, $color[$result], 'backup');
$trap->log('SNMP Trap: Backup Job ' . $result . ' - ' . $name . ' - ' . $comment, $severity, 'backup');
}
}

View File

@ -6,7 +6,7 @@ use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
class VeeamCdpRpoReport implements SnmptrapHandler
class VeeamCdpRpoReport extends VeeamTrap implements SnmptrapHandler
{
/**
* Handle snmptrap.
@ -21,8 +21,8 @@ class VeeamCdpRpoReport implements SnmptrapHandler
$policy_name = $trap->getOidData('VEEAM-MIB::cdpPolicyName');
$vm_name = $trap->getOidData('VEEAM-MIB::vmName');
$result = $trap->getOidData('VEEAM-MIB::cdpRpoStatus');
$color = ['Success' => 1, 'Warning' => 4, 'Failed' => 5];
$severity = $this->getResultSeverity($result);
$trap->log('SNMP Trap: CDP policy RPO status change' . $result . ' - ' . $policy_name . ' ' . $vm_name, $color[$result], 'policy');
$trap->log('SNMP Trap: CDP policy RPO status change' . $result . ' - ' . $policy_name . ' ' . $vm_name, $severity, 'policy');
}
}

View File

@ -6,7 +6,7 @@ use App\Models\Device;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
class VeeamLinuxFLRCopyToFinished implements SnmptrapHandler
class VeeamLinuxFLRCopyToFinished extends VeeamTrap implements SnmptrapHandler
{
/**
* Handle snmptrap.
@ -24,8 +24,8 @@ class VeeamLinuxFLRCopyToFinished implements SnmptrapHandler
$target_dir = $trap->getOidData('VEEAM-MIB::targetDir');
$time = $trap->getOidData('VEEAM-MIB::transferTime');
$result = $trap->getOidData('VEEAM-MIB::transferStatus');
$color = ['Success' => 1, 'Warning' => 4, 'Failed' => 5];
$severity = $this->getResultSeverity($result);
$trap->log('SNMP Trap: FLR job ' . $result . ' - ' . $vm_name . ' - ' . $initiator_name . ' ' . $target_host . ' ' . $target_dir . ' Time taken: ' . $time, $color[$result], 'backup');
$trap->log('SNMP Trap: FLR job ' . $result . ' - ' . $vm_name . ' - ' . $initiator_name . ' ' . $target_host . ' ' . $target_dir . ' Time taken: ' . $time, $severity, 'backup');
}
}

View File

@ -3,10 +3,11 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
class VeeamLinuxFLRCopyToStarted implements SnmptrapHandler
class VeeamLinuxFLRCopyToStarted extends VeeamTrap implements SnmptrapHandler
{
/**
* Handle snmptrap.
@ -23,6 +24,6 @@ class VeeamLinuxFLRCopyToStarted implements SnmptrapHandler
$target_host = $trap->getOidData('VEEAM-MIB::targetHost');
$target_dir = $trap->getOidData('VEEAM-MIB::targetDir');
$trap->log('SNMP Trap: FLR job started - ' . $vm_name . ' - ' . $initiator_name . ' ' . $target_dir . ' ' . $target_host, 2, 'backup');
$trap->log('SNMP Trap: FLR job started - ' . $vm_name . ' - ' . $initiator_name . ' ' . $target_dir . ' ' . $target_host, Severity::Info, 'backup');
}
}

View File

@ -3,10 +3,11 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use LibreNMS\Enum\Severity;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
class VeeamLinuxFLRMountStarted implements SnmptrapHandler
class VeeamLinuxFLRMountStarted extends VeeamTrap implements SnmptrapHandler
{
/**
* Handle snmptrap.
@ -21,6 +22,6 @@ class VeeamLinuxFLRMountStarted implements SnmptrapHandler
$initiator_name = $trap->getOidData('VEEAM-MIB::initiatorName');
$vm_name = $trap->getOidData('VEEAM-MIB::vmName');
$trap->log('SNMP Trap: FLR job started - ' . $vm_name . ' - ' . $initiator_name, 2, 'backup');
$trap->log('SNMP Trap: FLR job started - ' . $vm_name . ' - ' . $initiator_name, Severity::Info, 'backup');
}
}

Some files were not shown because too many files have changed in this diff Show More