Telegraf: Autogenerated telegraf.conf uses UCS-2 LE-BOM coding

Created on 18 Oct 2018  路  4Comments  路  Source: influxdata/telegraf

Relevant telegraf.conf:

autogenerated content

System info:

Windows 10 64-bit, x64 based processor

.\telegraf.exe --version shows
Telegraf 1.8.2 (git: HEAD 996a91f2)

Steps to reproduce:

  1. Navigate to folder containing telegraf.exe
  2. execute .\telegraf.exe config > telegraf.conf
  3. execute .\telegraf.exe --config telegraf.conf

Expected behaviour:

No parsing error

Actual behaviour:

2018/10/18 15:32:31 E! Error parsing telegraf.conf, toml: line 1: parse error

Additional info:

Using PowerShell CLI

Opening file in Notepad++ and setting UTF-8 coding resolves the problem, as mentioned in issue #1378.

bug

Most helpful comment

I implemented a workaround by catching the output in a variable and then out-file it with utf8 encoding.

$exe = "C:\Program Files\telegraf\telegraf.exe"
$telegrafConf = &$exe config
$telegrafConf | Out-File -FilePath "C:\Program Files\telegraf\telegraf.conf" -Encoding utf8

All 4 comments

I tried this with MinGW64 (from Git Bash) and in this case the file is set to UTF-8 coding.

Sounds like a PowerShell issue.

Fun facts:
Size of the different files
image

text-compare.com shows a change in line 1, some changes regarding 碌 sign (and spaces in the lines before the inputs.jolokia.metrics) and an additional line at the end.

telegraf.zip

This might occur on other platforms as well if the terminal is set to a different locale, the proper behavior is to output in the encoding of stdout. I'm not sure if Go is handling this conversion or if Powershell did.

Separately it would be a nice touch to expand the file encodings we can read, not just with respect to the config file, but also reading text data formats.

Now I feel less silly reporting my issue. I assumed it is just PS bollocks and that I should have used something else in the first place.

I implemented a workaround by catching the output in a variable and then out-file it with utf8 encoding.

$exe = "C:\Program Files\telegraf\telegraf.exe"
$telegrafConf = &$exe config
$telegrafConf | Out-File -FilePath "C:\Program Files\telegraf\telegraf.conf" -Encoding utf8
Was this page helpful?
0 / 5 - 0 ratings