cconard96 / jamf

JAMF Plugin for GLPI
GNU General Public License v2.0
6 stars 5 forks source link

Unable to import a device #103

Closed marekpierog closed 2 years ago

marekpierog commented 2 years ago

After a device from JAMF is discovered and clicking on import the following error apears:

[2022-05-24 09:50:46] glpisqllog.ERROR: DBmysql::query() in /var/www/html/src/DBmysql.php line 368
  *** MySQL query error:
  SQL: UPDATE `glpi_plugin_jamf_devices` SET `itemtype` = 'Phone', `items_id` = '193', `activation_lock_enabled` = '0', `last_inventory` = '2022-01-10T13:29:02.432+0000', `entry_date` = '2019-09-26T08:43:36.042+0000', `enroll_date` = '2021-03-15T13:35:19.738+0000', `jamf_items_id` = '1', `udid` = '2792f4bd88d0015b273***************', `managed` = '1', `supervised` = '1', `sync_date` = '2022-05-24 09:50:42' WHERE `itemtype` = 'Phone' AND `items_id` = '193'
  Error: Incorrect datetime value: '2022-01-10T13:29:02.432+0000' for column 'last_inventory' at row 1
  Backtrace :
  src/DBmysql.php:1451
  src/DBmysql.php:1489                               DBmysql->updateOrDie()
  marketplace/jamf/inc/devicesync.class.php:297      DBmysql->updateOrInsert()
  marketplace/jamf/inc/devicesync.class.php:250      PluginJamfDeviceSync->finalizeSync()
  marketplace/jamf/inc/mobilesync.class.php:810      PluginJamfDeviceSync::sync()
  marketplace/jamf/ajax/import.php:63                PluginJamfMobileSync::import()
  {"user":"7@glpi"}

GLPI: 10.0.0 Plugin: 3.0.0 PHP: 8.1.2 mySQL: 8.0.29 OS: Ubuntu 22.04 LTS

cconard96 commented 2 years ago

Hello,

The entry_date field should be using the date and time directly from the session in GLPI but that format does not look right. It should look similar to 2022-05-23 19:09:36. In your GLPI, can you enable debug mode for your user then click the bug icon in the top right to open the debug panel, navigate to the Session tab, and check the value of glpi_currenttime?

For fields like last_inventory, it should be the timestamp received directly from Jamf in the format. I'll have to look into that more to see if some conversions are missing.

marekpierog commented 2 years ago

Hi, time format @ GLPI seems to be fine:

glpi_currenttime => 2022-05-24 20:02:21
cconard96 commented 2 years ago

Sorry for the long delay, I was busy with core GLPI development work. Can you test the fixes done in #109? It should fix the handling of UTC dates coming from Jamf.

marekpierog commented 2 years ago
[2022-06-09 10:44:33] glpisqllog.ERROR: DBmysql::query() in /var/www/html/src/DBmysql.php line 370
  *** MySQL query error:
  SQL: UPDATE `glpi_plugin_jamf_devices` SET `itemtype` = 'Phone', `items_id` = '196', `activation_lock_enabled` = '0', `last_inventory` = '06-06-2022 10:08:58', `entry_date` = '26-09-2019 10:43:36', `enroll_date` = '15-03-2021 14:35:19', `jamf_items_id` = '1', `udid` = '2792f4bd88d0015b2733bd***************', `managed` = '1', `supervised` = '1', `sync_date` = '2022-06-09 10:44:26' WHERE `itemtype` = 'Phone' AND `items_id` = '196'
  Error: Incorrect datetime value: '06-06-2022 10:08:58' for column 'last_inventory' at row 1
  Backtrace :
  src/DBmysql.php:1453
  src/DBmysql.php:1491                               DBmysql->updateOrDie()
  marketplace/jamf/inc/devicesync.class.php:297      DBmysql->updateOrInsert()
  marketplace/jamf/inc/devicesync.class.php:250      PluginJamfDeviceSync->finalizeSync()
  marketplace/jamf/inc/mobilesync.class.php:810      PluginJamfDeviceSync::sync()
  marketplace/jamf/ajax/import.php:63                PluginJamfMobileSync::import()
  {"user":"7@glpi"}

Unfortunately datetime is still in a format unaccepted by mySQL

cconard96 commented 2 years ago

I made an adjustment to force Y-M-D date format when syncing instead of using the user preference for date format (which should only be used for display). The change was made in the same linked pull request.

marekpierog commented 2 years ago

Can confirm - it works after applying this PR. Thank you!