diff --git a/scripts/syncGLPI.py b/scripts/syncGLPI.py index e641831..301e3a1 100644 --- a/scripts/syncGLPI.py +++ b/scripts/syncGLPI.py @@ -26,14 +26,21 @@ else: #=========== Configuration des logs ===========# +# handler pour les logs de base logger = logging.getLogger(__name__) +# handler pour log les doublons dans GLPI +loggerDouble = logging.getLogger('doubleGLPI') +# hander pour log les appareils manquants dans GLPI +loggerMissing = logging.getLogger('missingGLPI') if(args.debug or settings["LOGS"]["Debug"]): logginglevel = logging.DEBUG else: logginglevel = logging.INFO - + logger.setLevel(logginglevel) +loggerDouble.setLevel(logginglevel) +loggerMissing.setLevel(logginglevel) formatter = logging.Formatter(fmt='%(asctime)s | %(levelname)s: %(message)s', datefmt='%Y/%m/%d %H:%M:%S') @@ -42,14 +49,25 @@ if(settings["LOGS"]["Enabled"]): if(settings["LOGS"].get("Path") and settings["LOGS"].get("Path") != ""): fileHandler = logging.FileHandler(f"{settings['LOGS'].get('Path')}syncGLPI.log") fileErrorHandler = logging.FileHandler(f"{settings['LOGS'].get('Path')}syncGLPI-errors.log") + fileDoubleHandler = logging.FileHandler(f"{settings['LOGS'].get('Path')}syncGLPI-double.log") + fileMissingHandler = logging.FileHandler(f"{settings['LOGS'].get('Path')}syncGLPI-missing.log") else: fileHandler = logging.FileHandler('./logs/syncGLPI.log') + fileErrorHandler = logging.FileHandler("./logs/syncGLPI-errors.log") + fileDoubleHandler = logging.FileHandler("./logs/syncGLPI-double.log") + fileDoubleHandler = logging.FileHandler("./logs/syncGLPI-missing.log") fileHandler.setLevel(logginglevel) fileHandler.setFormatter(formatter) fileErrorHandler.setLevel(logging.ERROR) fileErrorHandler.setFormatter(formatter) + fileDoubleHandler.setLevel(logging.ERROR) + fileDoubleHandler.setFormatter(formatter) + fileMissingHandler.setLevel(logging.ERROR) + fileMissingHandler.setFormatter(formatter) logger.addHandler(fileHandler) logger.addHandler(fileErrorHandler) + logger.addHandler(fileDoubleHandler) + logger.addHandler(fileMissingHandler) # handler pour log dans la console if(not args.silent): @@ -165,18 +183,22 @@ if(searchFilter != None): for device in devices: if(device.EnrollmentStatus != 'Enrolled'): - logger.warning(f"Device with id {device.Id} not enrolled, skipping this device...") + logger.warning(f"Device with Airwatch id {device.Id} not enrolled, skipping this device...") + continue + + if(device.SerialNumber == 'HUBNOSERIAL'): + logger.info(f"Device with Airwatch id {device.Id} is using work profile, skipping...") continue - logger.info(f"Searching device {device.FriendlyName} (id={device.Id}) on GLPI") + logger.info(f"Searching device {device.FriendlyName} (Airwatch id={device.Id}) on GLPI") deviceID, data, count = glpiapi.GetDevice(device) apps = airwatch.GetDeviceApps(device) if(count > 1): - logger.error(f"{count} devices matching airwatch device {device.FriendlyName} (id={device.Id}) in GLPI (GLPI ids = {', '.join(deviceID)}), skipping this device...") + loggerDouble.error(f"{count} devices matching airwatch device {device.FriendlyName} (Airwatch id={device.Id}) in GLPI (GLPI ids = {', '.join(deviceID)}), skipping this device...") continue if(count == 0): - logger.error(f"Device {device.FriendlyName} (id={device.Id}) not found in GLPI, is it in the trash bin ? Skipping device...") + loggerMissing.error(f"Device {device.FriendlyName} (id={device.Id}) not found in GLPI, is it in the trash bin ? Skipping device...") continue inventory = glpiapi.CreateInventoryForAirwatchDevice(device, data["1"], apps) @@ -197,7 +219,7 @@ for device in devices: glpiapi.UpdateInventory(inventory.Json()) if(data['5'] != device.SerialNumber): - logger.info(f"Updating serial number from {data['5']} to {device.SerialNumber} in GLPI") + logger.info(f"Updating serial number from {data['5']} to {device.SerialNumber} in GLPI (id={deviceID})") glpiapi.UpdateSerialNumber(deviceID, device.SerialNumber) logger.info("========= End of synchronization =========")