mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Enumerate Alert Level (#11652)
This commit is contained in:
36
LibreNMS/Enum/Alert.php
Normal file
36
LibreNMS/Enum/Alert.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* Alert.php
|
||||
*
|
||||
* Enumerates alarming Level
|
||||
*
|
||||
* 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 2020 Thomas Berberich
|
||||
* @author Thomas Berberich <sourcehhdoctor@gmail.com>
|
||||
*/
|
||||
|
||||
namespace LibreNMS\Enum;
|
||||
|
||||
abstract class Alert
|
||||
{
|
||||
const UNKNOWN = 0;
|
||||
const OK = 1;
|
||||
const INFO = 2;
|
||||
const NOTICE = 3;
|
||||
const WARNING = 4;
|
||||
const ERROR = 5;
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class Checks
|
||||
$user = Auth::user();
|
||||
|
||||
if ($user->isAdmin()) {
|
||||
$notifications = Notification::isUnread($user)->where('severity', '>', 1)->get();
|
||||
$notifications = Notification::isUnread($user)->where('severity', '>', \LibreNMS\Enum\Alert::OK)->get();
|
||||
foreach ($notifications as $notification) {
|
||||
Toastr::error("<a href='notifications/'>$notification->body</a>", $notification->title);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
namespace App\Facades;
|
||||
|
||||
use Auth;
|
||||
use LibreNMS\Enum\Alert;
|
||||
|
||||
class LogManager extends \Illuminate\Log\LogManager
|
||||
{
|
||||
@@ -38,7 +39,7 @@ class LogManager extends \Illuminate\Log\LogManager
|
||||
* @param int $severity 1: ok, 2: info, 3: notice, 4: warning, 5: critical, 0: unknown
|
||||
* @param int $reference the id of the referenced entity. Supported types: interface
|
||||
*/
|
||||
public function event($text, $device = null, $type = null, $severity = 2, $reference = null)
|
||||
public function event($text, $device = null, $type = null, $severity = Alert::INFO, $reference = null)
|
||||
{
|
||||
(new \App\Models\Eventlog([
|
||||
'device_id' => $device instanceof \App\Models\Device ? $device->device_id : $device,
|
||||
|
||||
@@ -29,6 +29,7 @@ use App\Models\Eventlog;
|
||||
use Carbon\Carbon;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\Url;
|
||||
use LibreNMS\Enum\Alert;
|
||||
|
||||
class EventlogController extends TableController
|
||||
{
|
||||
@@ -119,15 +120,15 @@ class EventlogController extends TableController
|
||||
private function severityLabel($eventlog_severity)
|
||||
{
|
||||
switch ($eventlog_severity) {
|
||||
case 1:
|
||||
case Alert::OK:
|
||||
return "label-success"; //OK
|
||||
case 2:
|
||||
case Alert::INFO:
|
||||
return "label-info"; //Informational
|
||||
case 3:
|
||||
case Alert::NOTICE:
|
||||
return "label-primary"; //Notice
|
||||
case 4:
|
||||
case Alert::WARNING:
|
||||
return "label-warning"; //Warning
|
||||
case 5:
|
||||
case Alert::ERROR:
|
||||
return "label-danger"; //Critical
|
||||
default:
|
||||
return "label-default"; //Unknown
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use LibreNMS\Enum\Alert;
|
||||
|
||||
class Eventlog extends DeviceRelatedModel
|
||||
{
|
||||
@@ -45,7 +46,7 @@ class Eventlog extends DeviceRelatedModel
|
||||
* @param int $severity 1: ok, 2: info, 3: notice, 4: warning, 5: critical, 0: unknown
|
||||
* @param int $reference the id of the referenced entity. Supported types: interface
|
||||
*/
|
||||
public static function log($text, $device = null, $type = null, $severity = 2, $reference = null)
|
||||
public static function log($text, $device = null, $type = null, $severity = Alert::INFO, $reference = null)
|
||||
{
|
||||
$log = new static([
|
||||
'reference' => $reference,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
use LibreNMS\Enum\Alert;
|
||||
use LibreNMS\Exceptions\JsonAppException;
|
||||
use LibreNMS\Exceptions\JsonAppPollingFailedException;
|
||||
use LibreNMS\Exceptions\JsonAppParsingFailedException;
|
||||
@@ -592,26 +593,25 @@ function update_application($app, $response, $metrics = array(), $status = '')
|
||||
|
||||
$app_name = \LibreNMS\Util\StringHelpers::nicecase($app['app_type']);
|
||||
|
||||
# $severity 1: ok, 2: info, 3: notice, 4: warning, 5: critical, 0: unknown
|
||||
switch ($data['app_state']) {
|
||||
case 'OK':
|
||||
$severity = 1;
|
||||
$severity = Alert::OK;
|
||||
$event_msg = "changed to OK";
|
||||
break;
|
||||
case 'ERROR':
|
||||
$severity = 5;
|
||||
$severity = Alert::ERROR;
|
||||
$event_msg = "ends with ERROR";
|
||||
break;
|
||||
case 'LEGACY':
|
||||
$severity = 4;
|
||||
$severity = Alert::WARNING;
|
||||
$event_msg = "Client Agent is deprecated";
|
||||
break;
|
||||
case 'UNSUPPORTED':
|
||||
$severity = 5;
|
||||
$severity = Alert::ERROR;
|
||||
$event_msg = "Client Agent Version is not supported";
|
||||
break;
|
||||
default:
|
||||
$severity = 0;
|
||||
$severity = Alert::UNKNOWN;
|
||||
$event_msg = "has UNKNOWN state";
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user