Page 1 of 2

NRPE Powershell UTF8

Posted: Wed Sep 14, 2016 11:29 am
by whitest
Hello everyone.

I've made Powershell-script to check Active Directory group members. Everything works fine, but I cannot make NRPE (v. 0.4.4.19 2015-12-08 on domain controller) or Powershell (v. 2.0) to accept non-latin (russian) input arguments. So when I run command where persist russian symbols I see the error:

Code: Select all

# ./check_nrpe -H 192.168.111.246 -t 30 -c check_ad_members -a "Администраторы домена" "user1,user2"
CHECK_NRPE: Invalid packet type received from server.

# locale
LANG=ru_RU.utf8
LC_CTYPE="ru_RU.utf8"
LC_NUMERIC="ru_RU.utf8"
LC_TIME="ru_RU.utf8"
LC_COLLATE="ru_RU.utf8"
LC_MONETARY="ru_RU.utf8"
LC_MESSAGES="ru_RU.utf8"
LC_PAPER="ru_RU.utf8"
LC_NAME="ru_RU.utf8"
LC_ADDRESS="ru_RU.utf8"
LC_TELEPHONE="ru_RU.utf8"
LC_MEASUREMENT="ru_RU.utf8"
LC_IDENTIFICATION="ru_RU.utf8"
LC_ALL=
That error showed in Web-interface too.

My powershell script in attachment.
The part of nsclient.ini:

Code: Select all

[/settings/external scripts/scripts]
check_ad_members=cmd /c echo scripts\check_adgroup.ps1 "$ARG1$" -usermembs $ARG2$ | powershell.exe -command -
Notice: Outoput of plugin in russian shows correctly in GUI and Shell as well:

Code: Select all

# ./check_nrpe -H 192.168.111.246 -t 30 -c check_ad_members -a "1C77-Users" "sav,nva"
WARINING: В группе '1C77-Users' обнаружены несовпадения. Лишние аккаунты: 'lera,Olga,Natasha'. Недостающие аккаунты: 'nva'.|
I don't now its issue of NRPE or Powershell. Could somebody advise how to make NRPE submit non-latin symbols to Powershell?

Re: NRPE Powershell UTF8

Posted: Thu Sep 15, 2016 10:01 am
by rkennedy
It looks like something similar was brought up on the NSClient++ boards - http://forums.nsclient.org/t/nsclient-p ... rs/3886/12

Are you able to hard code the encoding in the NSClient++ configuration file as it suggests, and see if that works?

Re: NRPE Powershell UTF8

Posted: Thu Sep 15, 2016 11:19 am
by whitest
Thank you for your response, rkennedy!

I've tried to set the option on the host. See results on screenshots:
BEFORE
Image

This check works correctly only when I make replacement in Powershell-script:

Code: Select all

if ($groupname -eq "Domain Admins") {$groupname = "Администраторы домена"}
Here russian text is showed correctly in Output.

AFTER (here I've specified input argument groupname as needed "Администраторы домена" instead "Domain Admins"):
Image

Now Output is showed Not correctly, BUT check works! =|
May be now I need configure something in Nagios?

Online encoding (https://2cyr.com/decode/?lang=en) detector says it windows-1251 encoded text.
OK: Группа 'Администраторы домена' совпадает с заданным списком:
'Administrator,ykazakevichadm,georgeadm,elicadm'.
Image

Why Windows-1251?...

Re: NRPE Powershell UTF8

Posted: Thu Sep 15, 2016 12:16 pm
by whitest
Update:
I've added redirect of output powershell script into temp file

Code: Select all

	ac C:\TEMP\ans.txt $print_string
Output in Windows-1251 encoding. I don't know how to change it =|
Image

When "encoding = utf8" in ON, I see abracadabra in GUI.
When "encoding = utf8" in OFF, GUI shows correct output.

Re: NRPE Powershell UTF8

Posted: Thu Sep 15, 2016 4:53 pm
by ssax
Please open up the /usr/local/nagios/var/status.dat file, find the service, and see if it's showing properly in there or not.

Thank you

Re: NRPE Powershell UTF8

Posted: Fri Sep 16, 2016 2:14 am
by whitest
ssax wrote:Please open up the /usr/local/nagios/var/status.dat file, find the service, and see if it's showing properly in there or not.

Thank you
Unfortunely it's showing not properly there, when utf8 encoding is enabled in nsclient:

Code: Select all

plugin_output=OK: Группа '1C77-Users' совпадает с заданным списком: 'sav,Olga,Natasha,lera'.

Re: NRPE Powershell UTF8

Posted: Fri Sep 16, 2016 9:07 am
by lmiltchev
At this point, I will need to say that this issue has nothing to do with Nagios. It is a Windows/PS issue. Similar issues have been reported here:
http://docs.notepad-plus-plus.org/index ... er_Display
and here:
https://connect.microsoft.com/PowerShel ... nsole-font

I was able to recreate the problem by selecting "Windows-1251", entering some cyrillic text, then changing the encoding to "UTF-8". The cyrillic characters become unreadable.
example01.PNG
example02.PNG
I also tried running a simple PS script against my test file:

Code: Select all

$text = Get-Content -Path D:\Temp\test.txt
Write-Host "$text"
example03.PNG
example03.PNG (8.28 KiB) Viewed 6236 times
As you can see, this issue has nothing to do with Nagios.

Re: NRPE Powershell UTF8

Posted: Fri Sep 16, 2016 9:26 am
by whitest
I glad to hear you, lmiltchev.

I agree with you. I only confused how "encoding = utf8" changes behavior plugin output?
When utf8 is enabled, then input russian chars processed well by the script, but output is broken.
Wnen utf8 is disabled, then input russian chars not recognized properly, but output of plugin is good.
Mystery... :(

Thank you anyway!

Re: NRPE Powershell UTF8

Posted: Fri Sep 16, 2016 10:45 am
by lmiltchev
Yeah, this is kind of a puzzler. :(

Is it OK if we close this topic as it is clearly not a Nagios issue? Thanks!

Re: NRPE Powershell UTF8

Posted: Fri Sep 16, 2016 10:55 am
by whitest
Close it, of course.
Thanks!