removed includes, updated to api modules
This commit is contained in:
@@ -5,8 +5,8 @@ import logging
|
||||
import time
|
||||
from datetime import datetime
|
||||
from functions import getSettings
|
||||
from includes.airwatchAPI import *
|
||||
from includes.GLPIAPI import *
|
||||
from AirwatchAPI.AirwatchAPI import *
|
||||
from GLPIAPI.GLPIAPI import *
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-sF", "--searchFilter", dest="searchfilter", type=str, choices=["Id", "SerialNumber", "Imei", "UserName"])
|
||||
@@ -126,7 +126,7 @@ else:
|
||||
logger.info("========= Synchronization started =========")
|
||||
|
||||
try:
|
||||
airwatch = AirwatchAPI(settings)
|
||||
airwatch = AirwatchAPI(Server=settings["AIRWATCH"]["Server"], APIKey=settings["AIRWATCH"]["APIKey"], AuthMethod=settings["AIRWATCH"]["AuthenticationMethod"], CertPath=settings["AIRWATCH"]["CertificatePath"], CertPass=settings["AIRWATCH"]["CertificatePassword"])
|
||||
# recherche des appareils
|
||||
devices = airwatch.GetDevices()
|
||||
logger.info("Airwatch server connection succeeded")
|
||||
@@ -141,7 +141,7 @@ except Exception as error:
|
||||
|
||||
# Initialisation de l'api GLPI
|
||||
try:
|
||||
glpiapi = GLPIAPI(settings)
|
||||
glpiapi = GLPIAPI(Server=settings["GLPI"]["Server"], AppToken=settings["GLPI"]["AppToken"], UserToken=settings["GLPI"]["UserToken"], UserAgent=settings["GLPI"]["UserAgent"])
|
||||
logger.info("GLPI server connection succeeded")
|
||||
except requests.exceptions.ConnectionError as error:
|
||||
logger.critical(f"Connection to GLPI server failed : {error}")
|
||||
@@ -209,13 +209,13 @@ for device in devices:
|
||||
|
||||
logger.info(f"Searching device {device.FriendlyName} (Airwatch id={device.Id}) on GLPI")
|
||||
|
||||
deviceID, data, count = glpiapi.GetDevice(device)
|
||||
deviceID, data, count = glpiapi.GetComputers(airwatchDevice=device)
|
||||
apps = airwatch.GetDeviceApps(device)
|
||||
if(count > 1):
|
||||
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):
|
||||
deviceIDTrash, dataTrash, countTrash = glpiapi.GetDevice(device)
|
||||
deviceIDTrash, dataTrash, countTrash = glpiapi.GetComputers(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):
|
||||
@@ -226,7 +226,6 @@ for device in devices:
|
||||
|
||||
inventory = glpiapi.CreateInventoryForAirwatchDevice(device, data["1"], apps)
|
||||
# Mise à jour du friendly name sur Airwatch
|
||||
print(device.PlatformId)
|
||||
platformName = inventory.operatingsystem["name"]
|
||||
osVersion = inventory.operatingsystem["version"]
|
||||
if(device.FriendlyName != f"{data['1']} {platformName} {osVersion} - {device.User}"):
|
||||
@@ -237,7 +236,8 @@ for device in devices:
|
||||
# Mise à jour de l'url vers la page airwatch de l'appareil sur GLPI
|
||||
airwatchlink = f"{settings['AIRWATCH']['ConsoleURI']}/AirWatch/#/AirWatch/Device/Details/Summary/{device.Id}"
|
||||
if(data['76689'] != airwatchlink):
|
||||
glpiapi.UpdateAirwatchLink(deviceID, airwatchlink)
|
||||
glpiapi.SetField(itemType="Computer", containerName="mdt", containerID=4, itemId=deviceID, fieldName="appareilsurmagentafield", data=airwatchlink)
|
||||
|
||||
|
||||
# filtre des plateformes
|
||||
if(platformFilterEnabled):
|
||||
@@ -248,12 +248,11 @@ for device in devices:
|
||||
logger.info(f"Updating {deviceID} on GLPI")
|
||||
glpiapi.UpdateInventory(inventory.Json())
|
||||
|
||||
print(f"{data['70']} - {device.User}")
|
||||
if(data['70'] == None and device.User != settings["AIRWATCH"]["StagingUser"]):
|
||||
userID, userData, userCount = glpiapi.GetUser(device.User)
|
||||
userID, userData, userCount = glpiapi.GetUsers(username=device.User)
|
||||
if(userCount == 1):
|
||||
logger.info(f"Updating user from {data['70']} to {device.User} in GLPI (id={deviceID})")
|
||||
glpiapi.UpdateUser(deviceID, userID)
|
||||
glpiapi.UpdateItemUser(deviceID, "Computer", 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