mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Fixes error handling on IMC for invalid JSON
This commit is contained in:
parent
f99230eb0e
commit
d88e61d33d
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
|
||||
|
||||
* [#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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
$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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
&$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