diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index 67f2579..3438bb9 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -7,12 +7,13 @@ documentation before upgrading to a new release. Released closed milestones can be found on [GitHub](https://github.com/Icinga/icinga-powershell-framework/milestones?state=closed). -## 1.4.0 (pending) +## 1.4.0 (2021-03-02) [Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/11?closed=1) ### Enhancements +* [#180](https://github.com/Icinga/icinga-powershell-framework/pull/180) Ensure check data are separated from each thread and not accessible from one thread to another to prevent conflicting results * [#193](https://github.com/Icinga/icinga-powershell-framework/pull/193) Adds optional support for adding milliseconds to `Get-IcingaUnixTime` with the `-Milliseconds` argument for more detailed time comparison * [#198](https://github.com/Icinga/icinga-powershell-framework/pull/198) Adds support to flush the content of the Icinga Agent API directory with a single Cmdlet `Clear-IcingaAgentApiDirectory` * [#203](https://github.com/Icinga/icinga-powershell-framework/pull/203) Removes experimental state of the Icinga PowerShell Framework code caching and adds docs on how to use the feature diff --git a/lib/core/framework/Get-IcingaCheckSchedulerPerfData.psm1 b/lib/core/framework/Get-IcingaCheckSchedulerPerfData.psm1 index a5a4eda..d3e4276 100644 --- a/lib/core/framework/Get-IcingaCheckSchedulerPerfData.psm1 +++ b/lib/core/framework/Get-IcingaCheckSchedulerPerfData.psm1 @@ -17,24 +17,12 @@ function Get-IcingaCheckSchedulerPerfData() { - if ($null -eq $IcingaDaemonData) { + if ($null -eq $global:Icinga) { return $null; } - if ($IcingaDaemonData.ContainsKey('IcingaThreadContent') -eq $FALSE) { - return $null; - } - - if ($IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler') -eq $FALSE) { - return $null; - } - - if ($IcingaDaemonData.IcingaThreadContent.Scheduler.ContainsKey('PluginPerfData') -eq $FALSE) { - return $null; - } - - $PerfData = $IcingaDaemonData.IcingaThreadContent.Scheduler.PluginPerfData; - $IcingaDaemonData.IcingaThreadContent.Scheduler.PluginPerfData = @(); + $PerfData = $global:Icinga.PerfData; + $global:Icinga.PerfData = @(); return $PerfData; } diff --git a/lib/core/framework/Get-IcingaCheckSchedulerPluginOutput.psm1 b/lib/core/framework/Get-IcingaCheckSchedulerPluginOutput.psm1 index 885dabd..5a96bab 100644 --- a/lib/core/framework/Get-IcingaCheckSchedulerPluginOutput.psm1 +++ b/lib/core/framework/Get-IcingaCheckSchedulerPluginOutput.psm1 @@ -17,24 +17,12 @@ function Get-IcingaCheckSchedulerPluginOutput() { - if ($null -eq $IcingaDaemonData) { + if ($null -eq $global:Icinga) { return $null; } - if ($IcingaDaemonData.ContainsKey('IcingaThreadContent') -eq $FALSE) { - return $null; - } - - if ($IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler') -eq $FALSE) { - return $null; - } - - if ($IcingaDaemonData.IcingaThreadContent.Scheduler.ContainsKey('PluginCache') -eq $FALSE) { - return $null; - } - - $CheckResult = [string]::Join("`r`n", $IcingaDaemonData.IcingaThreadContent.Scheduler.PluginCache); - $IcingaDaemonData.IcingaThreadContent.Scheduler.PluginCache = @(); + $CheckResult = [string]::Join("`r`n", $global:Icinga.CheckResults); + $global:Icinga.CheckResults = @(); return $CheckResult; } diff --git a/lib/core/framework/New-IcingaCheckSchedulerEnvironment.psm1 b/lib/core/framework/New-IcingaCheckSchedulerEnvironment.psm1 index bc737ec..5fa7972 100644 --- a/lib/core/framework/New-IcingaCheckSchedulerEnvironment.psm1 +++ b/lib/core/framework/New-IcingaCheckSchedulerEnvironment.psm1 @@ -1,8 +1,12 @@ function New-IcingaCheckSchedulerEnvironment() { + # Legacy code $IcingaDaemonData.IcingaThreadContent.Add('Scheduler', @{ }); - if ($IcingaDaemonData.IcingaThreadContent['Scheduler'].ContainsKey('PluginCache') -eq $FALSE) { - $IcingaDaemonData.IcingaThreadContent['Scheduler'].Add('PluginCache', @()); - $IcingaDaemonData.IcingaThreadContent['Scheduler'].Add('PluginPerfData', @()); + + if ($null -eq $global:Icinga) { + $global:Icinga = @{}; } + + $global:Icinga.Add('CheckResults', @()); + $global:Icinga.Add('PerfData', @()); } diff --git a/lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1 b/lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1 index ecf1f60..b9e821f 100644 --- a/lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1 +++ b/lib/daemons/ServiceCheckDaemon/Start-IcingaServiceCheckDaemon.psm1 @@ -101,6 +101,9 @@ function Start-IcingaServiceCheckTask() try { & $CheckCommand @Arguments | Out-Null; + Get-IcingaCheckSchedulerPerfData | Out-Null; + Get-IcingaCheckSchedulerPluginOutput | Out-Null; + $UnixTime = Get-IcingaUnixTime; foreach ($result in $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'].Keys) { diff --git a/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 b/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 index ab593bc..f45b6a1 100644 --- a/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 +++ b/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 @@ -7,8 +7,7 @@ function Write-IcingaPluginOutput() if ($global:IcingaDaemonData.FrameworkRunningAsDaemon -eq $FALSE) { Write-IcingaConsolePlain $Output; } else { - if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) { - $global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginCache'] += $Output; - } + # New behavior with local thread separated results + $global:Icinga.CheckResults += $Output; } } diff --git a/lib/icinga/plugin/Write-IcingaPluginPerfData.psm1 b/lib/icinga/plugin/Write-IcingaPluginPerfData.psm1 index ddb4a83..10a3b60 100644 --- a/lib/icinga/plugin/Write-IcingaPluginPerfData.psm1 +++ b/lib/icinga/plugin/Write-IcingaPluginPerfData.psm1 @@ -45,9 +45,8 @@ function Get-IcingaPluginPerfDataContent() $cachedresult = (New-IcingaPerformanceDataEntry -PerfDataObject $data -Label $SearchEntry -Value $checkresult.Value); if ($AsObject) { - if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) { - $global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginPerfData'] += $cachedresult; - } + # New behavior with local thread separated results + $global:Icinga.PerfData += $cachedresult; } $PerfDataOutput += $cachedresult; } @@ -56,9 +55,8 @@ function Get-IcingaPluginPerfDataContent() $compiledPerfData = (New-IcingaPerformanceDataEntry $data); if ($AsObject) { - if ($global:IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler')) { - $global:IcingaDaemonData.IcingaThreadContent['Scheduler']['PluginPerfData'] += $compiledPerfData; - } + # New behavior with local thread separated results + $global:Icinga.PerfData += $compiledPerfData; } $PerfDataOutput += $compiledPerfData; }