mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Display Up/Down time in Device List (#9951)
* First attempt of Up/Down time * First attempt of Up/Down time * Moved to Time::formatInterval() * cleaning * last polled in casts * Cleaning the variants of formatUptime() * Cleaning in ./html/includes/dev-overview-data.inc.php * Cleaning in ./html/includes/dev-overview-data.inc.php * Cleaning in ./html/includes/dev-overview-data.inc.php * updated includes/polling/core.inc.php * updated includes/alerts.inc.php * clean accessors
This commit is contained in:
@@ -31,6 +31,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use LibreNMS\Config;
|
||||
use LibreNMS\Util\Rewrite;
|
||||
use LibreNMS\Util\Url;
|
||||
use LibreNMS\Util\Time;
|
||||
|
||||
class DeviceController extends TableController
|
||||
{
|
||||
@@ -125,7 +126,7 @@ class DeviceController extends TableController
|
||||
'metrics' => $this->getMetrics($device),
|
||||
'hardware' => Rewrite::ciscoHardware($device),
|
||||
'os' => $this->getOsText($device),
|
||||
'uptime' => $device->formatUptime(true),
|
||||
'uptime' => Time::formatInterval($device->status ? $device->uptime : $device->last_polled->diffInSeconds(), 'short'),
|
||||
'location' => $this->getLocation($device),
|
||||
'actions' => $this->getActions($device),
|
||||
];
|
||||
|
@@ -13,6 +13,7 @@ use LibreNMS\Util\IP;
|
||||
use LibreNMS\Util\IPv4;
|
||||
use LibreNMS\Util\IPv6;
|
||||
use LibreNMS\Util\Url;
|
||||
use LibreNMS\Util\Time;
|
||||
|
||||
class Device extends BaseModel
|
||||
{
|
||||
@@ -21,7 +22,10 @@ class Device extends BaseModel
|
||||
public $timestamps = false;
|
||||
protected $primaryKey = 'device_id';
|
||||
protected $fillable = ['hostname', 'ip', 'status', 'status_reason'];
|
||||
protected $casts = ['status' => 'boolean'];
|
||||
protected $casts = [
|
||||
'last_polled' => 'datetime',
|
||||
'status' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Initialize this class
|
||||
@@ -253,34 +257,7 @@ class Device extends BaseModel
|
||||
|
||||
public function formatUptime($short = false)
|
||||
{
|
||||
$result = '';
|
||||
$interval = $this->uptime;
|
||||
$data = [
|
||||
'years' => 31536000,
|
||||
'days' => 86400,
|
||||
'hours' => 3600,
|
||||
'minutes' => 60,
|
||||
'seconds' => 1,
|
||||
];
|
||||
|
||||
foreach ($data as $k => $v) {
|
||||
if ($interval >= $v) {
|
||||
$diff = floor($interval / $v);
|
||||
|
||||
$result .= " $diff";
|
||||
if ($short) {
|
||||
$result .= substr($k, 0, 1);
|
||||
} elseif ($diff > 1) {
|
||||
$result .= $k;
|
||||
} else {
|
||||
$result .= substr($k, 0, -1);
|
||||
}
|
||||
|
||||
$interval -= $v * $diff;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return Time::formatInterval($this->uptime, $short);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user