mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add 'alert history' widget for dashboard (#10901)
* add alert history dashboard * add sql-schema * only alert * add settings * add settings * fix display alert details * fix db-schema * add filtering by severity * fix code climate * Update common.php
This commit is contained in:
60
app/Http/Controllers/Widgets/AlertlogController.php
Normal file
60
app/Http/Controllers/Widgets/AlertlogController.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* AlertlogController.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 2018 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Widgets;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AlertlogController extends WidgetController
|
||||
{
|
||||
protected $title = 'Alert history';
|
||||
protected $defaults = [
|
||||
'title' => null,
|
||||
'device_id' => '',
|
||||
'state' => -1,
|
||||
'min_severity' => null
|
||||
];
|
||||
|
||||
public function getView(Request $request)
|
||||
{
|
||||
return view('widgets.alertlog', $this->getSettings());
|
||||
}
|
||||
|
||||
|
||||
public function getSettingsView(Request $request)
|
||||
{
|
||||
$data = $this->getSettings(true);
|
||||
$data['severities'] = [
|
||||
// alert_rules.status is enum('ok','warning','critical')
|
||||
'ok' => 1,
|
||||
'warning' => 2,
|
||||
'critical' => 3,
|
||||
'ok only' => 4,
|
||||
'warning only' => 5,
|
||||
'critical only' => 6,
|
||||
];
|
||||
return view('widgets.settings.alertlog', $data);
|
||||
}
|
||||
}
|
@@ -91,6 +91,11 @@ class DefaultWidgetSeeder extends Seeder
|
||||
"widget_title" => "Server Stats",
|
||||
"widget" => "server-stats",
|
||||
"base_dimensions" => "6,3",
|
||||
],
|
||||
[
|
||||
"widget_title" => "Alert History",
|
||||
"widget" => "alertlog",
|
||||
"base_dimensions" => "6,3",
|
||||
]
|
||||
];
|
||||
|
||||
|
@@ -13,6 +13,17 @@
|
||||
* @author LibreNMS Contributors
|
||||
*/
|
||||
|
||||
$alert_severities = array(
|
||||
// alert_rules.status is enum('ok','warning','critical')
|
||||
'ok' => 1,
|
||||
'warning' => 2,
|
||||
'critical' => 3,
|
||||
'ok only' => 4,
|
||||
'warning only' => 5,
|
||||
'critical only' => 6,
|
||||
);
|
||||
|
||||
|
||||
$where = 1;
|
||||
$param = [];
|
||||
|
||||
|
62
resources/views/widgets/alertlog.blade.php
Normal file
62
resources/views/widgets/alertlog.blade.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<span id="message"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table id="alertlog_{{ $id }}" class="table table-hover table-condensed alerts">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="status" data-sortable="false"></th>
|
||||
<th data-column-id="time_logged" data-order="desc">Timestamp</th>
|
||||
<th data-column-id="details" data-sortable="false"> </th>
|
||||
<th data-column-id="hostname">Device</th>
|
||||
<th data-column-id="alert">Alert</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
<script>
|
||||
var grid = $("#alertlog_{{ $id }}").bootgrid({
|
||||
ajax: true,
|
||||
rowCount: [50, 100, 250, -1],
|
||||
post: function () {
|
||||
return {
|
||||
id: "alertlog",
|
||||
device_id: "",
|
||||
state: '{{ $state }}',
|
||||
min_severity: '{{ $min_severity }}',
|
||||
};
|
||||
},
|
||||
url: "ajax_table.php"
|
||||
}).on("loaded.rs.jquery.bootgrid", function () {
|
||||
|
||||
var results = $("div.infos").text().split(" ");
|
||||
low = results[1] - 1;
|
||||
high = results[3];
|
||||
max = high - low;
|
||||
search = $('.search-field').val();
|
||||
|
||||
grid.find(".incident-toggle").each(function () {
|
||||
$(this).parent().addClass('incident-toggle-td');
|
||||
}).on("click", function (e) {
|
||||
var target = $(this).data("target");
|
||||
$(target).collapse('toggle');
|
||||
$(this).toggleClass('fa-plus fa-minus');
|
||||
});
|
||||
grid.find(".incident").each(function () {
|
||||
$(this).parent().addClass('col-lg-4 col-md-4 col-sm-4 col-xs-4');
|
||||
$(this).parent().parent().on("mouseenter", function () {
|
||||
$(this).find(".incident-toggle").fadeIn(200);
|
||||
}).on("mouseleave", function () {
|
||||
$(this).find(".incident-toggle").fadeOut(200);
|
||||
}).on("click", "td:not(.incident-toggle-td)", function () {
|
||||
var target = $(this).parent().find(".incident-toggle").data("target");
|
||||
if ($(this).parent().find(".incident-toggle").hasClass('fa-plus')) {
|
||||
$(this).parent().find(".incident-toggle").toggleClass('fa-plus fa-minus');
|
||||
$(target).collapse('toggle');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
25
resources/views/widgets/settings/alertlog.blade.php
Normal file
25
resources/views/widgets/settings/alertlog.blade.php
Normal file
@@ -0,0 +1,25 @@
|
||||
@extends('widgets.settings.base')
|
||||
|
||||
@section('form')
|
||||
<div class="form-group row">
|
||||
<label for="title-{{ $id }}" class="control-label">@lang('Widget title')</label>
|
||||
<input type="text" class="form-control" name="title" id="title-{{ $id }}" placeholder="@lang('Custom title')" value="{{ $title }}">
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="state-{{ $id }}" class="control-label">@lang('State'):</label>
|
||||
<select class="form-control" name="state" id="state-{{ $id }}">
|
||||
<option value="-1">@lang('not filtered')</option>
|
||||
<option value="0" @if($state === '1') selected @endif>@lang('OK')</option>
|
||||
<option value="1" @if($state === '0') selected @endif>@lang('Alert')</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="min_severity-{{ $id }}" class="control-label">@lang('Displayed severity'):</label>
|
||||
<select class="form-control" name="min_severity" id="min_severity-{{ $id }}">
|
||||
<option value="">@lang('any severity')</option>
|
||||
@foreach($severities as $name => $val)
|
||||
<option value="{{ $val }}" @if($min_severity == $val) selected @endif>{{ $name }}{{$val > 3 ? '' : ' ' . __('or higher')}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
@endsection
|
@@ -117,6 +117,7 @@ Route::group(['middleware' => ['auth', '2fa'], 'guard' => 'auth'], function () {
|
||||
// dashboard widgets
|
||||
Route::group(['prefix' => 'dash', 'namespace' => 'Widgets'], function () {
|
||||
Route::post('alerts', 'AlertsController');
|
||||
Route::post('alertlog', 'AlertlogController');
|
||||
Route::post('availability-map', 'AvailabilityMapController');
|
||||
Route::post('component-status', 'ComponentStatusController');
|
||||
Route::post('device-summary-horiz', 'DeviceSummaryHorizController');
|
||||
|
Reference in New Issue
Block a user