diff --git a/doc/31-Changelog.md b/doc/31-Changelog.md index bad41ca..f768c6a 100644 --- a/doc/31-Changelog.md +++ b/doc/31-Changelog.md @@ -36,6 +36,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic * [#323](https://github.com/Icinga/icinga-powershell-framework/pull/323) Adds `-RebuildCache` switch to `icinga` command alias and `Invoke-IcingaCommand`, for quicker cache re-creation for developers * [#333](https://github.com/Icinga/icinga-powershell-framework/pull/333) Adds Cmdlet `Test-IcingaForWindowsService` to test the Icinga for Windows service configuration * [#338](https://github.com/Icinga/icinga-powershell-framework/pull/338) Improves various styles, outputs and view for the Icinga for Windows Management Console and fixes some spelling mistakes +* [#342](https://github.com/Icinga/icinga-powershell-framework/pull/342) Adds feature to print commands being executed by the Icinga Management Console with `l` and improves summary visualisation for better readability ## 1.5.2 (2021-07-09) diff --git a/lib/core/icingaagent/installer/Install-IcingaAgentCertificates.psm1 b/lib/core/icingaagent/installer/Install-IcingaAgentCertificates.psm1 index e0347ac..6329908 100644 --- a/lib/core/icingaagent/installer/Install-IcingaAgentCertificates.psm1 +++ b/lib/core/icingaagent/installer/Install-IcingaAgentCertificates.psm1 @@ -88,7 +88,7 @@ function Install-IcingaAgentCertificates() } if ([string]::IsNullOrEmpty($Endpoint) -And [string]::IsNullOrEmpty($CACert)) { - Write-IcingaConsoleWarning 'Your host certificates have been generated successfully. Please either specify an endpoint to connect to or provide the path to a valid ca.crt'; + Write-IcingaConsoleWarning 'Your host certificates were generated successfully. Please either specify an endpoint to connect to or provide the path to a valid ca.crt'; return $FALSE; } diff --git a/lib/core/installer/Install-Icinga.psm1 b/lib/core/installer/Install-Icinga.psm1 index 8cbcb3f..994730e 100644 --- a/lib/core/installer/Install-Icinga.psm1 +++ b/lib/core/installer/Install-Icinga.psm1 @@ -31,6 +31,7 @@ function Install-Icinga() 'DisplayAdvanced' = $FALSE; 'ShowAdvanced' = $FALSE; 'ShowHelp' = $FALSE; + 'ShowCommand' = $FALSE; 'DeleteValues' = $FALSE; 'HeaderPrint' = $FALSE; 'JumpToSummary' = $FALSE; diff --git a/lib/core/installer/menu/installation/general/ConfigurationSummary.psm1 b/lib/core/installer/menu/installation/general/ConfigurationSummary.psm1 index 289d3ef..7baa6f6 100644 --- a/lib/core/installer/menu/installation/general/ConfigurationSummary.psm1 +++ b/lib/core/installer/menu/installation/general/ConfigurationSummary.psm1 @@ -8,8 +8,9 @@ function Show-IcingaForWindowsInstallerConfigurationSummary() [switch]$Advanced = $FALSE ); - [array]$Entries = @(); - [int]$CurrentIndex = 0 + [array]$Entries = @(); + [int]$CurrentIndex = 0 + [int]$MaxEntryLength = (Get-IcingaMaxTextLength -TextArray $global:Icinga.InstallWizard.Config.Keys) - 4; Enable-IcingaForWindowsInstallationHeaderPrint; @@ -59,15 +60,16 @@ function Show-IcingaForWindowsInstallerConfigurationSummary() } $PrintName = $PrintName.Replace('IfW-', ''); + $PrintName = Add-IcingaWhiteSpaceToString -Text $PrintName -Length $MaxEntryLength; if (Test-Numeric ($ConfigEntry.Selection)) { Set-IcingaForWindowsInstallationHeaderSelection -Selection $ConfigEntry.Selection; &$RealCommand; - $Caption = ([string]::Format('{0}: {1}', $PrintName, $global:Icinga.InstallWizard.HeaderPreview)); + $Caption = ([string]::Format('{0}=> {1}', $PrintName, $global:Icinga.InstallWizard.HeaderPreview)); } else { - $Caption = ([string]::Format('{0}: {1}', $PrintName, $EntryValue)); + $Caption = ([string]::Format('{0}=> {1}', $PrintName, $EntryValue)); } $Entries += @{ diff --git a/lib/core/installer/menu/manage/framework/repository/SetIcingaSnapshotRepo.psm1 b/lib/core/installer/menu/manage/framework/repository/SetIcingaSnapshotRepo.psm1 index 542117a..387164e 100644 --- a/lib/core/installer/menu/manage/framework/repository/SetIcingaSnapshotRepo.psm1 +++ b/lib/core/installer/menu/manage/framework/repository/SetIcingaSnapshotRepo.psm1 @@ -23,6 +23,14 @@ function Show-IcingaForWindowsManagementConsoleSetIcingaSnapshotRepositories() @{ 'Command' = 'Show-IcingaForWindowsManagementConsoleManageIcingaRepositories'; 'Help' = 'Sets the current repository for Icinga for Windows as "Icinga Snapshot"'; + 'Action' = @{ + 'Command' = 'Add-IcingaRepository'; + 'Arguments' = @{ + '-Name' = 'Icinga Snapshot'; + '-RemotePath' = '$DefaultValues$'; + '-Force' = $TRUE; + } + } } ) ` -DefaultIndex $DefaultInput ` @@ -35,12 +43,4 @@ function Show-IcingaForWindowsManagementConsoleSetIcingaSnapshotRepositories() -HiddenConfigElement ` -Advanced ` -NoConfigSwap; - - if (Test-IcingaForWindowsManagementConsoleContinue) { - $UserInput = Get-IcingaForWindowsInstallerValuesFromStep -InstallerStep 'Show-IcingaForWindowsManagementConsoleSetIcingaSnapshotRepositories'; - - Add-IcingaRepository -Name 'Icinga Snapshot' -RemotePath $UserInput -Force; - - $global:Icinga.InstallWizard.LastNotice = ([string]::Format('Updated repository "Icinga Snapshot" with URL "{0}"', $UserInput)); - } } diff --git a/lib/core/installer/menu/manage/framework/repository/SetIcingaStableRepo.psm1 b/lib/core/installer/menu/manage/framework/repository/SetIcingaStableRepo.psm1 index 86908ae..d04ed3e 100644 --- a/lib/core/installer/menu/manage/framework/repository/SetIcingaStableRepo.psm1 +++ b/lib/core/installer/menu/manage/framework/repository/SetIcingaStableRepo.psm1 @@ -23,6 +23,14 @@ function Show-IcingaForWindowsManagementConsoleSetIcingaStableRepositories() @{ 'Command' = 'Show-IcingaForWindowsManagementConsoleManageIcingaRepositories'; 'Help' = 'Sets the current repository for Icinga for Windows as "Icinga Stable"'; + 'Action' = @{ + 'Command' = 'Add-IcingaRepository'; + 'Arguments' = @{ + '-Name' = 'Icinga Stable'; + '-RemotePath' = '$DefaultValues$'; + '-Force' = $TRUE; + } + } } ) ` -DefaultIndex $DefaultInput ` @@ -35,12 +43,4 @@ function Show-IcingaForWindowsManagementConsoleSetIcingaStableRepositories() -HiddenConfigElement ` -Advanced ` -NoConfigSwap; - - if (Test-IcingaForWindowsManagementConsoleContinue) { - $UserInput = Get-IcingaForWindowsInstallerValuesFromStep -InstallerStep 'Show-IcingaForWindowsManagementConsoleSetIcingaStableRepositories'; - - Add-IcingaRepository -Name 'Icinga Stable' -RemotePath $UserInput -Force; - - $global:Icinga.InstallWizard.LastNotice = ([string]::Format('Updated repository "Icinga Stable" with URL "{0}"', $UserInput)); - } } diff --git a/lib/core/installer/menu/manage/general/RemoveComponents.psm1 b/lib/core/installer/menu/manage/general/RemoveComponents.psm1 index 748e21f..6924dd2 100644 --- a/lib/core/installer/menu/manage/general/RemoveComponents.psm1 +++ b/lib/core/installer/menu/manage/general/RemoveComponents.psm1 @@ -2,7 +2,7 @@ function Show-IcingaForWindowsMenuRemoveComponents() { [array]$UninstallFeatures = @(); - $AgentInstalled = Get-Service -Name 'icinga2' -ErrorAction SilentlyContinue; + $AgentInstalled = (Get-IcingaAgentInstallation).Installed; $PowerShellServiceInstalled = Get-Service -Name 'icingapowershell' -ErrorAction SilentlyContinue; $IcingaWindowsServiceData = Get-IcingaForWindowsServiceData; $ModuleList = Get-Module 'icinga-powershell-*' -ListAvailable; @@ -11,7 +11,7 @@ function Show-IcingaForWindowsMenuRemoveComponents() 'Caption' = 'Uninstall Icinga Agent'; 'Command' = 'Show-IcingaForWindowsMenuRemoveComponents'; 'Help' = 'Will remove the Icinga Agent from this system. Please note that this option will leave content inside "ProgramData", like certificates, alone' - 'Disabled' = ($null -eq $AgentInstalled); + 'Disabled' = (-Not $AgentInstalled); 'Action' = @{ 'Command' = 'Show-IcingaWindowsManagementConsoleYesNoDialog'; 'Arguments' = @{ diff --git a/lib/core/installer/tools/ShowInstallerMenu.psm1 b/lib/core/installer/tools/ShowInstallerMenu.psm1 index f2b4b34..a03c4d2 100644 --- a/lib/core/installer/tools/ShowInstallerMenu.psm1 +++ b/lib/core/installer/tools/ShowInstallerMenu.psm1 @@ -102,7 +102,12 @@ function Show-IcingaForWindowsInstallerMenu() foreach ($entry in $Entries) { if ([string]::IsNullOrEmpty($entry.Caption) -eq $FALSE) { - $Header = ([string]::Format('[{0}] {1}', $EntryIndex, $entry.Caption)); + [string]$CaptionIndention = ''; + if ($Entries.Count -ge 10 -And $EntryIndex -lt 10) { + $CaptionIndention = ' '; + } + + $Header = ([string]::Format('{0}[{1}] {2}', $CaptionIndention, $EntryIndex, $entry.Caption)); $FontColor = 'Default'; if ((Test-IcingaForWindowsInstallationHeaderPrint) -eq $FALSE) { @@ -123,6 +128,10 @@ function Show-IcingaForWindowsInstallerMenu() Write-IcingaConsolePlain $Header -ForeColor $FontColor; + if ($global:Icinga.InstallWizard.ShowCommand) { + Write-IcingaManagementConsoleCommand -Entry $entry -Values $StoredValues; + } + if ($global:Icinga.InstallWizard.ShowHelp -And ([string]::IsNullOrEmpty($entry.Help)) -eq $FALSE) { Write-IcingaConsolePlain ''; Write-IcingaConsolePlain $entry.Help -ForeColor Magenta; @@ -157,6 +166,10 @@ function Show-IcingaForWindowsInstallerMenu() } if ($AddConfig) { + if ($global:Icinga.InstallWizard.ShowCommand) { + Write-IcingaManagementConsoleCommand -Entry $Entries[0] -Values $StoredValues; + } + if ($global:Icinga.InstallWizard.ShowHelp -And ([string]::IsNullOrEmpty($Entries[0].Help)) -eq $FALSE) { Write-IcingaConsolePlain ''; Write-IcingaConsolePlain $entry.Help -ForeColor Magenta; @@ -181,12 +194,19 @@ function Show-IcingaForWindowsInstallerMenu() } if ($global:Icinga.InstallWizard.ShowHelp -eq $FALSE) { - Write-IcingaConsolePlain ' [h] Help [m] Main' -NoNewLine; + Write-IcingaConsolePlain ' [h] Help' -NoNewLine; } else { Write-IcingaConsolePlain ' [h] Hide Help' -NoNewLine -ForeColor Green; - Write-IcingaConsolePlain ' [m] Main' -NoNewLine; } + if ($global:Icinga.InstallWizard.ShowCommand -eq $FALSE) { + Write-IcingaConsolePlain ' [l] Commands' -NoNewLine; + } else { + Write-IcingaConsolePlain ' [l] Hide Commands' -NoNewLine -ForeColor Green; + } + + Write-IcingaConsolePlain ' [m] Main' -NoNewLine; + if ([string]::IsNullOrEmpty($LastParent) -eq $FALSE -Or $global:Icinga.InstallWizard.LastParent.Count -gt 1) { Write-IcingaConsolePlain ' [p] Previous'; } else { @@ -266,13 +286,15 @@ function Show-IcingaForWindowsInstallerMenu() }; 'h' { $global:Icinga.InstallWizard.ShowHelp = (-Not ($global:Icinga.InstallWizard.ShowHelp)); - return; }; + 'l' { + $global:Icinga.InstallWizard.ShowCommand = (-Not ($global:Icinga.InstallWizard.ShowCommand)); + return; + } 'm' { $global:Icinga.InstallWizard.NextCommand = $null; $global:Icinga.InstallWizard.NextArguments = $null; - return; } 'p' { @@ -281,7 +303,6 @@ function Show-IcingaForWindowsInstallerMenu() $global:Icinga.InstallWizard.NextCommand = $LastParent; $global:Icinga.InstallWizard.NextArguments = $null; - return; } @@ -289,7 +310,6 @@ function Show-IcingaForWindowsInstallerMenu() if ($global:Icinga.InstallWizard.LastParent.Count -eq 0) { $global:Icinga.InstallWizard.NextCommand = $null; $global:Icinga.InstallWizard.NextArguments = $null; - return; } @@ -419,7 +439,8 @@ function Show-IcingaForWindowsInstallerMenu() } # Reset Help View - $global:Icinga.InstallWizard.ShowHelp = $FALSE; + $global:Icinga.InstallWizard.ShowHelp = $FALSE; + $global:Icinga.InstallWizard.ShowCommand = $FALSE; if ($NextMenu -eq 'break') { return; @@ -436,6 +457,21 @@ function Show-IcingaForWindowsInstallerMenu() if ([string]::IsNullOrEmpty($ActionCmd) -eq $FALSE) { if ($null -eq $ActionArgs -Or $ActionArgs.Count -eq 0) { $ActionArgs = @{ }; + } else { + while ($TRUE) { + [bool]$ModifiedAllArgs = $TRUE; + foreach ($entry in $ActionArgs.Keys) { + if ($ActionArgs[$entry].GetType().Name -ne 'Boolean' -And $ActionArgs[$entry] -eq '$DefaultValues$') { + $ActionArgs[$entry] = $StoredValues; + $ModifiedAllArgs = $FALSE; + break; + } + } + + if ($ModifiedAllArgs) { + break; + } + } } & $ActionCmd @ActionArgs | Out-Null; diff --git a/lib/core/installer/tools/Write-IcingaManagementConsoleCommand.psm1 b/lib/core/installer/tools/Write-IcingaManagementConsoleCommand.psm1 new file mode 100644 index 0000000..d26ed91 --- /dev/null +++ b/lib/core/installer/tools/Write-IcingaManagementConsoleCommand.psm1 @@ -0,0 +1,66 @@ +function Write-IcingaManagementConsoleCommand() +{ + param ( + $Entry = $null, + $Values = @() + ); + + if ($null -eq $Entry) { + return; + } + + if ($Entry.Action -And ($Entry.Action.ContainsKey('Command') -Or ($Entry.Action.ContainsKey('Arguments') -And $Entry.Action.Arguments.ContainsKey('-Command')))) { + $PrintArguments = ''; + $PrintCommand = '' + if ($Entry.Action.Arguments.ContainsKey('-CmdArguments')) { + $PrintCommand = $Entry.Action.Arguments['-Command']; + foreach ($cmdArg in $Entry.Action.Arguments['-CmdArguments'].Keys) { + $PrintValue = $Entry.Action.Arguments['-CmdArguments'][$cmdArg]; + [string]$StringArg = ([string]$cmdArg).Replace('-', ''); + if ($PrintValue.GetType().Name -eq 'Boolean') { + if ((Get-Command $PrintCommand).Parameters.$StringArg.ParameterType.Name -eq 'SwitchParameter') { + $PrintValue = ''; + } else { + if ($PrintValue) { + $PrintValue = '$TRUE'; + } else { + $PrintValue = '$FALSE'; + } + } + } elseif ($PrintValue.GetType().Name -eq 'String' -And $PrintValue.Contains(' ')) { + $PrintValue = (ConvertFrom-IcingaArrayToString -Array $PrintValue -AddQuotes); + } + $PrintArguments += ([string]::Format('{0} {1} ', $cmdArg, $PrintValue)); + } + } else { + $PrintCommand = $Entry.Action.Command; + foreach ($cmdArg in $Entry.Action.Arguments.Keys) { + $PrintValue = $Entry.Action.Arguments[$cmdArg]; + [string]$StringArg = ([string]$cmdArg).Replace('-', ''); + if ($PrintValue.GetType().Name -eq 'Boolean') { + if ((Get-Command $PrintCommand).Parameters.$StringArg.ParameterType.Name -eq 'SwitchParameter') { + $PrintValue = ''; + } else { + if ($PrintValue) { + $PrintValue = '$TRUE'; + } else { + $PrintValue = '$FALSE'; + } + } + } elseif ($PrintValue.GetType().Name -eq 'String' -And $PrintValue.Contains(' ')) { + $PrintValue = (ConvertFrom-IcingaArrayToString -Array $PrintValue -AddQuotes); + } + $PrintArguments += ([string]::Format('{0} {1} ', $cmdArg, $PrintValue)); + } + } + + $PrintArguments = $PrintArguments.Replace('$DefaultValues$', ((ConvertFrom-IcingaArrayToString -Array $Values -AddQuotes))); + + while ($PrintArguments[-1] -eq ' ') { + $PrintArguments = $PrintArguments.SubString(0, $PrintArguments.Length - 1); + } + + Write-IcingaConsolePlain ([string]::Format('PS> {0} {1};', $PrintCommand, $PrintArguments)) -ForeColor Magenta; + Write-IcingaConsolePlain ''; + } +} diff --git a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 index 05b14aa..e94df5e 100644 --- a/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 +++ b/lib/core/tools/Get-IcingaCheckCommandConfig.psm1 @@ -27,7 +27,7 @@ .EXAMPLE Get-IcingaCheckCommandConfig -OutDirectory 'C:\Users\icinga\config-exports' - The following commands have been exported: + The following commands were exported: - 'Invoke-IcingaCheckBiosSerial' - 'Invoke-IcingaCheckCPU' - 'Invoke-IcingaCheckProcessCount' @@ -40,7 +40,7 @@ .EXAMPLE Get-IcingaCheckCommandConfig Invoke-IcingaCheckBiosSerial, Invoke-IcingaCheckCPU -OutDirectory 'C:\Users\icinga\config-exports' - The following commands have been exported: + The following commands were exported: - 'Invoke-IcingaCheckBiosSerial' - 'Invoke-IcingaCheckCPU' JSON export created in 'C:\Users\icinga\config-exports\PowerShell_CheckCommands_09-13-2019-10-58-5342.json' @@ -412,7 +412,7 @@ function Get-IcingaCheckCommandConfig() } # Output-Text - Write-IcingaConsoleNotice "The following commands have been exported:" + Write-IcingaConsoleNotice "The following commands were exported:" foreach ($check in $CheckName) { Write-IcingaConsoleNotice "- '$check'"; } diff --git a/lib/wmi/Add-IcingaWmiPermissions.psm1 b/lib/wmi/Add-IcingaWmiPermissions.psm1 index 80d6000..dff4402 100644 --- a/lib/wmi/Add-IcingaWmiPermissions.psm1 +++ b/lib/wmi/Add-IcingaWmiPermissions.psm1 @@ -107,7 +107,7 @@ function Add-IcingaWmiPermissions() return $FALSE; } - Write-IcingaConsoleNotice 'Wmi permissions for Namespace "{0}" and user "{1}" have been set successfully' -Objects $Namespace, $User; + Write-IcingaConsoleNotice 'Wmi permissions for Namespace "{0}" and user "{1}" was set successfully' -Objects $Namespace, $User; return $TRUE; }