Score:0

How to properly display accentuated characters in a check_nrpe result based on a Powershell script?

ai flag

I have a custom Powershell script called by Nagios using "check_nrpe". Currently all check results output messages with special characters like 'è', 'é' or 'à' are not displayed properly when the check result is shown on Nagios.

How to allow those to be displayed properly?

Check command

$USER1$/check_nrpe  -H server.tld -c check_foo -a 7 7 7  

Script call on nsclient.ini

[/settings/external scripts/scripts]
check_foo = cmd /c echo X:\scripts_\check-foo.ps1 -arg1 "$ARG1$" -arg2 "$ARG2$" -arg3 "$ARG3$"; exit($lastexitcode) | powershell.exe -command -

Expected result

CRITICAL - Vérification échouée

Actual result

# UTF-8 BOM (GUI)
CRITICAL - Vrification choue

# UTF-8 BOM (CLI)
CRITICAL - V,rification ,choue,

# UTF-8 (GUI)
CRITICAL - VǸrification ǸchoueǸ 

Currently my Powershell script is remotely called with "check_nrpe" from the Linux CentOS 7 monitoring machine and NSClient++ on the target server (Windows 2016 Server). The script itelf is encoded as "UTF-8 BOM".

Archemar avatar
mx flag
have you tried enconding it in `ISO8859-P1` ,
donmelchior avatar
ai flag
@Archemar: Powershell script encoded with ISO8859-1 outputs: CRITICAL - V?rification ?choue?
donmelchior avatar
ai flag
I Also tried to add "encoding = utf8" in [/settings/NRPE/server] section of "nsclient.ini" configuration file for NSClient++ while keeping Powershell script encoding in "UTF-8 NOM": Issue remains.
Score:1
cn flag

disable your nsclient.ini encoding utf8

[/settings/NRPE/server]
;encoding = utf8

in your script use

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

output your result with : (instead of write-output or write-host)

[Console]::WriteLine("ééé")

works for me pick up from here

Score:0
cn flag

better solution disable utf8 encoding in nsclient.ini as above

and modify your wrapping ps1 scripts in nsclient.ini

ps1=cmd /c echo Try {$OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8;scripts\\%SCRIPT% -- %ARGS%; exit($lastexitcode)} Catch {echo $_.Exception.Message; exit 3} | powershell.exe -command -
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.