From 210862e683bd120314a7c213e6f39a8fc00338bf Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Thu, 27 Jan 2022 21:56:19 +0100 Subject: [PATCH] Fixes JEA error on no modules installed and output --- doc/100-General/10-Changelog.md | 1 + lib/core/jea/Get-IcingaJEAConfiguration.psm1 | 7 +++++++ lib/icinga/plugin/Write-IcingaPluginResult.psm1 | 11 ++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index 1a5d6c7..54bfe5a 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -32,6 +32,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#441](https://github.com/Icinga/icinga-powershell-framework/pull/441) Fixes an exception while loading the Framework, caused by a race condition for missing environment variables which are accessed by some plugins before the Framework is loaded properly * [#446](https://github.com/Icinga/icinga-powershell-framework/pull/446) Fixes Icinga for Windows progress preference, which sometimes caused UI glitches * [#449](https://github.com/Icinga/icinga-powershell-framework/pull/449) Fixes unhandled exception while importing modules during `Install-IcingaComponent` process, because of possible missing dependencies +* [#451](https://github.com/Icinga/icinga-powershell-framework/pull/451) Fixes PowerShell being unable to enter JEA context if only the Framework is installed and removes the `|` from plugin output, in case a JEA error is thrown that check commands are not present ### Enhancements diff --git a/lib/core/jea/Get-IcingaJEAConfiguration.psm1 b/lib/core/jea/Get-IcingaJEAConfiguration.psm1 index 49b6f93..d4fae8f 100644 --- a/lib/core/jea/Get-IcingaJEAConfiguration.psm1 +++ b/lib/core/jea/Get-IcingaJEAConfiguration.psm1 @@ -154,6 +154,13 @@ function Get-IcingaJEAConfiguration() -CmdName 'Add-IcingaForWindowsDaemon' ` -CmdType 'Function'; + # Fixes error if only the Icinga PowerShell Framework is installed, which then causes JEA to fail entirely because of this missing Cmdlet + $UsedCmdlets = Get-IcingaCommandDependency ` + -DependencyList $DependencyList ` + -CompiledList $UsedCmdlets ` + -CmdName 'Select-Object' ` + -CmdType 'Cmdlet'; + # Finally loop through all commands again and build our JEA command list $DeserializedFile = Read-IcingaPowerShellModuleFile -FileContent $ModuleContent; [array]$JeaCmds = $DeserializedFile.CommandList + $DeserializedFile.FunctionList; diff --git a/lib/icinga/plugin/Write-IcingaPluginResult.psm1 b/lib/icinga/plugin/Write-IcingaPluginResult.psm1 index ad28792..b0a006b 100644 --- a/lib/icinga/plugin/Write-IcingaPluginResult.psm1 +++ b/lib/icinga/plugin/Write-IcingaPluginResult.psm1 @@ -7,10 +7,15 @@ function Write-IcingaPluginResult() [string]$CheckResult = $PluginOutput; - if ($PluginPerfData -ne 0) { - $CheckResult += "`n`r| "; + if ($PluginPerfData.Count -ne 0) { + [string]$PerfDataContent = ''; foreach ($PerfData in $PluginPerfData) { - $CheckResult += $PerfData; + $PerfDataContent += $PerfData; + } + + if ([string]::IsNullOrEmpty($PerfDataContent) -eq $FALSE) { + $CheckResult += "`n`r| "; + $CheckResult += $PerfDataContent; } }