Suppression de certains paramètres de lancement et création d'un fichier de configuration à la place

This commit is contained in:
Jason SECULA
2025-06-04 13:25:13 +02:00
parent 339fd61fa0
commit f7ef0e2a8c
2 changed files with 71 additions and 29 deletions

View File

@ -3,32 +3,61 @@ import os
import base64
import requests
import json
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-debug", action=argparse.BooleanOptionalAction)
parser.add_argument("-force", action=argparse.BooleanOptionalAction)
args = parser.parse_args()
settingsDefault = {
"airwatchServer":"https://apimagenta.phm.education.gouv.fr",
"airwatchAPIKey":"",
"airwatchAPIUser":"",
"airwatchAPIPassword":"",
"glpiServer":"http://127.0.0.1/glpi/",
"glpiAppToken":"",
"glpiUserToken":"",
"stagingUser":"staging-pr"
}
settings = None
if(not os.path.isfile("./settings.json")):
f = open("./settings.json", "w")
f.write(json.dumps(settingsDefault, indent=4))
f.close()
exit(1)
else:
with open("./settings.json", "r") as f:
settings = json.load(f)
#======== Paramètres du script ========#
# Emplacement du verrou
lockFile = './magentaGLPIStaging.lock'
lockFile = './airwatchStagingUserAssignation.lock'
debug=False
debug=args.debug
# Informations du serveur Airwatch
#airwatchServer = 'https://pp-apimagenta.phm.education.gouv.fr'
airwatchServer = 'https://apimagenta.phm.education.gouv.fr'
airwatchAPIKey = ''
airwatchAPIUser = ''
airwatchAPIPassword = ''
stagingUser = 'staging-pr'
airwatchServer = settings["airwatchServer"]
airwatchAPIKey = settings["airwatchAPIKey"]
airwatchAPIUser = settings["airwatchAPIUser"]
airwatchAPIPassword = settings["airwatchAPIPassword"]
stagingUser = settings["stagingUser"]
# Informations du serveur GLPI
GLPIServer = 'http://127.0.0.1/glpi/'
GLPIAppToken = ''
GLPIUserToken = ''
GLPIServer = settings["glpiServer"]
GLPIAppToken = settings["glpiAppToken"]
GLPIUserToken = settings["glpiUserToken"]
# ====================================== #
# Vérification de la présence du verrou avant de continuer
if(os.path.isfile(lockFile)):
if(os.path.isfile(lockFile) and not args.force):
if(debug):
print('Lock file is present, exiting...')
exit(0)

View File

@ -11,37 +11,50 @@ parser = argparse.ArgumentParser()
parser.add_argument("-debug", action=argparse.BooleanOptionalAction)
parser.add_argument("-searchFilter", type=str, choices=["Id", "SerialNumber", "Imei", "UserName"])
parser.add_argument("-searchValue", type=str)
parser.add_argument("-airwatchServer", type=str, default="https://apimagenta.phm.education.gouv.fr")
parser.add_argument("-airwatchAPIKey", type=str, default="")
parser.add_argument("-airwatchAPIUser", type=str, default="")
parser.add_argument("-airwatchAPIPassword", type=str, default="")
parser.add_argument("-stagingUser", type=str, default="staging-pr")
parser.add_argument("-glpiServer", type=str, default="http://127.0.0.1/glpi")
parser.add_argument("-glpiAppToken", type=str, default="")
parser.add_argument("-glpiUserToken", type=str, default="")
parser.add_argument("-force", action=argparse.BooleanOptionalAction)
args = parser.parse_args()
settingsDefault = {
"airwatchServer":"https://apimagenta.phm.education.gouv.fr",
"airwatchAPIKey":"",
"airwatchAPIUser":"",
"airwatchAPIPassword":"",
"glpiServer":"http://127.0.0.1/glpi/",
"glpiAppToken":"",
"glpiUserToken":"",
"stagingUser":"staging-pr"
}
settings = None
if(not os.path.isfile("./settings.json")):
f = open("./settings.json", "w")
f.write(json.dumps(settingsDefault, indent=4))
f.close()
exit(1)
else:
with open("./settings.json", "r") as f:
settings = json.load(f)
#======== Paramètres du script ========#
# Emplacement du verrou
lockFile = './magentaGLPIUpdate.lock'
lockFile = './airwatchSyncGLPI.lock'
debug=args.debug
# Informations du serveur Airwatch
#airwatchServer = 'https://pp-apimagenta.phm.education.gouv.fr'
airwatchServer = args.airwatchServer
airwatchAPIKey = args.airwatchAPIKey
airwatchAPIUser = args.airwatchAPIUser
airwatchAPIPassword = args.airwatchAPIPassword
stagingUser = args.stagingUser
airwatchServer = settings["airwatchServer"]
airwatchAPIKey = settings["airwatchAPIKey"]
airwatchAPIUser = settings["airwatchAPIUser"]
airwatchAPIPassword = settings["airwatchAPIPassword"]
# Informations du serveur GLPI
GLPIServer = args.glpiServer
GLPIAppToken = args.glpiAppToken
GLPIUserToken = args.glpiUserToken
GLPIServer = settings["glpiServer"]
GLPIAppToken = settings["glpiAppToken"]
GLPIUserToken = settings["glpiUserToken"]
# Filtres
searchFilter = args.searchFilter
@ -307,7 +320,7 @@ for device in devices:
continue
install_date = datetime.strptime(app["latest_uem_action_time"], "%Y-%m-%dT%H:%M:%S.%f").strftime("%Y-%m-%d")
if(install_date == "0001-01-01"):
if(install_date == "1-01-01"):
inventory["content"]["softwares"] += [{
"name": app["name"],
"guid": app["bundle_id"],