glpi-project / glpi

GLPI is a Free Asset and IT Management Software package, Data center management, ITIL Service Desk, licenses tracking and software auditing.
https://glpi-project.org
GNU General Public License v3.0
4.23k stars 1.29k forks source link

V10 RC3 : inventory Import JSON file #11183

Closed EC2311 closed 2 years ago

EC2311 commented 2 years ago

Code of Conduct

Is there an existing issue for this?

Version

V10 RC3

Bug description

Hello when importing a json file (issue from GLPI agent on phone)

image

Json not valid, but it contains 'content' data...

Relevant log output

No response

Page URL

No response

Steps To reproduce

No response

Your GLPI setup information

No response

Anything else?

No response

trasher commented 2 years ago

Please provide json and xml file. I wonder if the json provided from agent is correct.

EC2311 commented 2 years ago

here are json and xml files generated on phone (glpi agent) Inventory.zip

stonebuzz commented 2 years ago

Hi @EC2311 Do you get the same error when it's the agent that sends the XML to GLPI ?

EC2311 commented 2 years ago

when it's XML : image

stonebuzz commented 2 years ago

And when it's the agent that sends the XML inventory ?

EC2311 commented 2 years ago

It's the report from my phone, and I can't connect it to the WIFI of my GLPI server. That's why I use the 'import' option...

trasher commented 2 years ago

OK, problem is the data provided are all incorrect. First; there are HTML entities in the XML file, It's required to convert them to regular characters in order to import the file. Also, there is an unknown status value of dormant on a network port (I've replaced with valid down). The JSON file is also incorrect, the request level should not be present.

If I fix the XML and then use GLPI to convert it to JSON, the result is ok.

This may be an agent issue, we will investigate.

EC2311 commented 2 years ago

for information, it's the glpi agent from playstore 1.1.0 build 39329

stonebuzz commented 2 years ago

Hi @EC2311 , after test

inventory send by agetnthe Agent works fine

image

If I get the XML file generated by the agent (in the Download folder) is well formatted

image

compared to your file

image

where <![CDATA]]> are encoded to &lt;![CDATA]]&gt;

how do you get the XML file generated by the agent?

Best regards

EC2311 commented 2 years ago

Hello

I shared it from my phone using bluetooth and Outlook

I checked in the download folder (with a file USB connected on the phone)

If i open using Edge : image If I open using Notepad+ image

How do you 'open' your file in the download folder ?

stonebuzz commented 2 years ago

Downloaded like you (with USB cable) and from VSCode / AndroidStudio / bluetooth

Original file have a good encoding each time.

Have you update inventory.xml file with NotePad++ when you send it here ?

EC2311 commented 2 years ago

Phone connected with USB -> using Explorer on my PC -> I go to download file on the phone Have a look on the screen I see below image

stonebuzz commented 2 years ago

I don't know if Explorer decode file before display it. Can you send inventory.xml (not altered)

Best regards

EC2311 commented 2 years ago

here is the original xml document generated by the phone Inventory.zip Best regards

stonebuzz commented 2 years ago

The format is good

image

You can use this file to manually import device into GLPI

EC2311 commented 2 years ago

either on Chrome or Edge image

I put a debug in conf.php (which seems to be the script which prompt message) image

the var.txt file is well filled with the content of my initial file So I guess about the handles of the inventory_request...

stonebuzz commented 2 years ago

No problem on my side image

Can you use latest GLPI nightly build

Here -> https://nightly.glpi-project.org/glpi/

image

EC2311 commented 2 years ago

I just uploaded the last version, : same error :(

to confirm :

I compare with a xml file issued from Fusion inventory (xml) I have no cdata in it. I try to upload it : I have a strange error in php log : JSON does not validate "---" does not match to .... inventory.php line 227

why json although I upload xml ?

stonebuzz commented 2 years ago

Because XML file is converted as JSON from GLPI native inventory to validate data and format with this https://github.com/glpi-project/inventory_format/blob/master/inventory.schema.json

A CDATA section is "a section of element content that is marked for the parser to interpret as only character data, not markup."

The problem here is that the <![CDATA[ ]]> is converted to &lt;![CDATA[]]&gt; between the moment you retrieve the file from the phone (where fiel encoding is fine) and the moment you import the file into GLPI

Did you update (with notepad++ ) file before import ?

EC2311 commented 2 years ago

Hello

I rerun at the moment a new inventory on my phone. I transfer the file (xml) with bluetooth to my computer I upload it without updating it

always Same error.

Can we imagine a problem with php version ? I use 7.4.9 version. and you ?

stonebuzz commented 2 years ago

PHP 7.4.3 but I don't think the problem is PHP

can you test by using the Agent to send XML inventory to GLPI (and not share and manually import) ?

stonebuzz commented 2 years ago

Where GLPI is hosted ? Linux, IIS, Windows ?

Are you using apache2 / Nginx other ?

EC2311 commented 2 years ago

I can't connect my phone to the wifi network :( I cant' share the connection of my Pc computer (forbidden by admin) : that's why I used the bluetooth (or mail from phone to computer)

I use Windows 10 and a wamp installation with apache

One more information : As i Have 9.5.5 glpi with fusioninveotyr : There is a option to load the xml file here is the result of the import (no error when importing, but strange result) image

EC2311 commented 2 years ago

Pour info : j'ai supprimé tous les lt; les gt; ainsi que les !Cdata[ et ]] l'import (hormis le status dormant -> up) passe et fonctionne.

je peux comprendre que le cdata peut faire partie du xml, mais en l'occurence l'import manuel ne le permet pas àl'heure actuelle

et le telehpone est importé dans ...ordinateur... :( je me suis dit : je vais creer le modele coté téléphone, et refaire l'import (apres avoir supprimé ordi) et non -> l'import ne vérifie pas que le modele existe dans telephone et 'limporte à nouveau dans ordi

stonebuzz commented 2 years ago

Pour information la prochaine version de l'agent inclura une option permettant de choisir la destination Computer ou Phone

Cette nouvelle option n'est valable que pour l'inventaire natif de GLPI (FusionInventory ne gère pas ce noeud)

Vous pouvez tester en ajoutant le noeud suivant dans le fichier XML

<ITEMTYPE>Phone</ITEMTYPE>

juste après la balise <REQUEST> en haut du fichier XML.

Concernant le CDATA ne reproduisant pas localement (même sur nos tests interne) il est difficile pour moi de comprendre ce qu'il se passe.

Bien cordialement

EC2311 commented 2 years ago

En effet, itemtype : c'est ok : le telephone est bien créé correctement.

dommage pour xml et l'import json egalement n'est pas ok (propriété requise manquante... + erreur avec deviceid (abstractrequest.php)

stonebuzz commented 2 years ago

La priorité manquante à déjà fait l'objet d'un fix ici https://github.com/glpi-project/inventory_format/pull/69

Il sera intégrer prochainement dans GLPI

EC2311 commented 2 years ago

ok pour "dormant"

mais pour image

image

trasher commented 2 years ago

Could you please use english?

EC2311 commented 2 years ago

Sorry in summury when removing cdata, lt; and gt; from the initial xml file -> ok to import (as computer, but as said by stonebuzz, the itemtype could be use in the file to split in the right item : ok

but I have still problem if I import using json (it's the screen shots of my last message) thanks

stonebuzz commented 2 years ago

Please only use the XML (agent work with it)

stonebuzz commented 2 years ago

Hi @EC2311 can you try with this version (futur latest of android-inventory-agent)

android-inventory-agent.tar.gz

This version remove all CDATA from XML file

Reminder: only work with the XML file on GLPI !

You need to update your GLPI to the latest nightly build tomorrow

or apply manually apply this fix -> https://github.com/glpi-project/glpi/pull/11212

EC2311 commented 2 years ago

Hello

I removed the previous version of android I installed the new one I run it on the phone I transfered the filte using bluetooth to the computer

1- i remark the itemtype line but it contains 'computer' rather 'phone' -> i Updated it to upload as phone 2- when uploading : an error linked to camera image

But I didn't update GLPI with the last version. 3- I updated GLPI : it's ok no error with camera

so : Very good ! (unless the itemtype ;) ) Thanks

EC2311 commented 2 years ago

perhaps still a mismatch in the volumes (drives) image -> no name on the volumes (drives) ? (empty in the xml file) image

trasher commented 2 years ago

Seems this is now fixed, I close this one.