Exit-IcingaExecutePlugin throws exception for localized PerfCounters

Fixes #232
This commit is contained in:
Lord Hepipud 2021-05-03 19:10:36 +02:00
parent eb5dd020b5
commit 0b6e2235ed
5 changed files with 41 additions and 4 deletions

View file

@ -21,6 +21,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
### Bugfixes
* [#232](https://github.com/Icinga/icinga-powershell-framework/pull/232) Fixes wrong encoding while using REST-Api checks experimental feature, and now forces UTF8
* [#240](https://github.com/Icinga/icinga-powershell-framework/pull/240) While filtering for certain services with `Get-IcingaServices`, there were some attributes missing from the collection. These are now added resulting in always correct output data.
## 1.4.1 (2021-03-10)

View file

@ -31,7 +31,9 @@
'.\lib\core\tools\Test-IcingaFunction.psm1',
'.\lib\core\tools\Write-IcingaConsoleHeader.psm1',
'.\lib\core\framework\Test-IcingaFrameworkConsoleOutput.psm1',
'.\lib\core\tools\ConvertTo-IcingaSecureString.psm1'
'.\lib\core\tools\ConvertTo-IcingaSecureString.psm1',
'.\lib\core\tools\ConvertTo-JsonUTF8Bytes.psm1',
'.\lib\core\tools\ConvertFrom-JsonUTF8.psm1'
)
FunctionsToExport = @(
'Use-Icinga',
@ -71,7 +73,9 @@
'Test-IcingaFunction',
'Write-IcingaConsoleHeader',
'Test-IcingaFrameworkConsoleOutput',
'ConvertTo-IcingaSecureString'
'ConvertTo-IcingaSecureString',
'ConvertTo-JsonUTF8Bytes',
'ConvertFrom-JsonUTF8'
)
CmdletsToExport = @('*')
VariablesToExport = '*'

View file

@ -86,7 +86,7 @@ function Invoke-IcingaInternalServiceCall()
# Now queue the check inside our REST-Api
try {
$ApiResult = Invoke-WebRequest -Method POST -UseBasicParsing -Uri ([string]::Format('https://localhost:{0}/v1/checker?command={1}', $RestApiPort, $Command)) -Body ($CommandArguments | ConvertTo-Json -Depth 100) -ContentType 'application/json' -TimeoutSec $Timeout;
$ApiResult = Invoke-WebRequest -Method POST -UseBasicParsing -Uri ([string]::Format('https://localhost:{0}/v1/checker?command={1}', $RestApiPort, $Command)) -Body (ConvertTo-JsonUTF8Bytes -InputObject $CommandArguments -Depth 100 -Compress) -ContentType 'application/json' -TimeoutSec $Timeout;
} catch {
# Something went wrong -> fallback to local execution
$ExMsg = $_.Exception.message;
@ -96,7 +96,7 @@ function Invoke-IcingaInternalServiceCall()
}
# Resolve our result from the API
$IcingaResult = ConvertFrom-Json -InputObject $ApiResult;
$IcingaResult = ConvertFrom-JsonUTF8 -InputObject $ApiResult.Content;
$IcingaCR = '';
# In case we didn't receive a check result, fallback to local execution

View file

@ -0,0 +1,15 @@
function ConvertFrom-JsonUTF8()
{
[CmdletBinding()]
param (
[parameter(Mandatory = $TRUE, ValueFromPipeline = $TRUE)]
$InputObject = $null
);
# We need to properly encode our String to UTF8
$ContentBytes = [System.Text.Encoding]::Default.GetBytes($InputObject);
$UTF8String = [System.Text.Encoding]::UTF8.GetString($ContentBytes);
# Return the correct encoded JSON
return (ConvertFrom-Json -InputObject $UTF8String);
}

View file

@ -0,0 +1,17 @@
function ConvertTo-JsonUTF8Bytes()
{
[CmdletBinding()]
param (
[parameter(Mandatory = $TRUE, ValueFromPipeline = $TRUE)]
$InputObject = $null,
[int]$Depth = 10,
[switch]$Compress = $FALSE
);
$JsonBody = ConvertTo-Json -InputObject $InputObject -Depth 100 -Compress;
$UTF8Bytes = ([System.Text.Encoding]::UTF8.GetBytes($JsonBody));
# Do not remove the "," as we require to force our PowerShell to handle our return value
# as proper collection
return , $UTF8Bytes;
}