From 76cd457ff31b32799d6337080582f65a36be1a9e Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Wed, 17 May 2023 14:52:26 +0200 Subject: [PATCH] CheckStatistics: Show `retry_interval` if object is in `problem && soft_state` --- .../Widget/Detail/CheckStatistics.php | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/library/Icingadb/Widget/Detail/CheckStatistics.php b/library/Icingadb/Widget/Detail/CheckStatistics.php index 51bcb638..0a6051f7 100644 --- a/library/Icingadb/Widget/Detail/CheckStatistics.php +++ b/library/Icingadb/Widget/Detail/CheckStatistics.php @@ -40,11 +40,12 @@ class CheckStatistics extends Card $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; } @@ -59,7 +60,7 @@ class CheckStatistics extends Card ) ]); } else { - $leftNow = $durationScale * (1 - ($nextCheckTime - time()) / $this->object->check_interval); + $leftNow = $durationScale * (1 - ($nextCheckTime - time()) / $checkInterval); if ($leftNow > $durationScale) { $leftNow = $durationScale; } elseif ($leftNow < 0) { @@ -125,8 +126,8 @@ class CheckStatistics extends Card ['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') ) ); @@ -201,4 +202,31 @@ class CheckStatistics extends Card ) ]); } + + /** + * 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')) { + 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. + // Since there is no flag in the database to check if the passive check was triggered. + // We have to manually check if the check_retry_interval matches the calculated interval. + 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; + } }