glpi-project / glpi-inventory-plugin

GLPI Inventory plugin
GNU Affero General Public License v3.0
43 stars 26 forks source link

XML not well formed! #207

Closed TretornESP closed 1 year ago

TretornESP commented 1 year ago

Describe the bug

When i try to upload the inventory generated in autonomous mode (which seems to be correctly generating). I get the error message stated in the title.

To reproduce

glpi-inventory --json > inventory.json
glpi-injector --file inventory.json --url http://glpi/

Expected behavior

This is a base use case. The program should be uploading the inventory to GLPI.

Operating system

Windows

GLPI Agent version

1.4, Nightly build (git version in additional context below)

GLPI version

10.0.2

GLPIInventory plugin

1.0.3

Additional context

This may be related to the fact that my computer is set up with spanish as main language, including non ascii characters like áéíóúñ in several fields.

g-bougard commented 1 year ago

Hi @TretornESP the "XML not well formed!" message is probably related to another problem than encoding. Here you're generating a JSON and the server seems to detect a XML while you inject it. Can you report the full output of:

glpi-injector --file inventory.json --url http://glpi/ --verbose --debug

Can you also try to generate a partial inventory and inject it ? Possibly sharing the generated json, so we can validate on our side. Here is an example:

glpi-inventory --partial bios >partial-inventory.json
TretornESP commented 1 year ago

[edit] im not sure how i closed this, but it was a mistake... sorry.

Hi @g-bougard thank you for answering so fast!

I'm seeing the same issue. No relevant extra informations seems to be provided by the --verboseand --debug flags.

Here is the output of a complete run (some output is changed to a's and 1's for privacy)

.\glpi-inventory.bat --partial bios  > partial.json
PS C:\Program Files\GLPI-Agent> cat .\partial.json
{
   "action": "inventory",
   "content": {
      "bios": {
         "bdate": "2022-05-09",
         "bversion": "2.10.0",
         "mmanufacturer": "Dell Inc.",
         "mmodel": "0828FX",
         "msn": "/1111AA1/AAAAA1111111AA/",
         "skunumber": "0B26",
         "smanufacturer": "Dell Inc.",
         "smodel": "Vostro 15 5510",
         "ssn": "1111AA1"
      },
      "hardware": {
         "chassis_type": "Notebook",
         "memory": 16126,
         "name": "XABIER-IGLESIAS",
         "uuid": "11111111-1111-1111-1111-11111111111",
         "vmsystem": "Physical",
         "winlang": "3082",
         "winowner": "xabier iglesias",
         "winprodid": "11111-11111-111111-11111",
         "winprodkey": "1111-1111-1111-1111-1111",
         "workgroup": "AAAA.AAA"
      },
      "versionclient": "GLPI-Inventory_v1.5-gitd86b85cd"
   },
   "deviceid": "XABIER-IGLESIAS.AAAA.AAA-2022-08-19-15-31-17",
   "itemtype": "Computer",
   "partial": true
}
PS C:\Program Files\GLPI-Agent> .\glpi-injector.bat --file partial.json --url http://glpi.server.com/front/inventory.php --verbose --debug
Loading partial.json...[07D6A1EB] [agentid:ef59809e-7159-1014-9b54-d08144492e9b] ERROR: XML not well formed!
DEBUG: <?xml version="1.0"?>
<REPLY><ERROR>XML not well formed!</ERROR></REPLY>

These elements were not sent:
partial.json
PS C:\Program Files\GLPI-Agent>
g-bougard commented 1 year ago

On my side, it is injected as expected on a test server. I can only guess for now you're URL may be wrong. Can you try without the /front/inventory.php part of the URL ? You should also check of any error in GLPI php-errors.log or in your HTTP daemon server log.

TretornESP commented 1 year ago

Trying with or without the /front/inventory.php yields the same result.

I'm seeing the following in my php-errors.log this may lead into something.

[2022-08-19 15:46:01] glpiphplog.WARNING:   *** PHP User Warning (512): Invalid item "Agent" (1). in /var/www/html/glpi/plugins/glpiinventory/inc/task.class.php at line 833
  Backtrace :
  plugins/glpiinventory/inc/task.class.php:833       trigger_error()
  plugins/glpiinventory/inc/task.class.php:663       PluginGlpiinventoryTask->getAgentsFromActors()
  plugins/glpiinventory/inc/task.class.php:913       PluginGlpiinventoryTask->prepareTaskjobs()
  src/CronTask.php:1018                              PluginGlpiinventoryTask::cronTaskscheduler()
  front/cron.php:84                                  CronTask::launch()

[2022-08-19 15:46:01] glpiphplog.WARNING:   *** PHP User Warning (512): Invalid item "Agent" (.1). in /var/www/html/glpi/plugins/glpiinventory/inc/task.class.php at line 833
  Backtrace :
  plugins/glpiinventory/inc/task.class.php:833       trigger_error()
  plugins/glpiinventory/inc/task.class.php:663       PluginGlpiinventoryTask->getAgentsFromActors()
  plugins/glpiinventory/inc/task.class.php:913       PluginGlpiinventoryTask->prepareTaskjobs()
  src/CronTask.php:1018                              PluginGlpiinventoryTask::cronTaskscheduler()
  front/cron.php:84                                  CronTask::launch()

[2022-08-19 15:46:01] glpiphplog.WARNING:   *** PHP User Warning (512): Invalid item "Agent" (.2). in /var/www/html/glpi/plugins/glpiinventory/inc/task.class.php at line 833
  Backtrace :
  plugins/glpiinventory/inc/task.class.php:833       trigger_error()
  plugins/glpiinventory/inc/task.class.php:663       PluginGlpiinventoryTask->getAgentsFromActors()
  plugins/glpiinventory/inc/task.class.php:913       PluginGlpiinventoryTask->prepareTaskjobs()
  src/CronTask.php:1018                              PluginGlpiinventoryTask::cronTaskscheduler()
  front/cron.php:84                                  CronTask::launch()

[2022-08-19 15:46:15] glpiphplog.WARNING:   *** PHP User Warning (512): Start tag expected, '<' not found
 in  at line 1
  Backtrace :
  src/Agent/Communication/AbstractRequest.php:235    Glpi\Agent\Communication\AbstractRequest->handleXMLRequest()
  front/inventory.php:86                             Glpi\Agent\Communication\AbstractRequest->handleRequest()
  index.php:94
g-bougard commented 1 year ago

The right URL for you should be http://glpi.server.com/plugins/glpiinventory/.

I see now you're running the agent from a PS console... Don't do that Carl ! PS is converting your json in UTF-16LE... and we only expect UTF-8 content on server-side. There's probably a way to request UTF-8 output in PS, but I'm not aware of it.

To fix your issue, just run from an administrative CMD console.

TretornESP commented 1 year ago

Running from an old regular terminal fixed the issue. Thanks!!

g-bougard commented 1 year ago

The problem is really how PS handle the output of commands. If you run .\glpi-agent.bat --local=. --json you'll obtain UTF-8 well formed inventory in the current folder, even from a PS console.