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.17k stars 1.28k forks source link

Temporary files not removed from `files/_inventories` #10356

Closed g-bougard closed 2 years ago

g-bougard commented 2 years ago

Code of Conduct

Is there an existing issue for this?

Version

10-beta

Bug description

I found 2 cases where a file is kept in files/_inventories but it shouldn't be.

  1. First case is when a json is not respecting JSON inventory spec.
  2. The second case is related to netdiscovery and netinventory tasks support with GlpiInventory plugin. These tasks are generating state message for the plugin that are finally kept in temporary file.

Relevant log output

No response

Page URL

No response

Steps To reproduce

  1. For the first case, here is sample you can try to inject in server with glpi-injector even if no related asset is known:

    {
    "action": "inventory",
    "content": {
      "bios": {
         "bmanufacturer": "Apple Inc.",
         "bversion": "IM112.88Z.0057.B00.1005031455",
         "mmanufacturer": "Apple Inc.",
         "mmodel": "Mac-F2238AC8",
         "msn": "C020XXXXXXXXCJN1M",
         "smanufacturer": "Apple Inc.",
         "smodel": "iMac11,2",
         "ssn": "WXXXXMWXXXX"
      },
      "hardware": {
         "chassis_type": "All in One",
         "dns": "127.0.0.53",
         "name": "xxxx",
         "uuid": "ba56962a-xxxx-xxxx-xxxx-a58fb09d46cb",
         "vmsystem": "Physical"
      },
      "remote_mgmt": [
         {
            "id": 1043952882,
            "type": "teamviewer"
         }
      ],
      "versionclient": "GLPI-Inventory_v1.0-1"
    },
    "deviceid": "xxxxxxxx-2022-01-18-09-03-56",
    "itemtype": "Computer",
    "partial": true
    }

    This file was generated by a still fixed bug in GLPI-Agent 1.0. But the problem is a temporary file with that content will remain in files/_inventories.

  2. For the second case, netdiscovery and netinventory tasks generates job state messages for the plugin like the following:

    <?xml version="1.0" encoding="UTF-8" ?>
    <REQUEST>
    <CONTENT>
    <AGENT>
      <START>1</START>
    </AGENT>
    <MODULEVERSION>4.4</MODULEVERSION>
    <PROCESSNUMBER>500</PROCESSNUMBER>
    </CONTENT>
    <DEVICEID>xxxxxxxx-2021-11-30-09-57-34</DEVICEID>
    <QUERY>NETDISCOVERY</QUERY>
    </REQUEST>

    This looks like an inventory and so is converted generating a temporary file in files/_inventories. As this is not an inventory file, it is finally not removed from that folder. To reproduce the case, you need GlpiInventory plugin and run a netdiscovery or netinventory task. This can be done with FusionInventory agent.

Your GLPI setup information

No response

Anything else?

No response

trasher commented 2 years ago

A crontask to clean temporary file already exists

g-bougard commented 2 years ago

Hi @trasher imho, just enabling the "cleantmp" automatic action is not the solution. We should still be able to at least handle the cases with the file content I proposed. I think the error handling is just missing to cleanup those temporary json or xml file when native inventory decides to not handle them.