mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Show Device Outages as Log List (#12011)
This commit is contained in:
134
app/Http/Controllers/Table/OutagesController.php
Normal file
134
app/Http/Controllers/Table/OutagesController.php
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* OutagesController.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 2020 Thomas Berberich
|
||||||
|
* @author Thomas Berberich <sourcehhdoctor@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Table;
|
||||||
|
|
||||||
|
use App\Models\DeviceOutage;
|
||||||
|
use App\Models\Eventlog;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use LibreNMS\Config;
|
||||||
|
use LibreNMS\Util\Url;
|
||||||
|
use LibreNMS\Enum\Alert;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
class OutagesController extends TableController
|
||||||
|
{
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'device' => 'nullable|int',
|
||||||
|
'to' => 'nullable|date',
|
||||||
|
'from' => 'nullable|date',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function filterFields($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'device_id' => 'device',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function sortFields($request)
|
||||||
|
{
|
||||||
|
return ['going_down', 'up_again', 'device_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines the base query for this resource
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
|
||||||
|
*/
|
||||||
|
public function baseQuery($request)
|
||||||
|
{
|
||||||
|
return DeviceOutage::hasAccess($request->user())
|
||||||
|
->with('device')
|
||||||
|
->when($request->from, function ($query) use ($request) {
|
||||||
|
$query->where('going_down', '>=', strtotime($request->from));
|
||||||
|
})
|
||||||
|
->when($request->to, function ($query) use ($request) {
|
||||||
|
$query->where('going_down', '<=', strtotime($request->to));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function formatItem($outage)
|
||||||
|
{
|
||||||
|
$start = $this->formatDatetime($outage->going_down);
|
||||||
|
$end = $outage->up_again ? $this->formatDatetime($outage->up_again) : '-';
|
||||||
|
$duration = ($outage->up_again ?: time()) - $outage->going_down;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'status' => $this->statusLabel($outage),
|
||||||
|
'going_down' => $start,
|
||||||
|
'up_again' => $end,
|
||||||
|
'device_id' => $outage->device ? Url::deviceLink($outage->device, $outage->device->shortDisplayName()) : null,
|
||||||
|
'duration' => $this->formatTime($duration),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatTime($duration)
|
||||||
|
{
|
||||||
|
$day_seconds = 86400;
|
||||||
|
|
||||||
|
$duration_days = (int)($duration / $day_seconds);
|
||||||
|
$duration_time = $duration % $day_seconds;
|
||||||
|
|
||||||
|
$output = "<span style='display:inline;'>";
|
||||||
|
if ($duration_days) {
|
||||||
|
$output .= $duration_days . 'd ';
|
||||||
|
}
|
||||||
|
$output .= (new Carbon($duration))->format(Config::get('dateformat.time'));
|
||||||
|
$output .= "</span>";
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatDatetime($timestamp)
|
||||||
|
{
|
||||||
|
if (! $timestamp) {
|
||||||
|
$timestamp = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = "<span style='display:inline;'>";
|
||||||
|
$output .= (new Carbon($timestamp))->format(Config::get('dateformat.compact'));
|
||||||
|
$output .= "</span>";
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function statusLabel($outage)
|
||||||
|
{
|
||||||
|
if (empty($outage->up_again)) {
|
||||||
|
$label = "label-danger";
|
||||||
|
} else {
|
||||||
|
$label = "label-success";
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = "<span class='alert-status " . $label . "'></span>";
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
}
|
@@ -27,7 +27,8 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class DeviceOutage extends Model
|
# class DeviceOutage extends Model
|
||||||
|
class DeviceOutage extends DeviceRelatedModel
|
||||||
{
|
{
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
protected $primaryKey = null;
|
protected $primaryKey = null;
|
||||||
|
50
includes/html/common/outages.inc.php
Normal file
50
includes/html/common/outages.inc.php
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 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. Please see LICENSE.txt at the top level of
|
||||||
|
* the source code distribution for details.
|
||||||
|
*
|
||||||
|
* @package LibreNMS
|
||||||
|
* @subpackage webui
|
||||||
|
* @link http://librenms.org
|
||||||
|
* @copyright 2017 LibreNMS
|
||||||
|
* @author LibreNMS Contributors
|
||||||
|
*/
|
||||||
|
|
||||||
|
$common_output[] = '
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table id="outages" class="table table-hover table-condensed table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th data-column-id="status" data-sortable="false"></th>
|
||||||
|
<th data-column-id="going_down" data-order="desc">Start</th>
|
||||||
|
<th data-column-id="up_again">End</th>
|
||||||
|
<th data-column-id="device_id">Hostname</th>
|
||||||
|
<th data-column-id="duration" data-sortable="false">Duration</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
var outages_grid = $("#outages").bootgrid({
|
||||||
|
ajax: true,
|
||||||
|
rowCount: [50, 100, 250, -1],
|
||||||
|
templates: {
|
||||||
|
search: ""
|
||||||
|
},
|
||||||
|
post: function ()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
device: "' . (int)($vars['device']) . '",
|
||||||
|
to: "' . addcslashes($vars['to'], '"') . '",
|
||||||
|
from: "' . addcslashes($vars['from'], '"') . '",
|
||||||
|
};
|
||||||
|
},
|
||||||
|
url: "' . url('/ajax/table/outages') . '"
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
';
|
@@ -24,6 +24,17 @@ echo '<div class="panel panel-default">';
|
|||||||
echo '<div class="panel-heading">';
|
echo '<div class="panel-heading">';
|
||||||
echo '<strong>Logging</strong> » ';
|
echo '<strong>Logging</strong> » ';
|
||||||
|
|
||||||
|
if ($vars['section'] == 'outages') {
|
||||||
|
echo '<span class="pagemenu-selected">';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo generate_link('Outages', $vars, array('section' => 'outages'));
|
||||||
|
if ($vars['section'] == 'outages') {
|
||||||
|
echo '</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo ' | ';
|
||||||
|
|
||||||
if ($vars['section'] == 'eventlog') {
|
if ($vars['section'] == 'eventlog') {
|
||||||
echo '<span class="pagemenu-selected">';
|
echo '<span class="pagemenu-selected">';
|
||||||
}
|
}
|
||||||
@@ -72,6 +83,10 @@ switch ($vars['section']) {
|
|||||||
case 'graylog':
|
case 'graylog':
|
||||||
include 'includes/html/pages/device/logs/'.$vars['section'].'.inc.php';
|
include 'includes/html/pages/device/logs/'.$vars['section'].'.inc.php';
|
||||||
break;
|
break;
|
||||||
|
case 'outages':
|
||||||
|
$vars['fromdevice'] = true;
|
||||||
|
include 'includes/html/pages/outages.inc.php';
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
128
includes/html/pages/outages.inc.php
Normal file
128
includes/html/pages/outages.inc.php
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 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. Please see LICENSE.txt at the top level of
|
||||||
|
* the source code distribution for details.
|
||||||
|
*
|
||||||
|
* @package LibreNMS
|
||||||
|
* @subpackage webui
|
||||||
|
* @link http://librenms.org
|
||||||
|
* @copyright 2017 LibreNMS
|
||||||
|
* @author LibreNMS Contributors
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use LibreNMS\Config;
|
||||||
|
|
||||||
|
$no_refresh = true;
|
||||||
|
$param = [];
|
||||||
|
$device_id = (int)$vars['device'];
|
||||||
|
|
||||||
|
$pagetitle[] = 'Outages';
|
||||||
|
?>
|
||||||
|
<div class="panel panel-default panel-condensed">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<strong>Outages</strong>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
require_once 'includes/html/common/outages.inc.php';
|
||||||
|
echo implode('', $common_output);
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
$('.actionBar').append(
|
||||||
|
'<div class="pull-left">' +
|
||||||
|
'<form method="post" action="" class="form-inline" role="form" id="result_form">' +
|
||||||
|
'<?php echo csrf_field() ?>'+
|
||||||
|
'<div class="form-group">' +
|
||||||
|
<?php
|
||||||
|
if (!isset($vars['fromdevice'])) {
|
||||||
|
?>
|
||||||
|
'<select name="device" id="device" class="form-control">' +
|
||||||
|
'<option value="">All Devices </option>' +
|
||||||
|
<?php
|
||||||
|
if ($device_id) {
|
||||||
|
echo "'<option value=$device_id>" . format_hostname(device_by_id_cache($device_id)) . "</option>' +";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
'</select>' +
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
|
echo "' <input type=\"hidden\" name=\"device\" id=\"device\" value=\"" . $device_id . "\">' + ";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
'</div>' +
|
||||||
|
' <div class="form-group">' +
|
||||||
|
'<input name="from" type="text" class="form-control" id="dtpickerfrom" maxlength="16" value="<?php echo $vars['from']; ?>" placeholder="From" data-date-format="YYYY-MM-DD HH:mm">' +
|
||||||
|
'</div>' +
|
||||||
|
'<div class="form-group">' +
|
||||||
|
' <input name="to" type="text" class="form-control" id="dtpickerto" maxlength="16" value="<?php echo $vars['to']; ?>" placeholder="To" data-date-format="YYYY-MM-DD HH:mm">' +
|
||||||
|
'</div>' +
|
||||||
|
' <button type="submit" class="btn btn-default">Filter</button>' +
|
||||||
|
'</form>' +
|
||||||
|
'</div>'
|
||||||
|
);
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
$("#dtpickerfrom").datetimepicker({
|
||||||
|
icons: {
|
||||||
|
time: 'fa fa-clock-o',
|
||||||
|
date: 'fa fa-calendar',
|
||||||
|
up: 'fa fa-chevron-up',
|
||||||
|
down: 'fa fa-chevron-down',
|
||||||
|
previous: 'fa fa-chevron-left',
|
||||||
|
next: 'fa fa-chevron-right',
|
||||||
|
today: 'fa fa-calendar-check-o',
|
||||||
|
clear: 'fa fa-trash-o',
|
||||||
|
close: 'fa fa-close'
|
||||||
|
},
|
||||||
|
defaultDate: '<?php echo Carbon::now()->subMonth()->format(Config::get('dateformat.byminute', 'Y-m-d H:i')); ?>'
|
||||||
|
});
|
||||||
|
$("#dtpickerfrom").on("dp.change", function (e) {
|
||||||
|
$("#dtpickerto").data("DateTimePicker").minDate(e.date);
|
||||||
|
});
|
||||||
|
$("#dtpickerto").datetimepicker({
|
||||||
|
icons: {
|
||||||
|
time: 'fa fa-clock-o',
|
||||||
|
date: 'fa fa-calendar',
|
||||||
|
up: 'fa fa-chevron-up',
|
||||||
|
down: 'fa fa-chevron-down',
|
||||||
|
previous: 'fa fa-chevron-left',
|
||||||
|
next: 'fa fa-chevron-right',
|
||||||
|
today: 'fa fa-calendar-check-o',
|
||||||
|
clear: 'fa fa-trash-o',
|
||||||
|
close: 'fa fa-close'
|
||||||
|
},
|
||||||
|
defaultDate: '<?php echo Carbon::now()->format(Config::get('dateformat.byminute', 'Y-m-d H:i')); ?>'
|
||||||
|
});
|
||||||
|
$("#dtpickerto").on("dp.change", function (e) {
|
||||||
|
$("#dtpickerfrom").data("DateTimePicker").maxDate(e.date);
|
||||||
|
});
|
||||||
|
if ($("#dtpickerfrom").val() != "") {
|
||||||
|
$("#dtpickerto").data("DateTimePicker").minDate($("#dtpickerfrom").val());
|
||||||
|
}
|
||||||
|
if ($("#dtpickerto").val() != "") {
|
||||||
|
$("#dtpickerfrom").data("DateTimePicker").maxDate($("#dtpickerto").val());
|
||||||
|
} else {
|
||||||
|
$("#dtpickerto").data("DateTimePicker").maxDate('<?php echo Carbon::now()->format(Config::get('dateformat.byminute', 'Y-m-d H:i')); ?>');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
<?php if (!isset($vars['fromdevice'])) { ?>
|
||||||
|
$("#device").select2({
|
||||||
|
theme: "bootstrap",
|
||||||
|
dropdownAutoWidth : true,
|
||||||
|
width: "auto",
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: "All Devices",
|
||||||
|
ajax: {
|
||||||
|
url: '<?php echo url('/ajax/select/device'); ?>',
|
||||||
|
delay: 200
|
||||||
|
}
|
||||||
|
})<?php echo $device_id ? ".val($device_id).trigger('change');" : ''; ?>;
|
||||||
|
<?php } ?>
|
||||||
|
</script>
|
||||||
|
|
@@ -126,6 +126,8 @@
|
|||||||
|
|
||||||
<li><a href="{{ url('inventory') }}"><i class="fa fa-cube fa-fw fa-lg"
|
<li><a href="{{ url('inventory') }}"><i class="fa fa-cube fa-fw fa-lg"
|
||||||
aria-hidden="true"></i> @lang('Inventory')</a></li>
|
aria-hidden="true"></i> @lang('Inventory')</a></li>
|
||||||
|
<li><a href="{{ url('outages') }}"><i class="fa fa-bar-chart fa-fw fa-lg"
|
||||||
|
aria-hidden="true"></i> @lang('Outages')</a></li>
|
||||||
@if($package_count)
|
@if($package_count)
|
||||||
<li><a href="{{ url('search/search=packages') }}"><i class="fa fa-archive fa-fw fa-lg"
|
<li><a href="{{ url('search/search=packages') }}"><i class="fa fa-archive fa-fw fa-lg"
|
||||||
aria-hidden="true"></i> @lang('Packages')
|
aria-hidden="true"></i> @lang('Packages')
|
||||||
|
@@ -118,6 +118,7 @@ Route::group(['middleware' => ['auth'], 'guard' => 'auth'], function () {
|
|||||||
Route::post('customers', 'CustomersController');
|
Route::post('customers', 'CustomersController');
|
||||||
Route::post('device', 'DeviceController');
|
Route::post('device', 'DeviceController');
|
||||||
Route::post('eventlog', 'EventlogController');
|
Route::post('eventlog', 'EventlogController');
|
||||||
|
Route::post('outages', 'OutagesController');
|
||||||
Route::post('fdb-tables', 'FdbTablesController');
|
Route::post('fdb-tables', 'FdbTablesController');
|
||||||
Route::post('routes', 'RoutesTablesController');
|
Route::post('routes', 'RoutesTablesController');
|
||||||
Route::post('graylog', 'GraylogController');
|
Route::post('graylog', 'GraylogController');
|
||||||
|
Reference in New Issue
Block a user