New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


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

Votes:

0

Your Vote:

Up

Down

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 Behnsen [Paessler Support]



1 Reply

Accepted Answer

Votes:

1

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 15.2.16 or later

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 version 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 have to provide the following information in the script:

  • Your script has to start with the following line:
    [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  • If you use the EXE/Script Advanced sensor that returns XML, you have to additionally add the following line at the beginning of the XML output:
    <?xml version=`"1.0`" encoding=`"UTF-8`" ?> Note the grave accent (`) 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 has to 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: If you use an SSH Script Advanced sensor, you also have to provide a correct XML declaration in the script.


Update PRTG 17.1.29: As of PRTG version 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 will take 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 Jul 15, 2019 4:51:01 AM by  Maike Behnsen [Paessler Support]



Please log in or register to enter your reply.


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.