From 7d59af9a583e147c68c4d84b8b36f5466386732b Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Tue, 20 Jun 2023 11:03:49 +0200 Subject: [PATCH] Fixes Clear-Host throwing exceptions during automation tasks --- doc/100-General/10-Changelog.md | 6 ++---- .../installer/Start-IcingaForWindowsInstallation.psm1 | 2 +- .../installer/menu/manage/shell/StartIcingaShell.psm1 | 2 +- lib/core/installer/tools/Clear-CLIConsole.psm1 | 8 ++++++++ lib/core/installer/tools/ShowInstallerMenu.psm1 | 4 ++-- lib/icinga/plugin/Write-IcingaPluginOutput.psm1 | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 lib/core/installer/tools/Clear-CLIConsole.psm1 diff --git a/doc/100-General/10-Changelog.md b/doc/100-General/10-Changelog.md index b5371b5..4be685d 100644 --- a/doc/100-General/10-Changelog.md +++ b/doc/100-General/10-Changelog.md @@ -20,6 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#615](https://github.com/Icinga/icinga-powershell-framework/issues/615) Fixes the framework migration tasks which fails in case multiple versions of the framework are installed, printing warnings in case there is * [#617](https://github.com/Icinga/icinga-powershell-framework/issues/617) Fixes failing calls for plugins which use a switch argument like `-NoPerfData`, which is followed directly by the `-ThresholdInterval` argument * [#621](https://github.com/Icinga/icinga-powershell-framework/pull/621) Fixes `-ThresholdInterval` key detection on newer systems +* [#634](https://github.com/Icinga/icinga-powershell-framework/pull/634) Fixes an issue with `Clear-Host` which could cause an exception during certain automation tasks, causing it to fail * [#645](https://github.com/Icinga/icinga-powershell-framework/pull/645) Fixes error and exception handling while using API-Checks, which now will in most cases always return a proper check-result object and also abort while running into plugin execution errors, in case a server is not reachable by the time sync plugin for example * [#646](https://github.com/Icinga/icinga-powershell-framework/pull/646) Fixes REST-Api to allow arguments for check execution with and without leading `-` * [#648](https://github.com/Icinga/icinga-powershell-framework/pull/648) Fixes some memory management while using the REST-Api to clear connection objects once they are no longer required @@ -29,6 +30,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#544](https://github.com/Icinga/icinga-powershell-framework/issues/544) Adds support to configure the Icinga Director JSON string for registering hosts via self-service API * [#572](https://github.com/Icinga/icinga-powershell-framework/issues/572) Adds support to write the name of the repository synced/created into the local `ifw.repo.json` file * [#573](https://github.com/Icinga/icinga-powershell-framework/issues/573) Adds support to run command `icinga` with new argument `-NoNewInstance`, to use `-RebuildCache` as example to update the current PowerShell instance with all applied changes +* [#613](https://github.com/Icinga/icinga-powershell-framework/pull/613) Adds a `-Version` parameter to the `Update-Icinga` command, to be able to update a component to a specified version [@log1-c] * [#619](https://github.com/Icinga/icinga-powershell-framework/pull/619) Adds feature to securely read enum provider values with new function `Get-IcingaProviderEnumData` * [#623](https://github.com/Icinga/icinga-powershell-framework/issues/623) Adds support to provide the Icinga service user written as `user@domain` * [#633](https://github.com/Icinga/icinga-powershell-framework/pull/633) Adds support for Icinga 2.14.0 native Icinga for Windows API communication @@ -41,10 +43,6 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#655](https://github.com/Icinga/icinga-powershell-framework/pull/655) Adds [IWKB](https://icinga.com/docs/icinga-for-windows/latest/doc/knowledgebase/IWKB000016/) and test/manage Cmdlets for SCOM intercept counters * [#656](https://github.com/Icinga/icinga-powershell-framework/pull/656) Adds new feature to write document content easier by storing it in memory first and then allowing to write it to disk at once with proper UTF8 encoding -### Enhancements - -* [#613](https://github.com/Icinga/icinga-powershell-framework/pull/613) Adds a `-Version` parameter to the `Update-Icinga` command, to be able to update a component to a specified version [@log1-c] - ## 1.10.1 (2022-12-20) [Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/27?closed=1) diff --git a/lib/core/installer/Start-IcingaForWindowsInstallation.psm1 b/lib/core/installer/Start-IcingaForWindowsInstallation.psm1 index 39f390f..d34126f 100644 --- a/lib/core/installer/Start-IcingaForWindowsInstallation.psm1 +++ b/lib/core/installer/Start-IcingaForWindowsInstallation.psm1 @@ -5,7 +5,7 @@ function Start-IcingaForWindowsInstallation() ); if ($global:Icinga.InstallWizard.DirectorInstallError -eq $FALSE -And (Get-IcingaFrameworkDebugMode) -eq $FALSE) { - Clear-Host; + Clear-CLIConsole; } Write-IcingaConsoleNotice 'Starting Icinga for Windows installation'; diff --git a/lib/core/installer/menu/manage/shell/StartIcingaShell.psm1 b/lib/core/installer/menu/manage/shell/StartIcingaShell.psm1 index d8e6b43..cc6a97f 100644 --- a/lib/core/installer/menu/manage/shell/StartIcingaShell.psm1 +++ b/lib/core/installer/menu/manage/shell/StartIcingaShell.psm1 @@ -1,6 +1,6 @@ function Invoke-IcingaForWindowsMenuStartIcingaShell() { - Clear-Host; + Clear-CLIConsole; $global:Icinga.InstallWizard.Closing = $TRUE; Invoke-IcingaCommand -Shell; } diff --git a/lib/core/installer/tools/Clear-CLIConsole.psm1 b/lib/core/installer/tools/Clear-CLIConsole.psm1 new file mode 100644 index 0000000..cf39f6b --- /dev/null +++ b/lib/core/installer/tools/Clear-CLIConsole.psm1 @@ -0,0 +1,8 @@ +function Clear-CLIConsole() +{ + try { + Clear-Host -ErrorAction Stop; + } catch { + # Nothing to do + } +} diff --git a/lib/core/installer/tools/ShowInstallerMenu.psm1 b/lib/core/installer/tools/ShowInstallerMenu.psm1 index 174baa4..83719ca 100644 --- a/lib/core/installer/tools/ShowInstallerMenu.psm1 +++ b/lib/core/installer/tools/ShowInstallerMenu.psm1 @@ -23,7 +23,7 @@ function Show-IcingaForWindowsInstallerMenu() ); if ($global:Icinga.InstallWizard.DirectorInstallError -eq $FALSE -And (Test-IcingaForWindowsInstallationHeaderPrint) -eq $FALSE -And (Get-IcingaFrameworkDebugMode) -eq $FALSE) { - Clear-Host; + Clear-CLIConsole; } $PSCallStack = Get-PSCallStack; @@ -295,7 +295,7 @@ function Show-IcingaForWindowsInstallerMenu() switch ($Result) { 'x' { - Clear-Host; + Clear-CLIConsole; $global:Icinga.InstallWizard.Closing = $TRUE; return; }; diff --git a/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 b/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 index 97d12f6..2bf6e99 100644 --- a/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 +++ b/lib/icinga/plugin/Write-IcingaPluginOutput.psm1 @@ -6,7 +6,7 @@ function Write-IcingaPluginOutput() if ($Global:Icinga.Protected.RunAsDaemon -eq $FALSE -And $Global:Icinga.Protected.JEAContext -eq $FALSE) { if ($Global:Icinga.Protected.Minimal) { - Clear-Host; + Clear-CLIConsole; } Write-IcingaConsolePlain $Output; } else {