Skip to content

Commit

Permalink
CheckStatistics#assembleBody(): avoid divisions by 0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Al2Klimov committed Oct 10, 2023
1 parent 701797e commit 8d9760a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/Icingadb/Widget/Detail/CheckStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;

Expand Down

0 comments on commit 8d9760a

Please sign in to comment.