Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem decoding accentuated characters from powershell output in centreon_nsclient_restapi.pl #5414

Open
gehasia opened this issue Jan 27, 2025 · 4 comments

Comments

@gehasia
Copy link

gehasia commented Jan 27, 2025

Hi,

I don't know if it belongs to this codebase or another, as i don't really understand how everything fits in what repo (does the perl serverside module for centreon belongs to here, i don't find it ? centreon_nsclient_restapi.pl --plugin=apps::nsclient::restapi::plugin )...

The problem seems to be a generic one, but i have it with this particular plugin clientside :
apps::microsoft::exchange::local::plugin

The perl script is called with those arguments serverside :
/usr/lib/centreon/plugins//centreon_nsclient_restapi.pl --plugin=apps::nsclient::restapi::plugin --mode=query --hostname='MYIPADDRESS' --port='8443' --proto='https' --legacy-password='MYSECRET' --command=check_centreon_plugins --arg='apps::microsoft::exchange::local::plugin' --arg='queues' --arg=' --warning-status="" --critical-status="not %{status} =~ /Ready|Active/i" --verbose' --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE" --timeout=30

I get this response :
UNKNOWN: Cannot decode json response: malformed UTF-8 character in JSON string, at character offset 2020 (before "\x{fffd}0080\\u009Ap...") at /usr/lib/centreon/plugins//centreon_nsclient_restapi.pl line 162.

Sure, if i check the nsclient plugin from the client side it check the Exchange Queue with the powershell command. Here is the problem, powershell reply with this in my case (my server is in French, so Exchange does some automatic translations...)

Get-Queue | fl
RunspaceId                       : 92b0f10a-cd46-42e8-9ffe-e7df26dc5519
DeliveryType                     : Undefined
NextHopDomain                    : Dépôt
TlsDomain                        :
NextHopConnector                 : 00000000-0000-0000-0000-000000000000
...

As you can see the NextHopDomain is "Dépôt" which contains accentuated characters which are not correctly handled by json_decode in
centreon_nsclient_restapi.pl

As it belongs to the base script centreon_nsclient_restapi.pl, i'm pretty sure that any accentuated characters sended in UTF-8 via json to the perl script will crash the same way, not only exchange plugins.

In general i try to do a PR with the issue as i tend to try to debug fully. But i'm new to this project, i don't really get which script has to handle thie case for the moment, nor i have any knowledge in perl (litteraly 0)...

@omercier
Copy link
Contributor

Hi @gehasia,
The whole chain is :

  • centreon_nsclient_restapi.pl --plugin=apps::nsclient::restapi::plugin is a client program to ask the NSClient++ server to run a command
  • The executed command uses centreon_plugins.exe, which is a binary compilation of all the plugins that may be run on Windows.
  • apps::microsoft::exchange::local::plugin shows where the code that is executed on the Windows server is.

The error you encountered certainly occurred there:

$decoded = JSON::XS->new->decode($stdout);

To get more information, you should run:

centreon_plugins.exe --plugin='apps::microsoft::exchange::local::plugin' --mode='queues' --warning-status="" --critical-status="not %{status} =~ /Ready|Active/i" --verbose --debug

It may help us fix it.

@gehasia
Copy link
Author

gehasia commented Jan 28, 2025

Hi @omercier and thanks for your reply !

Here is the output :

[PS] C:\Program Files\Centreon NSClient++\scripts\centreon>./centreon_plugins.exe --plugin='apps::microsoft::exchange::local::plugin' --mode='queues' --warning-status="" --critical-status="not %{status} =~ /Ready|Active/i" --verbose --debug
UNKNOWN: Cannot decode json response: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "#< CLIXML\n<Objs Ver...") at C:\Users\ADMINI~1.GEC\AppData\Local\Temp\par-61646d696e697374726174657572\cache-3f10fc802e8b3f966a342cbafbec948b4934fb5b\inc\lib/apps/microsoft/exchange/local/mode/queues.pm line 153.

Here is the output of --ps-exec-only

[{"nexthopdomain":"waterheatermeadowsplace.com","is_valid":true,"message_count":1,"delivery_type":1,"identity":"srv-mail/571","status":3,"last_error":"[{LED=451 4.4.395 Target host responded with error. -> 550 Your country is not allowed to connect to this server.};{MSG=};{FQDN=waterheatermeadowsplace.com};{IP=184.168.29.239};{LRT=28/01/2025 17:30:00}]"},{"nexthopdomain":"lightcrestsoftware.org","is_valid":true,"message_count":1,"delivery_type":1,"identity":"srv-mail/1011","status":2,"last_error":""},{"nexthopdomain":"mailbox db temp","is_valid":true,"message_count":0,"delivery_type":13,"identity":"srv-mail/1646","status":2,"last_error":""},{"nexthopdomain":"carlocksmithcibolo.com","is_valid":true,"message_count":1,"delivery_type":1,"identity":"srv-mail/1697","status":3,"last_error":"[{LED=451 4.4.395 Target host responded with error. -> 550 Your country is not allowed to connect to this server.};{MSG=};{FQDN=carlocksmithcibolo.com};{IP=184.168.23.79};{LRT=28/01/2025 17:35:16}]"},{"nexthopdomain":"plumbingrepairuniversitypark.com","is_valid":true,"message_count":1,"delivery_type":1,"identity":"srv-mail/1715","status":3,"last_error":"[{LED=451 4.4.395 Target host responded with error. -> 550 Your country is not allowed to connect to this server.};{MSG=};{FQDN=plumbingrepairuniversitypark.com};{IP=184.168.23.18};{LRT=28/01/2025 17:36:57}]"},{"nexthopdomain":"termoroni.com","is_valid":true,"message_count":4,"delivery_type":1,"identity":"srv-mail/1720","status":2,"last_error":""},{"nexthopdomain":"oooqo.com","is_valid":true,"message_count":2,"delivery_type":1,"identity":"srv-mail/1843","status":2,"last_error":""},{"nexthopdomain":"ieeie.com","is_valid":true,"message_count":1,"delivery_type":1,"identity":"srv-mail/2340","status":2,"last_error":""},{"nexthopdomain":"Dépôt","is_valid":true,"message_count":0,"delivery_type":0,"identity":"srv-mail/Submission","status":2,"last_error":""}]

This is the last item which cause the error :
{"nexthopdomain":"Dépôt","is_valid":true,"message_count":0,"delivery_type":0,"identity":"srv-mail/Submission","status":2,"last_error":""}

Maybe
$decoded = JSON::XS->new->utf8->decode($stdout);
instead of
$decoded = JSON::XS->new->decode($stdout);

for this kind of powershell output ??

@garnier-quentin
Copy link
Contributor

garnier-quentin commented Jan 29, 2025

Be careful. The error UNKNOWN: Cannot decode json response: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "#< CLIXML\n<Objs Ver...") at C:\Users\ADMINI~1.GEC\AppData\Local\Temp\par-61646d696e697374726174657572\cache-3f10fc802e8b3f966a342cbafbec948b4934fb5b\inc\lib/apps/microsoft/exchange/local/mode/queues.pm line 153. comes from the --debug option.

I think you should try to update the /usr/lib/centreon/plugins//centreon_nsclient_restapi.pl file. In the package package apps::nsclient::restapi::mode::query; replaces:

use JSON;
...
eval {
        $decoded = decode_json($options{content});
};

By;

use JSON::XS;
...
eval {
     $decoded = JSON::XS->new->decode($stdout);
}

@gehasia
Copy link
Author

gehasia commented Jan 29, 2025

Ok after changing

use JSON
...
eval {
        $decoded = decode_json($options{content});
};

to

use JSON::XS
...
eval {
        $decoded = JSON::XS->new->decode($options{content});
};

I get

"/usr/lib/centreon/plugins//centreon_nsclient_restapi.pl --plugin=apps::nsclient::restapi::plugin --mode=query --hostname='MYHOSTNAME' --port='8443' --proto='https' --legacy-password='MYSECRET'  --command=check_centreon_plugins --arg='apps::microsoft::exchange::local::plugin' --arg='queues'  --arg='--warning-status="" --critical-status="not %{status} =~ /Ready|Active/i" --verbose'  --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE" --timeout=30
{"header":{"source_id":""},"payload":[{"command":"check_centreon_plugins","lines":[{"message":"CRITICAL: Queue 'waterheatermeadowsplace.com' status: Retry [last error: [{LED=451 4.4.395 Target host responded with error. -> 550 Your  country is not allowed to connect to this server.};{MSG=};{FQDN=waterheatermeadowsplace.com};{IP=184.168.29.239};{LR T=29.01.2025 14:31:55}]] [delivery type: DnsConnectorDelivery] [identity: srv-mail/571] [message count: 1] | 'srv-mail/Submission#queue.length.count'=0;;;0; 'srv-mail/#queue.length.count'=5;;;0;\r\nQueue 'lightcrestsoftware.org' status: Ready [last error: ] [delivery type: DnsConnectorDelivery] [identity: srv-mail/1011] [message count: 1]\r\nQueue 'mailbox db temp' status: Ready [last error: ] [delivery type: SmtpDeliveryToMailbox] [identity: srv-mail/1646] [message count: 0]\r\nQueue 'termoroni.com' status: Ready [last error: ] [delivery type: DnsConnectorDelivery] [identity: srv-mail/1720] [message count: 2]\r\nQueue 'ieeie.com' status: Ready [last error: ] [delivery type: DnsConnectorDelivery] [identity: srv-mail/2340] [message count: 1]\r\nQueue 'waterheatermeadowsplace.com' status: Retry [last error: [{LED=451 4.4.395 Target host responded with error. -> 550 Your country is not allowed to connect to this server.};{MSG=};{FQDN=waterheatermeadowsplace.com};{IP=184.168.29.239};{LRT=29.01.2025 14:31:55}]] [delivery type: DnsConnectorDelivery] [identity: srv-mail/571] [message count: 1]\r\nQueue 'mailbox db 02' status: Ready [last error: ] [delivery type: SmtpDeliveryToMailbox] [identity: srv-mail/896] [message count: 0]\r\nQueue 'D▒\u0080\u009Ap▒\u0080\u009Ct' status: Ready [last error: ] [delivery type: Undefined] [identity: srv-mail/Submission] [message count: 0]"}],  "result":"CRITICAL"}]}CRITICAL: Queue 'waterheatermeadowsplace.com' status: Retry [last error: [{LED=451 4.4.395 Target host responded with error. -> 550 Your country is not allowed to connect to this server.};{MSG=};{FQDN=waterheatermeadowsplace.com};{IP=184.168.29.239};{LRT=29.01.2025 14:31:55}]] [delivery type: DnsConnectorDelivery] [identity: srv-mail/571] [message count: 1] | 'srv-mail/Submission#queue.length.count'=0;;;0; 'srv-mail/#queue.length.count'=5;;;0;
Queue 'lightcrestsoftware.org' status: Ready [last error: ] [delivery type: DnsConnectorDelivery] [identity: srv-mai                                                                                                                                                                    l/1011] [message count: 1]
Queue 'mailbox db temp' status: Ready [last error: ] [delivery type: SmtpDeliveryToMailbox] [identity: srv-mail/1646] [message count: 0]
Queue 'termoroni.com' status: Ready [last error: ] [delivery type: DnsConnectorDelivery] [identity: srv-mail/1720] [                                                                                                                                                                    message count: 2]
Queue 'ieeie.com' status: Ready [last error: ] [delivery type: DnsConnectorDelivery] [identity: srv-mail/2340] [mess                                                                                                                                                                    age count: 1]
Queue 'waterheatermeadowsplace.com' status: Retry [last error: [{LED=451 4.4.395 Target host responded with error. -> 550 Your country is not allowed to connect to this server.};{MSG=};{FQDN=waterheatermeadowsplace.com};{IP=184.168.29.239};{LRT=29.01.2025 14:31:55}]] [delivery type: DnsConnectorDelivery] [identity: srv-mail/571] [message count: 1]
Queue 'mailbox db 02' status: Ready [last error: ] [delivery type: SmtpDeliveryToMailbox] [identity: srv-mail/896] [message count: 0]
Queue 'D‚p“t' status: Ready [last error: ] [delivery type: Undefined] [identity: srv-mail/Submission] [message count : 0]
"

we see that it returned
\r\nQueue 'D▒\u0080\u009Ap▒\u0080\u009Ct'
which was translated to
Queue 'D‚p“t' status: Ready [last error: ]

It seems that nsclient exchange queue plugin still continue to send an incorrectly utf-8 encoded string but the serverside script centreon_nsclient_restapi.pl can handle it normally now but with downside of wrong characters.

That can do it for now, i will try to investigate further later when i will be able to install the toolchain for this and do some test/debug correctly if you can't help 'blindly' anymore. Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants