Skip to content

Commit

Permalink
CheckStatistics: Show retry_interval if object is in `problem && so…
Browse files Browse the repository at this point in the history
…ft_state`
  • Loading branch information
sukhwinder33445 committed May 22, 2023
1 parent 9041a64 commit be93049
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions library/Icingadb/Widget/Detail/CheckStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ protected function assembleBody(BaseHtmlElement $body)

$overdueBar = null;
$nextCheckTime = $this->object->state->next_check;
$checkInterval = $this->getCheckInterval();
if ($this->object->state->is_overdue) {
$nextCheckTime = $this->object->state->next_update;
$leftNow = $durationScale + $hPadding / 2;

$overdueScale = ($durationScale / 2) * (time() - $nextCheckTime) / (10 * $this->object->check_interval);
$overdueScale = ($durationScale / 2) * (time() - $nextCheckTime) / (10 * $checkInterval);
if ($overdueScale > $durationScale / 2) {
$overdueScale = $durationScale / 2;
}
Expand All @@ -59,7 +60,7 @@ protected function assembleBody(BaseHtmlElement $body)
)
]);
} else {
$leftNow = $durationScale * (1 - ($nextCheckTime - time()) / $this->object->check_interval);
$leftNow = $durationScale * (1 - ($nextCheckTime - time()) / $checkInterval);
if ($leftNow > $durationScale) {
$leftNow = $durationScale;
} elseif ($leftNow < 0) {
Expand Down Expand Up @@ -120,13 +121,14 @@ protected function assembleBody(BaseHtmlElement $body)
: t('PENDING'))
)
);

$interval = Html::tag(
'li',
['class' => 'interval'],
new VerticalKeyValue(
t('Interval'),
$this->object->check_interval
? Format::seconds($this->object->check_interval)
$checkInterval
? Format::seconds($checkInterval)
: (new EmptyState(t('n. a.')))->setTag('span')
)
);
Expand Down Expand Up @@ -201,4 +203,30 @@ protected function assembleHeader(BaseHtmlElement $header)
)
]);
}

/**
* Get the active `check_interval` OR `check_retry_interval`
*
* @return int
*/
protected function getCheckInterval(): int
{
if (($this->object->state->is_problem && $this->object->state->state_type === 'soft') === false) {
return $this->object->check_interval;
}

$delay = $this->object->state->execution_time + $this->object->state->latency + 5;
$interval = $this->object->state->next_check - $this->object->state->last_update;

// In case passive check is used, the check_retry_interval has no effect.
// As there is no flag in db to check whether passive check is triggered. We have to check it manually.
if (
$this->object->check_retry_interval - $delay <= $interval
&& $this->object->check_retry_interval + $delay >= $interval
) {
return $this->object->check_retry_interval;
}

return $this->object->check_interval;
}
}

0 comments on commit be93049

Please sign in to comment.