Adds improvements to IMC including cmd preview

This commit is contained in:
Lord Hepipud 2021-08-19 17:19:26 +02:00
parent 25578d0d50
commit 63be379368
11 changed files with 141 additions and 35 deletions

View file

@ -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)

View file

@ -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;
}

View file

@ -31,6 +31,7 @@ function Install-Icinga()
'DisplayAdvanced' = $FALSE;
'ShowAdvanced' = $FALSE;
'ShowHelp' = $FALSE;
'ShowCommand' = $FALSE;
'DeleteValues' = $FALSE;
'HeaderPrint' = $FALSE;
'JumpToSummary' = $FALSE;

View file

@ -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 += @{

View file

@ -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));
}
}

View file

@ -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));
}
}

View file

@ -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' = @{

View file

@ -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;

View file

@ -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 '';
}
}

View file

@ -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'";
}

View file

@ -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;
}