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->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
|
||||
$uptime_warn = Config::get('uptime_warning', 84600);
|
||||
|
@@ -203,9 +203,10 @@ class Device extends BaseModel
|
||||
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')]);
|
||||
}
|
||||
|
||||
$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()) {
|
||||
$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();
|
||||
|
||||
foreach (dbFetchRows($sql, $param) as $device) {
|
||||
$updowntime = "";
|
||||
if ($device['disabled'] == '1') {
|
||||
$deviceState = "disabled";
|
||||
$deviceLabel = "blackbg";
|
||||
@@ -217,11 +218,13 @@ if (defined('SHOW_SETTINGS')) {
|
||||
$deviceLabelOld = 'availability-map-oldview-box-up';
|
||||
$host_up_count++;
|
||||
}
|
||||
$updowntime = ($device['uptime'] ? " - " : "") . formatUptime($device['uptime']);
|
||||
} else {
|
||||
$deviceState = 'down';
|
||||
$deviceLabel = 'label-danger';
|
||||
$deviceLabelOld = 'availability-map-oldview-box-down';
|
||||
$host_down_count++;
|
||||
$updowntime = ($device['last_polled'] ? " - " . formatUptime(time() - strtotime($device['last_polled'])) : "") ;
|
||||
}
|
||||
|
||||
if (AlertUtil::isMaintenance($device['device_id'])) {
|
||||
@@ -235,7 +238,7 @@ if (defined('SHOW_SETTINGS')) {
|
||||
if ($directpage == "yes") {
|
||||
$deviceIcon = getIconTag($device);
|
||||
$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;">
|
||||
<span class="availability-label label ' . $deviceLabel . ' label-font-border">' . $deviceState . '</span>
|
||||
<span class="device-icon">' . $deviceIcon . '</span><br>
|
||||
@@ -248,12 +251,12 @@ if (defined('SHOW_SETTINGS')) {
|
||||
$deviceLabel .= ' widget-availability-fixed';
|
||||
}
|
||||
$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>
|
||||
</a>';
|
||||
}
|
||||
} 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 class="device-name">{{ $device->displayName() }}</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>
|
||||
@endforeach
|
||||
</table>
|
||||
|
@@ -65,7 +65,7 @@
|
||||
{!! \LibreNMS\Util\Url::deviceLink($device, $device->shortDisplayName()) !!}
|
||||
<span class="device-rebooted">@lang('Device Rebooted')</span>
|
||||
<br />
|
||||
<span class="body-date-1">{{ $device->formatUptime(true) }}</span>
|
||||
<span class="body-date-1">{{ $device->formatDownUptime(true) }}</span>
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
|
@@ -26,7 +26,7 @@
|
||||
<br style="clear:both;">
|
||||
|
||||
@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($color_only_select == 1)
|
||||
<span class="label {{ $device->labelClass }} widget-availability-fixed widget-availability label-font-border"> </span>
|
||||
|
Reference in New Issue
Block a user