From 8d9760ab779434a74432fbefc5ce505a349747b6 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 10 Oct 2023 13:12:00 +0200 Subject: [PATCH] CheckStatistics#assembleBody(): avoid divisions by 0 A too small check interval can let the last and next check appear to be at the same time due to rounding to milliseconds. Their difference is 0 which shall not be used for division. --- library/Icingadb/Widget/Detail/CheckStatistics.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/Icingadb/Widget/Detail/CheckStatistics.php b/library/Icingadb/Widget/Detail/CheckStatistics.php index 64fef3922..b69b4bdb8 100644 --- a/library/Icingadb/Widget/Detail/CheckStatistics.php +++ b/library/Icingadb/Widget/Detail/CheckStatistics.php @@ -122,6 +122,8 @@ protected function assembleBody(BaseHtmlElement $body) // The only way to detect this, is to measure how old the last update is. $nextCheckTime = null; $leftNow = 0; + } elseif ($nextCheckTime - $lastUpdateTime <= 0) { + $leftNow = 0; } else { $leftNow = 100 * (1 - ($nextCheckTime - time()) / ($nextCheckTime - $lastUpdateTime)); if ($leftNow > 100) { @@ -133,7 +135,7 @@ protected function assembleBody(BaseHtmlElement $body) $styleElement->addFor($progressBar, ['width' => sprintf('%F%%', $leftNow)]); - $leftExecutionEnd = $nextCheckTime !== null ? $durationScale * ( + $leftExecutionEnd = $nextCheckTime !== null && $nextCheckTime - $lastUpdateTime > 0 ? $durationScale * ( 1 - ($nextCheckTime - $executionEndTime) / ($nextCheckTime - $lastUpdateTime) ) : 0;