Modification de la gestion des logs pour gérer les doublons et les manquants dans un fichier séparé
This commit is contained in:
@ -26,7 +26,12 @@ else:
|
|||||||
|
|
||||||
#=========== Configuration des logs ===========#
|
#=========== Configuration des logs ===========#
|
||||||
|
|
||||||
|
# handler pour les logs de base
|
||||||
logger = logging.getLogger(__name__)
|
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"]):
|
if(args.debug or settings["LOGS"]["Debug"]):
|
||||||
logginglevel = logging.DEBUG
|
logginglevel = logging.DEBUG
|
||||||
@ -34,6 +39,8 @@ else:
|
|||||||
logginglevel = logging.INFO
|
logginglevel = logging.INFO
|
||||||
|
|
||||||
logger.setLevel(logginglevel)
|
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')
|
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") != ""):
|
if(settings["LOGS"].get("Path") and settings["LOGS"].get("Path") != ""):
|
||||||
fileHandler = logging.FileHandler(f"{settings['LOGS'].get('Path')}syncGLPI.log")
|
fileHandler = logging.FileHandler(f"{settings['LOGS'].get('Path')}syncGLPI.log")
|
||||||
fileErrorHandler = logging.FileHandler(f"{settings['LOGS'].get('Path')}syncGLPI-errors.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:
|
else:
|
||||||
fileHandler = logging.FileHandler('./logs/syncGLPI.log')
|
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.setLevel(logginglevel)
|
||||||
fileHandler.setFormatter(formatter)
|
fileHandler.setFormatter(formatter)
|
||||||
fileErrorHandler.setLevel(logging.ERROR)
|
fileErrorHandler.setLevel(logging.ERROR)
|
||||||
fileErrorHandler.setFormatter(formatter)
|
fileErrorHandler.setFormatter(formatter)
|
||||||
|
fileDoubleHandler.setLevel(logging.ERROR)
|
||||||
|
fileDoubleHandler.setFormatter(formatter)
|
||||||
|
fileMissingHandler.setLevel(logging.ERROR)
|
||||||
|
fileMissingHandler.setFormatter(formatter)
|
||||||
logger.addHandler(fileHandler)
|
logger.addHandler(fileHandler)
|
||||||
logger.addHandler(fileErrorHandler)
|
logger.addHandler(fileErrorHandler)
|
||||||
|
logger.addHandler(fileDoubleHandler)
|
||||||
|
logger.addHandler(fileMissingHandler)
|
||||||
|
|
||||||
# handler pour log dans la console
|
# handler pour log dans la console
|
||||||
if(not args.silent):
|
if(not args.silent):
|
||||||
@ -165,18 +183,22 @@ if(searchFilter != None):
|
|||||||
|
|
||||||
for device in devices:
|
for device in devices:
|
||||||
if(device.EnrollmentStatus != 'Enrolled'):
|
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
|
continue
|
||||||
|
|
||||||
logger.info(f"Searching device {device.FriendlyName} (id={device.Id}) on GLPI")
|
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} (Airwatch id={device.Id}) on GLPI")
|
||||||
|
|
||||||
deviceID, data, count = glpiapi.GetDevice(device)
|
deviceID, data, count = glpiapi.GetDevice(device)
|
||||||
apps = airwatch.GetDeviceApps(device)
|
apps = airwatch.GetDeviceApps(device)
|
||||||
if(count > 1):
|
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
|
continue
|
||||||
if(count == 0):
|
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
|
continue
|
||||||
|
|
||||||
inventory = glpiapi.CreateInventoryForAirwatchDevice(device, data["1"], apps)
|
inventory = glpiapi.CreateInventoryForAirwatchDevice(device, data["1"], apps)
|
||||||
@ -197,7 +219,7 @@ for device in devices:
|
|||||||
glpiapi.UpdateInventory(inventory.Json())
|
glpiapi.UpdateInventory(inventory.Json())
|
||||||
|
|
||||||
if(data['5'] != device.SerialNumber):
|
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)
|
glpiapi.UpdateSerialNumber(deviceID, device.SerialNumber)
|
||||||
|
|
||||||
logger.info("========= End of synchronization =========")
|
logger.info("========= End of synchronization =========")
|
||||||
|
|||||||
Reference in New Issue
Block a user