Skip to content

Commit

Permalink
CheckStatistics: avoid divisions by 0 (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg authored Oct 13, 2023
2 parents 17b8065 + d09f3ff commit c1f1d68
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions 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 Expand Up @@ -206,12 +208,7 @@ protected function assembleBody(BaseHtmlElement $body)
$intervalLine = new HtmlElement(
'li',
Attributes::create(['class' => 'interval-line']),
new VerticalKeyValue(
t('Interval'),
$checkInterval
? Format::seconds($checkInterval)
: (new EmptyState(t('n. a.')))->setTag('span')
)
new VerticalKeyValue(t('Interval'), Format::seconds($checkInterval))
);

$styleElement->addFor($intervalLine, [
Expand Down

0 comments on commit c1f1d68

Please sign in to comment.