From 38461f755a455b56e1b627d7526eddcbbfb89cd7 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Tue, 22 Apr 2025 11:34:04 +0200 Subject: [PATCH] Fixes UNKNOWN on checks using MoT thresholds if they are newly registered --- doc/100-General/10-Changelog.md | 1 + .../task/Add-IcingaServiceCheckTask.psm1 | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 6a8ce2ee..a0578c6a 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#787](https://github.com/Icinga/icinga-powershell-framework/pull/787) Fixes the return value in case the `Agent` component could not be installed from `$FALSE` to `null` * [#796](https://github.com/Icinga/icinga-powershell-framework/issues/796) [#798](https://github.com/Icinga/icinga-powershell-framework/issues/798) Fixes an issue with the new check handling, which did not properly convert values from checks to the correct performance data values and base values in some cases +* [#797](https://github.com/Icinga/icinga-powershell-framework/issues/797) Fixes plugins throwing `UNKNOWN` in case `-TresholdInterval` is used for Metrics over Time, when checks are newly registered and checked, before the first MoT is executed and collected ## 1.13.3 (tbd) diff --git a/lib/daemons/ServiceCheckDaemon/task/Add-IcingaServiceCheckTask.psm1 b/lib/daemons/ServiceCheckDaemon/task/Add-IcingaServiceCheckTask.psm1 index 4546a4ae..e29faf02 100644 --- a/lib/daemons/ServiceCheckDaemon/task/Add-IcingaServiceCheckTask.psm1 +++ b/lib/daemons/ServiceCheckDaemon/task/Add-IcingaServiceCheckTask.psm1 @@ -21,19 +21,27 @@ function Add-IcingaServiceCheckTask() [int]$CheckInterval = ConvertTo-Seconds $Interval; [hashtable]$CheckDataCache = @{ }; [array]$PerfDataEntries = @(); + [bool]$ForceExecution = $FALSE; if (Test-Path -Path $MetricCacheFile) { $CheckDataCache = [System.Management.Automation.PSSerializer]::Deserialize((Get-Content -Path $MetricCacheFile -Raw -Encoding UTF8)); } + # In case we run this code for the first time for a CheckCommand and no data is available, ensure we run the check immediately + # This will ensure our plugins will always return proper values and not throw unknowns, in case the execution is set to a higher interval + if ($null -eq $CheckDataCache -Or $CheckDataCache.Count -eq 0) { + $ForceExecution = $TRUE; + } + while ($TRUE) { - if ($Global:Icinga.Private.Daemons.ServiceCheck.PassedTime -lt $CheckInterval) { + if ($ForceExecution -eq $FALSE -And $Global:Icinga.Private.Daemons.ServiceCheck.PassedTime -lt $CheckInterval) { $Global:Icinga.Private.Daemons.ServiceCheck.PassedTime += 1; Start-Sleep -Seconds 1; continue; } + $ForceExecution = $FALSE; $Global:Icinga.Private.Daemons.ServiceCheck.PassedTime = 0; # Clear possible previous performance data from the daemon cache