mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge pull request #376 from Icinga:fix/imc_install_json_error_handling
Fix: IMC error handling on invalid JSON for install command/file Fixes error handling for IMC on automated installation with installation command or answer file, which will not abort the installation in case invalid JSON is provided or commands are used inside the command, not valid or exist on the system. The system will write an error message and abort the installation in case of initial errors now.
This commit is contained in:
commit
30ea5370e1
3 changed files with 30 additions and 7 deletions
|
|
@ -14,6 +14,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
||||||
### Bugfixes
|
### 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
|
* [#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)
|
## 1.6.1 (2021-09-15)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,15 +50,25 @@ function Install-Icinga()
|
||||||
# Use our install command to configure everything
|
# Use our install command to configure everything
|
||||||
if ([string]::IsNullOrEmpty($InstallCommand) -eq $FALSE) {
|
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
|
# Add our "old" swap internally
|
||||||
$OldConfigSwap = Get-IcingaPowerShellConfig -Path 'Framework.Config.Swap';
|
$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
|
# 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
|
# 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
|
# 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
|
# Now apply our configuration again to ensure the defaults are overwritten again
|
||||||
# Suite a mess, but we can improve this later
|
# 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;
|
Enable-IcingaFrameworkConsoleOutput;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ function Invoke-IcingaForWindowsManagementConsoleCustomConfig()
|
||||||
$cmdConfig = $IcingaConfiguration[$cmd];
|
$cmdConfig = $IcingaConfiguration[$cmd];
|
||||||
|
|
||||||
if ($cmd.Contains(':')) {
|
if ($cmd.Contains(':')) {
|
||||||
continue; # skip for now, as more complicated
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmdArguments = @{
|
$cmdArguments = @{
|
||||||
|
|
@ -22,6 +22,14 @@ function Invoke-IcingaForWindowsManagementConsoleCustomConfig()
|
||||||
$cmdArguments.Add('DefaultInput', $cmdConfig.Selection)
|
$cmdArguments.Add('DefaultInput', $cmdConfig.Selection)
|
||||||
}
|
}
|
||||||
|
|
||||||
&$cmd @cmdArguments;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue