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

getFromDBByCrit expects to get one result, 2 found! #3159

Open fralla2 opened 3 years ago

fralla2 commented 3 years ago

Hi,

Since upgrading to glpi v9.5.5, the fusioninventory plugins seems to trigger this warning frequently in the php-errors.log file.

[2021-04-26 01:20:39] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 351 getFromDBByCrit expects to get one result, 2 found! {"user":"928@glpi06"} [2021-04-26 01:24:01] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 351 getFromDBByCrit expects to get one result, 2 found! {"user":"928@glpi06"} [2021-04-26 01:40:59] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 351 getFromDBByCrit expects to get one result, 2 found! {"user":"928@glpi06"} [2021-04-26 02:26:40] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 351 getFromDBByCrit expects to get one result, 2 found! {"user":"928@glpi06"} [2021-04-26 02:26:40] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 351 getFromDBByCrit expects to get one result, 2 found! {"user":"928@glpi06","mem_usage":"0.002\", 7.97Mio)"}

Not sure it it's coming from GLPI' side or FusionInventory' side but it only affect the user 928 (Plugin_FusionInventory). I also verified the database and this user id (928) and name (Plugin_FusionInventory) is only present once on the glpi_users table so there's no uniticity error there....

GLPI version : 9.5.5 FusionInventory version : 9.5+3.0

Thanks Francois

ftoledo commented 3 years ago

I confirm this issue

bacus99 commented 3 years ago

Confirmed

SebastienBatteur commented 3 years ago

same configuration I also confirm

AnthonySIF commented 3 years ago

Same here, 9.5.5 + FI 3.0 The LDAP configuration worked for a long time, so it's certainly a bug.

Found those similar tickets :

I modified the commondbtm.class.php (second ticket), each users appears twice in sync log, but they a ok in AD...

I translate this other ticket : https://forum.glpi-project.org/viewtopic.php?id=164796 As said in last entry, users seems to have "hex" data in exchange attributes... can't modify them but maybe a change in 9.5.5 ? My output is : (...) found! CommonDBTM::getFromDBByCrit() in .....\glpi\inc\commondbtm.class.php line 352 getFromDBByCrit expects to get one result, Array ( [user_dn] => CN=LAST First,OU=Users,OU=Accounts,DC=domain,DC=com )

fralla2 commented 3 years ago

Thanks @AnthonySIF , I've added the "print_r($crit['WHERE'],1)" as indicated in post #4 of the second link you found (https://forum.glpi-project.org/viewtopic.php?id=280233) and the error seemed to came from a peripheral. I've deleted it and will see if the error show up again.

Managed to solve this by doing

changed the commondbtm.class file

sprintf( 'getFromDBByCrit expects to get one result, %1$s found!', /count($iter)/ print_r($crit['WHERE'],1) )

     );

That way it printed me the table it was checking. On my case was some networkports... deleted them and the error disappeared

[2021-09-09 10:38:18] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 352 getFromDBByCrit expects to get one result, Array ( [itemtype] => Peripheral [items_id] => 2734 ) found! {"user":"928@glpi06"} [2021-09-09 10:38:45] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 352 getFromDBByCrit expects to get one result, Array ( [itemtype] => Peripheral [items_id] => 216 )

fralla2 commented 3 years ago

I've modified the line 349 to 352 of the file commondbtm.class with the following to have a little more logging

sprintf( 'getFromDBByCrit expects to get one result, %1$s found! in table %2$s with criterias %3$s', count($iter), print_r($crit['FROM'],1), print_r($crit['WHERE'],1) )

The results are of the followings form... : image

They all seems to be glpi_networkports_networkports but I have many different id's...

I'll investigate further

AnthonySIF commented 3 years ago

Great, with your code I notice that for my case it was the "glpi_user" table... As it's an historical installation, i never add the "sync shield" on ldap link => Added the "objectguid", clean some users that was really duplicated (some in trash) Et voilà !

The code should be included in next release of glpi (easier to find the problem), but we are on fusion inventory github... ^^

ftoledo commented 3 years ago

just for understand.. i get that follow output, what kind of problem have these pheripeals? must i delete it to solve?

[2021-09-09 13:52:12] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /home/glpi/html/inc/commondbtm.class.php line 352
getFromDBByCrit expects to get one result, Array
(
    [itemtype] => Peripheral
    [items_id] => 680
)
 found!  {"user":"65@tom"}
[2021-09-09 14:37:01] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /home/glpi/html/inc/commondbtm.class.php line 352
getFromDBByCrit expects to get one result, Array
(
    [itemtype] => Peripheral
    [items_id] => 672
)
 found!  {"user":"65@tom"}
fralla2 commented 3 years ago

Glad this could help others and thanks again for pointing me to the right direction with the other forum' post.

I had to do a lot of cleaning as I found many duplicates in glpi_networkports_networkports and glpi_computers_items.

I'll keep an eye on my logs for the next day but I'm confident it's now corrected.

I'm wondering it these duplicates were created following a recent bug with the plugins or if, as you, they were long time duplicates (we have been using glpi since v0.75 I think) but glpi just started showing them in logs....

fralla2 commented 3 years ago

@ftoledo : Once I modified my commondbtm.class with the following, it gave me a more precise idea of the affected table (in my case it was in glpi_networkports_networkports and glpi_computers_items

I've deleted the duplicate entried from the db and it seemed to have fixed the problem

sprintf( 'getFromDBByCrit expects to get one result, %1$s found! in table %2$s with criterias %3$s', count($iter), print_r($crit['FROM'],1), print_r($crit['WHERE'],1) )

[2021-09-09 14:07:37] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 356 getFromDBByCrit expects to get one result, 2 found! in table glpi_computers_items with criterias Array ( [itemtype] => Peripheral [items_id] => 17058 )

EDIT : Got a few duplicates in table glpi_items_devicefirmwares too

fralla2 commented 3 years ago

Well.... A new one got added this morning while the fusionInventory of the switches happened. I'll try to add as much details as I could find :

Affected networkPorts_id is 735208 This port is listed as being the port 1 of an unmanaged device in glpi : image

The reported FusionInventory history reported for this port this morning is the following :

image

The thing is... The same device is already imported in GLPI under Network Equipment and already had it's ports bind by FusionInventory to the correct devices....

image

image

And here's the logs from this morning :

`[2021-09-10 07:34:53] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 356 getFromDBByCrit expects to get one result, 2 found! in table glpi_networkports_networkports with criterias Array ( [OR] => Array ( [glpi_networkports_networkports.networkports_id_1] => 735208 [glpi_networkports_networkports.networkports_id_2] => 735208 )

) {"user":"928@glpi06"} [2021-09-10 07:34:53] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 356 getFromDBByCrit expects to get one result, 2 found! in table glpi_networkports_networkports with criterias Array ( [OR] => Array ( [glpi_networkports_networkports.networkports_id_1] => 735208 [glpi_networkports_networkports.networkports_id_2] => 735208 )

) {"user":"928@glpi06","mem_usage":"0.000\", 6.22Mio)"} [2021-09-10 07:36:01] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 356 getFromDBByCrit expects to get one result, 3 found! in table glpi_networkports_networkports with criterias Array ( [OR] => Array ( [glpi_networkports_networkports.networkports_id_1] => 735208 [glpi_networkports_networkports.networkports_id_2] => 735208 )

) {"user":"928@glpi06"} [2021-09-10 07:36:01] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 356 getFromDBByCrit expects to get one result, 3 found! in table glpi_networkports_networkports with criterias Array ( [OR] => Array ( [glpi_networkports_networkports.networkports_id_1] => 735208 [glpi_networkports_networkports.networkports_id_2] => 735208 )

) {"user":"928@glpi06","mem_usage":"0.001\", 7.11Mio)"} [2021-09-10 07:36:02] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 356 getFromDBByCrit expects to get one result, 4 found! in table glpi_networkports_networkports with criterias Array ( [OR] => Array ( [glpi_networkports_networkports.networkports_id_1] => 735208 [glpi_networkports_networkports.networkports_id_2] => 735208 )

) {"user":"928@glpi06"} [2021-09-10 07:36:02] glpiphplog.WARNING: CommonDBTM::getFromDBByCrit() in /var/www/html/glpi-9.5.5/inc/commondbtm.class.php line 356 getFromDBByCrit expects to get one result, 4 found! in table glpi_networkports_networkports with criterias Array ( [OR] => Array ( [glpi_networkports_networkports.networkports_id_1] => 735208 [glpi_networkports_networkports.networkports_id_2] => 735208 )

) {"user":"928@glpi06","mem_usage":"0.001\", 6.89Mio)"} `

Hope this can help troubleshoot a little more Francois

fralla2 commented 3 years ago

My guess is that the plugins fails to detect that this device (A) is already in the inventory and add it to the "Unmanaged devices" section (B) with the same mac address....

Then when the SNMP inventory runs on the other devices (X-Y-Z) that are connected to the device (A), it bind those ports (with the MAC address) to the device A (correct), but also bind them to the unmanaged device B (witch shouldn't be on the unmanaged devices to begin with) because they list the same MAC....

A fix would probably be to add more checkups before adding a device to the unmanaged devices list to make sure a same device is not already present in glpi ???