centreon / centreon-plugins

Collection of standard plugins to discover and gather cloud-to-edge metrics and status across your whole IT infrastructure.
https://www.centreon.com
Apache License 2.0
310 stars 274 forks source link

apps-nsclient-restapi problem "Cannot decode json response: malformed UTF-8 character in JSON string" #4034

Open rmorandell-pgum opened 1 year ago

rmorandell-pgum commented 1 year ago

Hi,

We often have the problem that strings with italian accents do not go over the nsclient restapi plugin.

E.g. we had now the problem that with the veeam job status or veeam list job the following names with accent trigger the problem

"Sanità"

image

We get the error:

UNKNOWN: Cannot decode json response: malformed UTF-8 character in JSON string, at character offset 3010 (before "\x{fffd}u0082\x{fffd}...") at /tmp/centreon-plugins-20221017/apps/nsclient/restapi/mode/query.pm line 154.

Same error when i'm trying to exec a PS command directly

/tmp/centreon-plugins-20221017/centreon_plugins.pl --plugin=apps::nsclient::restapi::plugin --timeout=120 --hostname=xxx --port=8443 --proto=https --insecure --legacy-password=xxx --mode=query --command=apps-backup-veeam-local-list-jobs --arg='--command="PowerShell.exe -NoLogo -Command \"& {Get-VBRJob}\"" --no-ps --ps-exec-only'

image

The only workaround is to rename in this case the jobs. But this is only a temporary solution since the next user will insert an name with an accent.

Thanks for help

garnier-quentin commented 1 year ago

Could you provide the json output ?

rmorandell-pgum commented 1 year ago

Hi Quentin,

The problem was fixed by simply renaming the jobs.

But the problem can be rerproduced. You can simply rename your drive description in Windows and run a list-storages via the agent

"Windows Sanità"

image

sudo -u centreon-engine /tmp/centreon-plugins-dev/centreon_plugins.pl --plugin=apps::nsclient::restapi::plugin --timeout=30 --hostname=10.10.101.6 --port=8443 --proto=https --insecure --legacy-password=***--mode=query --command=os-windows-local-list-storages

<?xml version="1.0" encoding="utf-8"?>
<plugin>
  <name>os::windows::local::plugin</name>
  <mode>list-storages</mode>
  <exit>unknown</exit>
  <outputs>
    <output>
      <type>1</type>
      <exit>UNKNOWN</exit>
      <msg>UNKNOWN: Cannot decode json response: malformed UTF-8 character in JSON string, at character offset 90 (before "\x{fffd}","size":"51...") at C:\WINDOWS\TEMP\par-524d2d5448494e4b50414424\cache-ae9ca07a8429128ffe89a31e47d2f245ee88dd00\inc\lib/os/windows/local/mode/liststorages.pm line 99.</msg>
    </output>
  </outputs>
  <perfdatas/>
</plugin>

The 'à' is a UTF-8 char

https://www.utf8-chartable.de/

image

Any idea ?

garnier-quentin commented 1 year ago

Could you provide output with --ps-exec-only ?

rmorandell-pgum commented 1 year ago

same ...

sudo -u centreon-engine /usr/lib/i-vertix/plugins/apps-nsclient-restapi.pl --plugin=apps::nsclient::restapi::plugin --timeout=30 --hostname=10.10.101.6 --port=8443 --proto=https --insecure --legacy-password=*** --mode=query --command=os-windows-local-list-storages --arg='--ps-exec-only'

UNKNOWN: Cannot decode json response: malformed UTF-8 character in JSON string, at character offset 208 (before "\x{fffd}0080\x{fffd}...") at /usr/lib/i-vertix/plugins/apps-nsclient-restapi.pl line 162.

using a normal name like wihout the 'à'

[{"name":"C:","freespace":"78183096320","providername":null,"type":3,"desc":"Windows","size":"510770802688"}]

rmorandell-pgum commented 1 year ago

Ok when i'm doing a --ps-display and run the ps script in the Powershell ISE the result is correct ..

[{"name":"C:","freespace":"78177816576","providername":null,"type":3,"desc":"Win dows Sanità","size":"510770802688"}]

lucie-dubrunfaut commented 3 months ago

Hello :)

This issue seems particularly old and I'm not sure to understand if it had been solved by Quentin's proposition? Also I need to check if recent works around this kind of characters affect this issue. Can you tell us if you still having problem with this currently? Thank you for your understanding.