unistra / ansible-collection-glpi

Ansible dynamic inventory for GLPI.
GNU General Public License v3.0
9 stars 5 forks source link

GLPI meta search #8

Open Rico29 opened 7 months ago

Rico29 commented 7 months ago

Hello I'm actually integrating your work in our ansible setup, to get inventory from GLPI API. works fine.

One problem though : the fact that it's not possible to get elements by name (uid_cols=true). The inherent problem is when using meta search : if a meta filed has the same id in its category, it overwrites the result.

example when trying to get computers with a specific version of a software installed :

GET PARAMS :

uid_cols:1
criteria[0][field]:5161
criteria[0][searchtype]:contains
criteria[0][value]:freepbx
criteria[1][link]:AND
criteria[1][meta]:true
criteria[1][itemtype]:Software
criteria[1][field]:1
criteria[1][searchtype]:contains
criteria[1][value]:freepbx-module-core
criteria[2][link]:AND
criteria[2][meta]:true
criteria[2][itemtype]:Software
criteria[2][field]:5
criteria[2][searchtype]:contains
criteria[2][value]:^16

result of query :

    "data": [
        {
            "Computer.name": "117-freepbx",
            "Computer.Entity.completename": "/",
            "Computer.Location.completename": null,
            "Computer.State.completename": "actif",
            "Computer.ComputerType.name": "QEMU",
            "Computer.PluginFusioninventoryInventoryComputerComputer.last_fusioninventory_update": "2024-04-03 17:00:50",
            "Computer.comment": null,
            "Computer.ComputerModel.name": "Standard PC (i440FX + PIIX, 1996)",
            "Computer.Item_OperatingSystem.OperatingSystem.name": "Debian GNU/Linux",
            "Computer.Item_OperatingSystem.OperatingSystemVersion.name": "12.5",
            "Computer.ComputerVirtualMachine.name": null,
            "Computer.PluginFusioninventoryAgent.tag": "freepbx location_client",
            "Software.name": "freepbx-module-core",
            "Software.SoftwareVersion.name": "freepbx-module-core - 16.0.68.20"
        },
...

but if I remove the "uid_cols:1" I get this result, which does not display anymore the targeted hostname :

    "data": [
        {
            "1": "freepbx-module-core",
            "80": "/",
            "3": null,
            "31": "actif",
            "4": "QEMU",
            "5150": "2024-04-03 17:00:50",
            "16": null,
            "40": "Standard PC (i440FX + PIIX, 1996)",
            "45": "Debian GNU/Linux",
            "46": "12.5",
            "160": null,
            "5161": "freepbx location_client",
            "5": "freepbx-module-core - 16.0.68.20"
        },
...

because "Software.name" has id 1 in software itemtype.

Is there any workaround ? Regards

Rico29 commented 7 months ago

from https://github.com/glpi-project/glpi/blob/main/apirest.md#search-items :

uid_cols (default false): a boolean to identify cols by the 'uniqid' of the searchoptions instead of a numeric value (see List searchOptions and 'uid' field)