Fixes error handling on IMC for invalid JSON

This commit is contained in:
Lord Hepipud 2021-09-24 10:21:44 +02:00
parent f99230eb0e
commit d88e61d33d
3 changed files with 30 additions and 7 deletions

View file

@ -14,6 +14,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Bugfixes
* [#375](https://github.com/Icinga/icinga-powershell-framework/pull/375) Fixes exception on last message printed during `Uninstall-IcingaForWindows`, because the prior used function is no longer present at this point
* [#376](https://github.com/Icinga/icinga-powershell-framework/pull/376) Fixes IMC error handling on invalid JSON for installation command/file
## 1.6.1 (2021-09-15)

View file

@ -50,15 +50,25 @@ function Install-Icinga()
# Use our install command to configure everything
if ([string]::IsNullOrEmpty($InstallCommand) -eq $FALSE) {
Disable-IcingaFrameworkConsoleOutput;
try {
$JsonInstallCmd = ConvertFrom-Json -InputObject $InstallCommand -ErrorAction Stop;
} catch {
Write-IcingaConsoleError 'Failed to deserialize the provided JSON from file or command: {0}' -Objects $_.Exception.Message;
return;
}
# Add our "old" swap internally
$OldConfigSwap = Get-IcingaPowerShellConfig -Path 'Framework.Config.Swap';
Disable-IcingaFrameworkConsoleOutput;
[hashtable]$IcingaConfiguration = Convert-IcingaForwindowsManagementConsoleJSONConfig -Config (ConvertFrom-Json -InputObject $InstallCommand);
[hashtable]$IcingaConfiguration = Convert-IcingaForwindowsManagementConsoleJSONConfig -Config $JsonInstallCmd;
# First run our configuration values
Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
$Success = Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
if ($Success -eq $FALSE) {
return;
}
# In case we use the director, we require to first fetch all basic values from the Self-Service API then
# require to register the host to fet the remaining content
@ -74,7 +84,11 @@ function Install-Icinga()
# Now apply our configuration again to ensure the defaults are overwritten again
# Suite a mess, but we can improve this later
Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
$Success = Invoke-IcingaForWindowsManagementConsoleCustomConfig -IcingaConfiguration $IcingaConfiguration;
if ($Success -eq $FALSE) {
return;
}
Enable-IcingaFrameworkConsoleOutput;

View file

@ -8,7 +8,7 @@ function Invoke-IcingaForWindowsManagementConsoleCustomConfig()
$cmdConfig = $IcingaConfiguration[$cmd];
if ($cmd.Contains(':')) {
continue; # skip for now, as more complicated
continue;
}
$cmdArguments = @{
@ -22,6 +22,14 @@ function Invoke-IcingaForWindowsManagementConsoleCustomConfig()
$cmdArguments.Add('DefaultInput', $cmdConfig.Selection)
}
try {
&$cmd @cmdArguments;
} catch {
Enable-IcingaFrameworkConsoleOutput;
Write-IcingaConsoleError 'Failed to apply installation configuration of command "{0}" and argument list{1}because of the following error: "{2}"' -Objects $cmd, ($cmdArguments | Out-String), $_.Exception.Message;
return $FALSE;
}
}
return $TRUE;
}