NRPE Powershell UTF8

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
whitest
Posts: 107
Joined: Tue Dec 30, 2014 8:16 am

NRPE Powershell UTF8

Post 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?
Attachments
check_adgroup.ps1.txt
(2.16 KiB) Downloaded 480 times
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: NRPE Powershell UTF8

Post 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?
Former Nagios Employee
whitest
Posts: 107
Joined: Tue Dec 30, 2014 8:16 am

Re: NRPE Powershell UTF8

Post 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?...
whitest
Posts: 107
Joined: Tue Dec 30, 2014 8:16 am

Re: NRPE Powershell UTF8

Post 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.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: NRPE Powershell UTF8

Post 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
whitest
Posts: 107
Joined: Tue Dec 30, 2014 8:16 am

Re: NRPE Powershell UTF8

Post 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'.
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: NRPE Powershell UTF8

Post 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 6242 times
As you can see, this issue has nothing to do with Nagios.
Be sure to check out our Knowledgebase for helpful articles and solutions!
whitest
Posts: 107
Joined: Tue Dec 30, 2014 8:16 am

Re: NRPE Powershell UTF8

Post 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!
User avatar
lmiltchev
Former Nagios Staff
Posts: 13587
Joined: Mon May 23, 2011 12:15 pm

Re: NRPE Powershell UTF8

Post 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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
whitest
Posts: 107
Joined: Tue Dec 30, 2014 8:16 am

Re: NRPE Powershell UTF8

Post by whitest »

Close it, of course.
Thanks!
Locked