Fixes Icinga for Windows freezing on empty config.json

This commit is contained in:
Lord Hepipud 2025-04-22 12:04:41 +02:00
parent 6169f1170d
commit 98de20725e
3 changed files with 34297 additions and 29 deletions

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Bugfixes
* [#785](https://github.com/Icinga/icinga-powershell-framework/issues/785) Fixes Icinga for Windows freezing during loading in case the `config.json` is empty
* [#787](https://github.com/Icinga/icinga-powershell-framework/pull/787) Fixes the return value in case the `Agent` component could not be installed from `$FALSE` to `null`
* [#796](https://github.com/Icinga/icinga-powershell-framework/issues/796) [#798](https://github.com/Icinga/icinga-powershell-framework/issues/798) Fixes an issue with the new check handling, which did not properly convert values from checks to the correct performance data values and base values in some cases
* [#797](https://github.com/Icinga/icinga-powershell-framework/issues/797) Fixes plugins throwing `UNKNOWN` in case `-TresholdInterval` is used for Metrics over Time, when checks are newly registered and checked, before the first MoT is executed and collected

View file

@ -38,7 +38,10 @@ function Get-FileEncoding()
return $null;
}
$Bytes = Get-Content -Encoding Byte -ReadCount 4 -TotalCount 4 -Path $Path;
$FileStream = [System.IO.File]::OpenRead($Path);
$Bytes = New-Object Byte[] 4;
$FileStream.Read($Bytes, 0, 4) | Out-Null;
$FileStream.Close();
if ($Bytes[0] -eq 0xef -and $Bytes[1] -eq 0xbb -and $Bytes[2] -eq 0xbf) {
return 'UTF8-BOM';
@ -52,8 +55,14 @@ function Get-FileEncoding()
return 'UTF32';
} else {
# Check if the file is ASCII or UTF8 without BOM
$Content = Get-Content -Encoding String -Path $Path;
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($content);
$Content = Get-Content -Encoding String -Path $Path -ErrorAction SilentlyContinue;
# In case the file is empty, we assume it's UTF8
if ([string]::IsNullOrEmpty($Content)) {
return 'UTF8';
}
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($content);
# Check each byte to see if it's outside the ASCII range
foreach ($byte in $Bytes) {