Fix downtime in corner cases (#16040)

If somehow device outage wasn't recorded, fall back to last_polled (or now)
This should not happen in normal operation

fixes #15634
This commit is contained in:
Tony Murray
2024-05-19 09:46:16 -05:00
committed by GitHub
parent 8fdf990dd5
commit 6c6bdf26d0

View File

@@ -279,7 +279,13 @@ class Device extends BaseModel
*/
public function downSince(): Carbon
{
return Carbon::createFromTimestamp((int) $this->getCurrentOutage()?->going_down);
$deviceOutage = $this->getCurrentOutage();
if ($deviceOutage) {
return Carbon::createFromTimestamp((int) $deviceOutage->going_down);
}
return $this->last_polled ?? Carbon::now();
}
/**