mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix availability map downtime (#11638)
* fix * fix widget * fix widget * fix widget * fix * last_polled fix * factorize down / up time device * factorize down / up time device * factorize down / up time device * factorize down / up time device * factorize down / up time device
This commit is contained in:
@@ -102,7 +102,7 @@ class AvailabilityMapController extends WidgetController
|
|||||||
$device_query->isNotDisabled();
|
$device_query->isNotDisabled();
|
||||||
}
|
}
|
||||||
$device_query->orderBy($settings['order_by']);
|
$device_query->orderBy($settings['order_by']);
|
||||||
$devices = $device_query->select('devices.device_id', 'hostname', 'sysName', 'status', 'uptime', 'disabled', 'disable_notify', 'location_id')->get();
|
$devices = $device_query->select('devices.device_id', 'hostname', 'sysName', 'status', 'uptime', 'last_polled', 'disabled', 'disable_notify', 'location_id')->get();
|
||||||
|
|
||||||
// process status
|
// process status
|
||||||
$uptime_warn = Config::get('uptime_warning', 84600);
|
$uptime_warn = Config::get('uptime_warning', 84600);
|
||||||
|
@@ -203,9 +203,10 @@ class Device extends BaseModel
|
|||||||
return Permissions::canAccessDevice($this->device_id, $user->user_id);
|
return Permissions::canAccessDevice($this->device_id, $user->user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function formatUptime($short = false)
|
public function formatDownUptime($short = false)
|
||||||
{
|
{
|
||||||
return Time::formatInterval($this->uptime, $short);
|
$time = ($this->status == 1) ? $this->uptime : time() - strtotime($this->last_polled);
|
||||||
|
return Time::formatInterval($time, $short);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -171,7 +171,7 @@ if (defined('SHOW_SETTINGS')) {
|
|||||||
$in_devices = dbFetchColumn($device_group, [Session::get('group_view')]);
|
$in_devices = dbFetchColumn($device_group, [Session::get('group_view')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = 'SELECT `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`status`, `D`.`uptime`, `D`.`os`, `D`.`icon`, `D`.`disable_notify`, `D`.`disabled` FROM `devices` AS `D`';
|
$sql = 'SELECT `D`.`hostname`, `D`.`sysName`, `D`.`device_id`, `D`.`status`, `D`.`uptime`, `D`.`last_polled`, `D`.`os`, `D`.`icon`, `D`.`disable_notify`, `D`.`disabled` FROM `devices` AS `D`';
|
||||||
|
|
||||||
if (!Auth::user()->hasGlobalRead()) {
|
if (!Auth::user()->hasGlobalRead()) {
|
||||||
$sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND ';
|
$sql .= ' , `devices_perms` AS P WHERE D.`device_id` = P.`device_id` AND P.`user_id` = ? AND ';
|
||||||
@@ -197,6 +197,7 @@ if (defined('SHOW_SETTINGS')) {
|
|||||||
$temp_output = array();
|
$temp_output = array();
|
||||||
|
|
||||||
foreach (dbFetchRows($sql, $param) as $device) {
|
foreach (dbFetchRows($sql, $param) as $device) {
|
||||||
|
$updowntime = "";
|
||||||
if ($device['disabled'] == '1') {
|
if ($device['disabled'] == '1') {
|
||||||
$deviceState = "disabled";
|
$deviceState = "disabled";
|
||||||
$deviceLabel = "blackbg";
|
$deviceLabel = "blackbg";
|
||||||
@@ -217,11 +218,13 @@ if (defined('SHOW_SETTINGS')) {
|
|||||||
$deviceLabelOld = 'availability-map-oldview-box-up';
|
$deviceLabelOld = 'availability-map-oldview-box-up';
|
||||||
$host_up_count++;
|
$host_up_count++;
|
||||||
}
|
}
|
||||||
|
$updowntime = ($device['uptime'] ? " - " : "") . formatUptime($device['uptime']);
|
||||||
} else {
|
} else {
|
||||||
$deviceState = 'down';
|
$deviceState = 'down';
|
||||||
$deviceLabel = 'label-danger';
|
$deviceLabel = 'label-danger';
|
||||||
$deviceLabelOld = 'availability-map-oldview-box-down';
|
$deviceLabelOld = 'availability-map-oldview-box-down';
|
||||||
$host_down_count++;
|
$host_down_count++;
|
||||||
|
$updowntime = ($device['last_polled'] ? " - " . formatUptime(time() - strtotime($device['last_polled'])) : "") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AlertUtil::isMaintenance($device['device_id'])) {
|
if (AlertUtil::isMaintenance($device['device_id'])) {
|
||||||
@@ -235,7 +238,7 @@ if (defined('SHOW_SETTINGS')) {
|
|||||||
if ($directpage == "yes") {
|
if ($directpage == "yes") {
|
||||||
$deviceIcon = getIconTag($device);
|
$deviceIcon = getIconTag($device);
|
||||||
$temp_output[] = '
|
$temp_output[] = '
|
||||||
<a href="' .generate_device_url($device). '" title="' . $device_system_name . ($device['uptime'] ? " - " : "") . formatUptime($device['uptime']) . '">
|
<a href="' .generate_device_url($device). '" title="' . $device_system_name . $updowntime . '">
|
||||||
<div class="device-availability ' . $deviceState . '" style="width:' . Config::get('webui.availability_map_box_size') . 'px;">
|
<div class="device-availability ' . $deviceState . '" style="width:' . Config::get('webui.availability_map_box_size') . 'px;">
|
||||||
<span class="availability-label label ' . $deviceLabel . ' label-font-border">' . $deviceState . '</span>
|
<span class="availability-label label ' . $deviceLabel . ' label-font-border">' . $deviceState . '</span>
|
||||||
<span class="device-icon">' . $deviceIcon . '</span><br>
|
<span class="device-icon">' . $deviceIcon . '</span><br>
|
||||||
@@ -248,12 +251,12 @@ if (defined('SHOW_SETTINGS')) {
|
|||||||
$deviceLabel .= ' widget-availability-fixed';
|
$deviceLabel .= ' widget-availability-fixed';
|
||||||
}
|
}
|
||||||
$temp_output[] = '
|
$temp_output[] = '
|
||||||
<a href="' .generate_device_url($device). '" title="' . $device_system_name . " - " . formatUptime($device['uptime']) . '">
|
<a href="' .generate_device_url($device). '" title="' . $device_system_name . $updowntime . '">
|
||||||
<span class="label ' . $deviceLabel . ' widget-availability label-font-border">' . $deviceState . '</span>
|
<span class="label ' . $deviceLabel . ' widget-availability label-font-border">' . $deviceState . '</span>
|
||||||
</a>';
|
</a>';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$temp_output[] = "<a href='" . generate_device_url($device) . "' title='" . $device_system_name . ' - ' . formatUptime($device['uptime']) . "'><div class='" . $deviceLabelOld . "' style='width:${compact_tile}px;height:${compact_tile}px;'></div></a>";
|
$temp_output[] = "<a href='" . generate_device_url($device) . "' title='" . $device_system_name . $updowntime . "'><div class='" . $deviceLabelOld . "' style='width:${compact_tile}px;height:${compact_tile}px;'></div></a>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
<td><img src="{{ asset($device->icon) }}" width="32px" height="32px"></td>
|
<td><img src="{{ asset($device->icon) }}" width="32px" height="32px"></td>
|
||||||
<td class="device-name">{{ $device->displayName() }}</td>
|
<td class="device-name">{{ $device->displayName() }}</td>
|
||||||
<td>{{ $device->hardware }} {{ $device->features }}</td>
|
<td>{{ $device->hardware }} {{ $device->features }}</td>
|
||||||
<td>{{ $device->formatUptime(true) }}<br>{{ substr($device->location, 0, 32) }}</td>
|
<td>{{ $device->formatDownUptime(true) }}<br>{{ substr($device->location, 0, 32) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
@endforeach
|
@endforeach
|
||||||
</table>
|
</table>
|
||||||
|
@@ -65,7 +65,7 @@
|
|||||||
{!! \LibreNMS\Util\Url::deviceLink($device, $device->shortDisplayName()) !!}
|
{!! \LibreNMS\Util\Url::deviceLink($device, $device->shortDisplayName()) !!}
|
||||||
<span class="device-rebooted">@lang('Device Rebooted')</span>
|
<span class="device-rebooted">@lang('Device Rebooted')</span>
|
||||||
<br />
|
<br />
|
||||||
<span class="body-date-1">{{ $device->formatUptime(true) }}</span>
|
<span class="body-date-1">{{ $device->formatDownUptime(true) }}</span>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
<br style="clear:both;">
|
<br style="clear:both;">
|
||||||
|
|
||||||
@foreach($devices as $device)
|
@foreach($devices as $device)
|
||||||
<a href="@deviceUrl($device)" title="{{ $device->displayName() }}@if($device->formatUptime(true)) - @endif{{ $device->formatUptime(true) }}">
|
<a href="@deviceUrl($device)" title="{{$device->displayName() }}@if($device->stateName == 'up' or $device->stateName == 'warn')@if($device->formatDownUptime(true)) - @endif{{ $device->formatDownUptime(true) }}@elseif($device->stateName == 'down')@if($device->formatDownUptime(true)) - downtime @endif{{$device->formatDownUptime(true)}}@endif">
|
||||||
@if($type == 0)
|
@if($type == 0)
|
||||||
@if($color_only_select == 1)
|
@if($color_only_select == 1)
|
||||||
<span class="label {{ $device->labelClass }} widget-availability-fixed widget-availability label-font-border"> </span>
|
<span class="label {{ $device->labelClass }} widget-availability-fixed widget-availability label-font-border"> </span>
|
||||||
|
Reference in New Issue
Block a user