fusioninventory / fusioninventory-for-glpi

FusionInventory plugin for GLPI
http://www.FusionInventory.org/
GNU Affero General Public License v3.0
361 stars 148 forks source link

WMI collecting ignores multivalue answers #2196

Open nbriche opened 7 years ago

nbriche commented 7 years ago

For WMI Collect tasks, if the client answers with several values, only the last one is retained. For example, with a WMI task for class Win32_UserProfile and property SID, this is a typical client answer (from server log):

172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=getJobs&machineid=xxxxx-2017-06-29-10-01-38 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 609
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=9&uuid=5954ff35f1d2a&_cpt=14 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&uuid=5954ff35f1d2a&_sid=9&_cpt=13 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&uuid=5954ff35f1d2a&_sid=9&_cpt=12 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_cpt=11&uuid=5954ff35f1d2a&_sid=9 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_cpt=10&uuid=5954ff35f1d2a&_sid=9 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_cpt=9&_sid=9&uuid=5954ff35f1d2a HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_cpt=8&_sid=9&uuid=5954ff35f1d2a HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_cpt=7&uuid=5954ff35f1d2a&_sid=9 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=9&uuid=5954ff35f1d2a&_cpt=6 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_cpt=5&_sid=9&uuid=5954ff35f1d2a HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&uuid=5954ff35f1d2a&_sid=9&_cpt=4 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=9&uuid=5954ff35f1d2a&_cpt=3 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=9&uuid=5954ff35f1d2a&_cpt=2 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&uuid=5954ff35f1d2a&_sid=9&_cpt=1 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=6&uuid=5954ff35f1d2a&_cpt=14&SID=S-1-5-21-xxxx-365832613-509684405-500 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=6&uuid=5954ff35f1d2a&_cpt=13&SID=S-1-5-21-xxxx-365832613-509684405-1002 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&SID=S-1-5-21-xxxx-4292491762-2523612438-2667&_cpt=12&uuid=5954ff35f1d2a&_sid=6 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=6&uuid=5954ff35f1d2a&_cpt=11&SID=S-1-5-21-xxxx-4292491762-2523612438-2634 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&SID=S-1-5-21-xxxx-4292491762-2523612438-2334&_cpt=10&uuid=5954ff35f1d2a&_sid=6 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:29 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_cpt=9&SID=S-1-5-21-xxxx-4292491762-2523612438-1795&_sid=6&uuid=5954ff35f1d2a HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:30 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=6&uuid=5954ff35f1d2a&_cpt=8&SID=S-1-5-21-xxxx-4292491762-2523612438-1768 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:30 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=6&uuid=5954ff35f1d2a&_cpt=7&SID=S-1-5-21-xxxx-4292491762-2523612438-1682 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:30 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=6&uuid=5954ff35f1d2a&_cpt=6&SID=S-1-5-21-xxxx-4292491762-2523612438-1298 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:30 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_cpt=5&SID=S-1-5-21-xxxx-4292491762-2523612438-1113&_sid=6&uuid=5954ff35f1d2a HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:30 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=6&uuid=5954ff35f1d2a&_cpt=4&SID=S-1-5-21-xxxx-4292491762-2523612438-1109 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:30 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&uuid=5954ff35f1d2a&_sid=6&SID=S-1-5-20&_cpt=3 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:30 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&_sid=6&uuid=5954ff35f1d2a&_cpt=2&SID=S-1-5-19 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:30 +0200] "GET //plugins/fusioninventory/b/collect/?action=setAnswer&SID=S-1-5-18&_cpt=1&uuid=5954ff35f1d2a&_sid=6 HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345
172.17.66.195 - - [29/Jun/2017:16:19:30 +0200] "GET //plugins/fusioninventory/b/collect/?action=jobsDone&uuid=5954ff35f1d2a HTTP/1.1" ("/plugins/fusioninventory/b/collect/index.php") 200 345

The client answers with 14 items, but only the last is retained by the server. The database itself has only those items; this is not a display issue. The XML has not trace of collect task data at all.

nbriche commented 7 years ago

Some thoughts:

If I understand 171-174 correctly, there's no concept of possible multiple values for a given WMI property when updating the DB.

We could MacGyver something using _cpt, except that for some reason I haven't found yet, that URL parameter gets consumed by setting up $cpt (at 129 and 132), and then $cpt never gets used anywhere in the code. So _cpt is essentially useless, as far as I can see.

The issue could be resolved by:

Either would mean some UI rework to actually display multiples values properly, and I don't even know about making searches by property and/or value useful.

EC2311 commented 3 years ago

Bonjour, Hello

In fact I created last week a topic in GLPI Forum

I have (I think) the same problem : arborescence in a tree of WMI, with for each entry values, keyname and so on...

How solving this ?

nbriche commented 3 years ago

Reading your thread, I do believe it's the same problem. No matter how many values are returned by your query, only the last one is taken.

Unfortunately there doesn't seem to have been any related changes since then, so we can only hope that a dev sees this and agrees that it's a thing we should have.

EC2311 commented 3 years ago

I think taht code had changed since 2017 136

and I don't understand why all data (present in taskjoblog) are not implemented in collects_wmi_contents.

EC2311 commented 3 years ago

By searching and debugging, I wonder if it's not possible to trace here In fact the updatecomputer is called there for wmi information. so if we can check at first if $a_values is ok... But i don't know how to do it : I don't know php.

EC2311 commented 3 years ago

After few days trying to understand... In fact the agent sends one record by one record (one key by key)

that's why the last key (only) is recorded.

I find a way to solve that by 'adding' a column (keyname) in glpi_plugin_fusioninventory_collects_wmis_contents. image

Each property (we want to get and defined in wmi) will have the same keyname.

in collect_wmi_content.class.php function updateComputer($computers_id, $wmi_data, $collects_wmis_id) { global $DB;

  **// on recherche la clé des valeurs retournées , soit la keyname //**
  **$keyvalue = $wmi_data['keyname'];**

  $db_wmis = [];
  $query = "SELECT `id`, `property`, `value`
            FROM `glpi_plugin_fusioninventory_collects_wmis_contents`
            WHERE `computers_id` = '".$computers_id."'
            **and `keyname` = '".$keyvalue."'**
              AND `plugin_fusioninventory_collects_wmis_id` =
              '".$collects_wmis_id."'";

..... $input = ['property' => $arraydb['property'], 'id' => $keydb, 'keyname' => $keyvalue, 'value' => $value]; .... 'property' => $key, 'value' => $value, 'Keyname' => $keyvalue ]; $this->add($input);

.... $a_data = $this->find(['computers_id' => $computers_id], // ['plugin_fusioninventory_collects_wmis_id', 'property']); ['plugin_fusioninventory_collects_wmis_id', 'keyname asc','property ASC']);

EC2311 commented 3 years ago

Hello

In the same topic : in the file "glpi_plugin_fusioninventory_collects_wmis_contents" (in which the NEW value from wmi are stored/added) : old values are not deleted : normal : they are not matched with the 'each' value returned.

I would like in fact to 'delete' all the old values from the computer when agent on computer starts to send its new datas : where/how to do that ? how to detect that the values sent by computer are the first ones and so, delete its old values (delete from glpi_plugin_fusioninventory_collects_wmis_contents where computers_id = $computers_id, (in updatecomputer function) :

I guess perhaps to do that when agent is awaked ? No idea... If somebody has idea...

Thanks