Closed LLHogia closed 5 months ago
Windows does not use UTF-8 encoding by default, instead, depending on the version it uses a different encoding format: IBM Code Page 037, IBM Code Page 860, Windows 1253, etc.
On the other hand, Golang’s JSON encoder only accepts UTF-8 valid characters: json package - encoding/json - Go Packages.
Taking into account the detailed bug, the characters åäö have a different encoding in “IBM Code Page 860” and in UTF-8, thus nri-flex (Go) is not able to properly decode them and outputs the unknown symbol. The solution in the product side might be complex as it would require detecting the encoding algorithm used by the running underlying PowerShell and initialize the corresponding decoder into valid UTF-8 characters. Meanwhile, there are a few simpler solutions on the client’s side:
Enable UTF-8 globally in the Windows machine: Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10)
Enable UTF-8 in the spawned PowerShell context, this can be done by running the following command in the shell script:
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8;
// Fixed script
integrations:
- name: nri-flex
interval: 60s
config:
name: FlexSystemSample
apis:
- event type: FlexSystemSample
shell: powershell
commands:
- run: '[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-WmiObject -Class Win32_Service | Where-Object { $_.Name -like "Förarinformation" } | Select Name, State, StartMode | ConvertTo-Json'
Let us know if any of the client’s side solution would work.
The issue will not be fixed.
Description
Flex via PowerShell is not UTF-8 encoded.
I have a PowerShell script which fetches all "our" services. Extracting the EXE file and then getting the file version of each file.
Here is one of our services:
Here is the JSON from my PowerShell script:
Here is the result in New Relic UI:
Expected Behavior
JSON should be UTF-8 encoded before sending to New Relic. I cannot find any way of doing this in the YML file. Result in PowerShell looks good.
Steps to Reproduce
Your Environment
OS: Windows Server 2022 Infrastructure Agent: 1.33.2