NRPE Powershell UTF8

This forum is intended for the discussion of Nagios plugin development. Feature requests, patches, bug fixes, and all types of development-related discussions are welcome!

NOTE: The SourceForge.net nagiosplug-devel mailing list has been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

NRPE Powershell UTF8

Postby whitest » Wed Sep 14, 2016 11:29 am

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

Re: NRPE Powershell UTF8

Postby rkennedy » Thu Sep 15, 2016 10:01 am

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?
rkennedy
 
Posts: 6545
Joined: Mon Oct 05, 2015 11:45 am

Re: NRPE Powershell UTF8

Postby whitest » Thu Sep 15, 2016 11:19 am

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: 104
Joined: Tue Dec 30, 2014 8:16 am

Re: NRPE Powershell UTF8

Postby whitest » Thu Sep 15, 2016 12:16 pm

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

Re: NRPE Powershell UTF8

Postby ssax » Thu Sep 15, 2016 4:53 pm

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
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
ssax
Dreams In Code
 
Posts: 2814
Joined: Wed Feb 11, 2015 12:54 pm

Re: NRPE Powershell UTF8

Postby whitest » Fri Sep 16, 2016 2:14 am

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

Re: NRPE Powershell UTF8

Postby lmiltchev » Fri Sep 16, 2016 9:07 am

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.php/Encodings_And_Character_Display
and here:
https://connect.microsoft.com/PowerShell/feedback/details/525324/support-a-bigger-subset-of-unicode-in-the-console-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 314 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!
User avatar
lmiltchev
QA Manager
 
Posts: 9069
Joined: Mon May 23, 2011 12:15 pm

Re: NRPE Powershell UTF8

Postby whitest » Fri Sep 16, 2016 9:26 am

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

Re: NRPE Powershell UTF8

Postby lmiltchev » Fri Sep 16, 2016 10:45 am

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!
User avatar
lmiltchev
QA Manager
 
Posts: 9069
Joined: Mon May 23, 2011 12:15 pm

Re: NRPE Powershell UTF8

Postby whitest » Fri Sep 16, 2016 10:55 am

Close it, of course.
Thanks!
whitest
 
Posts: 104
Joined: Tue Dec 30, 2014 8:16 am

Next

Return to Nagios Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests