What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

How can I show special characters with EXE/Script sensors?

Votes:

0

The script that my custom EXE sensor runs returns special characters that are encoded. So, for example, some channel names contain diacritics and German umlauts that are not correctly displayed in PRTG.

How can EXE/Script sensors display special characters, for example, in channel names or sensor messages?

custom-script-exe encoding exe-script-advanced-sensor exe-script-sensor exexml prtg special-characters

Created on Jun 3, 2015 4:26:37 PM by  Gerald Schoch [Paessler Support]

Last change on Jul 12, 2019 10:55:21 AM by  Maike Guba [Paessler Support] (2,404) 2 1



1 Reply

Accepted Answer

Votes:

3

This article applies as of PRTG 22

Correct display of special characters in EXE/Script sensors

If you use an EXE/Script sensor or an EXE/Script Advanced sensor and the executed script returns encoded special characters (for example, diacritics), PRTG might not correctly display these characters in the sensor message or in channel names.

As of PRTG 15.2.16, you can explicitly define the encoding in the target script. In previous versions, PRTG tried to determine the encoding merely by chance. This did not work in every case.

You must provide the following information in the script:

  • Your script must start with the following line:
    [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  • If you use the EXE/Script Advanced sensor that returns XML, you must additionally add the following line at the beginning of the XML output:
    <?xml version=`"1.0`" encoding=`"UTF-8`" ?> Note the grave accents (`) in front of the quotation marks encoding the attributes. These are necessary for correct escaping.
  • The text of both the EXE/Script and the EXE/Script Advanced sensor must be returned with the following command at the end of the script:
    [Console]::WriteLine($output)

Defining your script this way ensures the correct display of special characters in PRTG.

Note: VBScript does not seem to be able to encode text in UTF-8. Use PowerShell instead.

Note: For a proper sensor overview, change the encoding of the .ps1 file from UTF-8 to UTF-8-BOM.

Note: If you use an SSH Script Advanced sensor, you must also provide a correct XML declaration in the script.


Update PRTG 17.1.29: As of PRTG 17.1.29, you can use escape sequences for special characters (for example, &#xb0;). Note that this only applies to sensor message and custom units, it does not work with channel names.


Default encoding

If you do not define the encoding in PRTG 15.2.16 or later, PRTG takes the following default encoding:

  • EXE/Script sensors: OEMCP encoding from HLKM\SYSTEM\CurrentControlSet\Control\Nls\CodePage
  • EXE/Script Advanced sensors: UTF-8 for both XML and JSON

Sample structure of a corresponding PowerShell script:

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$output = @"
<?xml version=`"1.0`" encoding=`"UTF-8`" ?>
<prtg>
    <result>
       […]
    </result>
</prtg>
"@

[Console]::WriteLine($output)

Error message The handle is invalid

I get the error message The handle is invalid when I try to run the script.
This happens sometimes for reasons that are yet unknown. To fix the issue, instead of starting the script with the output encoding, use the following command:

# create temporary console
ping localhost -n 1 | Out-Null
# set output encoding
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

Further information about this can be found on Microsoft TechNet Powershell ISE vs [Console]::OutputEncoding.

Created on Jun 3, 2015 4:27:49 PM by  Gerald Schoch [Paessler Support]

Last change on Jun 30, 2023 9:05:04 AM by  Jacqueline Conforti [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.