Ajout d'une traduction des noms de version Windows dans le friendlyname
This commit is contained in:
@ -61,6 +61,27 @@ class GLPIAPI:
|
||||
return None, None, 0
|
||||
return None, None, None
|
||||
|
||||
def GetUser(self, username=None, email=None):
|
||||
|
||||
if(username != None):
|
||||
search_parameter = f'is_deleted=0&criteria[0][field]=1&withindexes=true&criteria[0][searchtype]=contains&criteria[0][value]=^{username}$'
|
||||
elif(email != None):
|
||||
search_parameter = f'is_deleted=0&criteria[0][field]=5&withindexes=true&criteria[0][searchtype]=contains&criteria[0][value]=^{email}$'
|
||||
searchUri = f"{self.Server}/apirest.php/search/user?{search_parameter}"
|
||||
search = requests.get(searchUri, headers=self.Headers)
|
||||
if(search.status_code == 200):
|
||||
search = search.json()
|
||||
if(search["totalcount"] == 1):
|
||||
userID = list(search["data"].keys())[0]
|
||||
data = search["data"][userID]
|
||||
|
||||
return userID, data, search["totalcount"]
|
||||
elif(search["totalcount"] > 1):
|
||||
userID = list(search["data"].keys())
|
||||
return userID, search["data"], search["totalcount"]
|
||||
else:
|
||||
return None, None, 0
|
||||
|
||||
def UpdateInventory(self, inventory):
|
||||
headers = {
|
||||
"Content-Type":"Application/x-compress",
|
||||
@ -94,7 +115,7 @@ class GLPIAPI:
|
||||
platforms = {
|
||||
2:"Apple iOS",
|
||||
5:"Android",
|
||||
12:"Windows Desktop"
|
||||
12:"Windows"
|
||||
}
|
||||
|
||||
if(device.PlatformId in platforms.keys()):
|
||||
@ -119,9 +140,26 @@ class GLPIAPI:
|
||||
osArch = "Unknown"
|
||||
softwareArch = "Unknown"
|
||||
|
||||
windowsOSTranslation = {
|
||||
"10.0.19043":"10 21H1",
|
||||
"10.0.19044":"10 21H2",
|
||||
"10.0.19045":"10 22H2",
|
||||
"10.0.22000":"11 21H2",
|
||||
"10.0.22621":"11 22H2",
|
||||
"10.0.22631":"11 23H2",
|
||||
"10.0.26100":"11 24H2",
|
||||
"10.0.26200":"11 25H2"
|
||||
}
|
||||
|
||||
logDate = datetime.strptime(device.LastSeen, "%Y-%m-%dT%H:%M:%S.%f").strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
inventory = GLPIInventory(logdate=logDate, versionclient=self.UserAgent, tag=device.Group, deviceid=f"{deviceName} - {device.SerialNumber}", itemtype="Computer")
|
||||
if(platformName == "Windows"):
|
||||
if(device.OS in windowsOSTranslation.keys()):
|
||||
inventory.SetOperatingSystem(platformName, windowsOSTranslation[str(device.OS)], osArch)
|
||||
else:
|
||||
inventory.SetOperatingSystem(platformName, device.OS, osArch)
|
||||
else:
|
||||
inventory.SetOperatingSystem(platformName, device.OS, osArch)
|
||||
inventory.SetHardware(deviceName, device.Uuid, device.TotalMemory)
|
||||
inventory.AddUser(device.User)
|
||||
|
||||
@ -204,14 +204,21 @@ for device in devices:
|
||||
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):
|
||||
loggerMissing.error(f"Device {device.FriendlyName} (id={device.Id}) not found in GLPI, is it in the trash bin ? Skipping device...")
|
||||
deviceIDTrash, dataTrash, countTrash = glpiapi.GetDevice(device)
|
||||
if(countTrash > 1):
|
||||
loggerDouble.error(f"{countTrash} devices matching airwatch device {device.FriendlyName} (Airwatch id={device.Id}) in GLPI trashbin (GLPI ids = {', '.join(deviceIDTrash)}), skipping this device...")
|
||||
elif(countTrash == 1):
|
||||
logger.warning(f"Device {device.FriendlyName} (Airwatch id={device.Id}) in GLPI trashbin (GLPI id={deviceIDTrash}), skipping...")
|
||||
else:
|
||||
loggerMissing.error(f"Device {device.FriendlyName} (Airwatch id={device.Id}) not found in GLPI.")
|
||||
continue
|
||||
|
||||
inventory = glpiapi.CreateInventoryForAirwatchDevice(device, data["1"], apps)
|
||||
# Mise à jour du friendly name sur Airwatch
|
||||
platformName = inventory.operatingsystem["name"]
|
||||
if(device.FriendlyName != f"{data['1']} {platformName} {device.OS} - {device.User}"):
|
||||
newFriendlyName = f"{data['1']} {platformName} {device.OS} - {device.User}"
|
||||
osVersion = inventory.operatingsystem["version"]
|
||||
if(device.FriendlyName != f"{data['1']} {platformName} {osVersion} - {device.User}"):
|
||||
newFriendlyName = f"{data['1']} {platformName} {osVersion} - {device.User}"
|
||||
logger.info(f"Updating device friendlyname to {newFriendlyName}")
|
||||
airwatch.SetDeviceFriendlyName(device, newFriendlyName)
|
||||
|
||||
@ -224,9 +231,11 @@ for device in devices:
|
||||
logger.info(f"Updating {deviceID} on GLPI")
|
||||
glpiapi.UpdateInventory(inventory.Json())
|
||||
|
||||
#if(data['70'] == None and device.User != settings["AIRWATCH"]["StagingUser"]):
|
||||
#logger.info(f"Updating user from {data['70']} to {device.User} in GLPI (id={deviceID})")
|
||||
#glpiapi.UpdateUser(deviceID, device.User)
|
||||
if(data['70'] == None and device.User != settings["AIRWATCH"]["StagingUser"]):
|
||||
userID, userData, userCount = glpiapi.GetUser(device.User)
|
||||
if(userCount == 1):
|
||||
logger.info(f"Updating user from {data['70']} to {device.User} in GLPI (id={deviceID})")
|
||||
glpiapi.UpdateUser(deviceID, userID)
|
||||
|
||||
if(data['5'] != device.SerialNumber):
|
||||
logger.info(f"Updating serial number from {data['5']} to {device.SerialNumber} in GLPI (id={deviceID})")
|
||||
|
||||
Reference in New Issue
Block a user