mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Merge pull request #238 from Icinga:fix/Exit-IcingaExecutePlugin-throws-exception-for-localized-PerfCounters
Fix: Exit-IcingaExecutePlugin throws exception for localized PerfCounters Encoding for REST-Api check calls was wrong during queue and while reading the result. We will now enfore UTF8 in both ways. Fixes #232
This commit is contained in:
commit
527b3951ba
5 changed files with 41 additions and 4 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 = '*'
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
15
lib/core/tools/ConvertFrom-JsonUTF8.psm1
Normal file
15
lib/core/tools/ConvertFrom-JsonUTF8.psm1
Normal 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);
|
||||
}
|
||||
17
lib/core/tools/ConvertTo-JsonUTF8Bytes.psm1
Normal file
17
lib/core/tools/ConvertTo-JsonUTF8Bytes.psm1
Normal 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;
|
||||
}
|
||||
Loading…
Reference in a new issue