0

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".

donmelchior
  • 103
  • 5
  • have you tried enconding it in `ISO8859-P1` , – Archemar Oct 22 '21 at 14:57
  • @Archemar: Powershell script encoded with ISO8859-1 outputs: CRITICAL - V?rification ?choue? – donmelchior Oct 28 '21 at 13:22
  • 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. – donmelchior Oct 29 '21 at 14:05

2 Answers2

1

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

samfuzz
  • 26
  • 1
0

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 -
samfuzz
  • 26
  • 1