cconard96 / jamf

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

Cron error #107

Closed bacus99 closed 2 years ago

bacus99 commented 2 years ago

Describe the bug Error in ssql logs 2022-06-02 16:50:44] glpisqllog.ERROR: DBmysql::query() in /usr/share/glpi/src/DBmysql.php line 370 *** MySQL query error: SQL: SELECT itemtype, items_id FROM glpi_plugin_jamf_devices WHERE sync_date < NOW() - INTERVAL MINUTE Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Backtrace : src/DBmysqlIterator.php:110
src/DBmysql.php:1048 DBmysqlIterator->execute() marketplace/jamf/inc/devicesync.class.php:187 DBmysql->request() marketplace/jamf/inc/cron.class.php:42 PluginJamfDeviceSync::syncAll() src/CronTask.php:1018 PluginJamfCron::cronSyncJamf() front/cron.php:64 CronTask::launch()

To Reproduce Cron job give the error

Expected behavior Missing "TIME" ex: x MINUTE. If I edit instead of variable for 1 min, it works

Screenshots

System Specifications (please complete the following information):

Additional context Add any other context about the problem here.

cconard96 commented 2 years ago

Hello, sorry for the delay. Can you test the fix made in #110?

bacus99 commented 2 years ago

New error [2022-06-09 08:33:47] glpisqllog.ERROR: DBmysql::query() in /usr/share/glpi/src/DBmysql.php line 370 *** MySQL query error: SQL: SELECT itemtype, items_id FROM glpi_plugin_jamf_devices WHERE sync_date < NOW() - INTERVAL MINUTE Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Backtrace : src/DBmysqlIterator.php:110
src/DBmysql.php:1048 DBmysqlIterator->execute() marketplace/jamf/inc/devicesync.class.php:187 DBmysql->request() marketplace/jamf/inc/cron.class.php:42 PluginJamfDeviceSync::syncAll() src/CronTask.php:1018 PluginJamfCron::cronSyncJamf() front/cron.php:64 CronTask::launch()

Missing time (ex 1 minute)

cconard96 commented 2 years ago

I added another check to the sync interval in the linked pull request. Can you add the new changes and test again?

If it still doesn't work, can you add the two "Toolbox::logWarning" lines as shown below to print the original value for the sync interval and the calculated one (from the fix)? File: marketplace/jamf/inc/devicesync.class.php Method: syncAll

global $DB;

$volume = 0;

$config = PluginJamfConfig::getConfig();
Toolbox::logWarning('Original sync value: ' . var_export($config['sync_interval'], true));
$valid_sync_interval = isset($config['sync_interval']) && !empty($config['sync_interval']) && ((int) $config['sync_interval'] < 1);
if (!$valid_sync_interval) {
    $config['sync_interval'] = 8 * 60;
}
Toolbox::logWarning('New sync value: ' . var_export($config['sync_interval'], true));

This will put two entries in files/_log/php-errors.log indicating the original value for the sync interval and the one after corrections are attempted (before it goes into the query). I would need the content of both lines to continue debugging.

bacus99 commented 2 years ago

Result [2022-06-13 08:34:08] glpiphplog.WARNING: PluginJamfDeviceSync::syncAll() in /usr/share/glpi/marketplace/jamf/inc/devicesync.class.php line 181 Original sync value: NULL {"user":"12@GLPI"} [2022-06-13 08:34:08] glpiphplog.WARNING: PluginJamfDeviceSync::syncAll() in /usr/share/glpi/marketplace/jamf/inc/devicesync.class.php line 186 New sync value: 480 {"user":"12@GLPI","mem_usage":"0.000\", 5.04Mio)"} [2022-06-13 08:34:09] glpiphplog.WARNING: PluginJamfDeviceSync::syncAll() in /usr/share/glpi/marketplace/jamf/inc/devicesync.class.php line 181 Original sync value: NULL {"user":"12@GLPI","mem_usage":"0.000\", 5.13Mio)"} [2022-06-13 08:34:09] glpiphplog.WARNING: PluginJamfDeviceSync::syncAll() in /usr/share/glpi/marketplace/jamf/inc/devicesync.class.php line 186 New sync value: 480 {"user":"12@GLPI","mem_usage":"0.000\", 5.13Mio)"}

cconard96 commented 2 years ago

The log output shows that a value is being assigned for the sync interval now (default of 8 hours) and the value is directly added into the query so there shouldn't be any more issues with that. On my end, it seems to work OK when the sync interval is not set initially but computed by the changes made in this fix.

cconard96 commented 2 years ago

Note that there are some other issues that I fixed recently that may prevent syncing.

I will merge this fix as-is. If there are still issues, I suggest trying to use the files from the 3.0.0/fixes branch which would be what the next fix version will contain. https://github.com/cconard96/jamf/archive/refs/heads/3.0.0/fixes.zip

The only thing that may be missed is a database schema fix that fixed an issue with discovering Computers from Jamf.

cconard96 commented 2 years ago

v3.0.1 was just released with a bunch of fixes including fixes related to this reported issue. I'll close this issue for now, but if it is still present in v3.0.1, please let me know and I will re-open it.