Suppression de certains paramètres de lancement et création d'un fichier de configuration à la place
This commit is contained in:
@ -3,32 +3,61 @@ import os
|
|||||||
import base64
|
import base64
|
||||||
import requests
|
import requests
|
||||||
import json
|
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 ========#
|
#======== Paramètres du script ========#
|
||||||
|
|
||||||
# Emplacement du verrou
|
# Emplacement du verrou
|
||||||
lockFile = './magentaGLPIStaging.lock'
|
lockFile = './airwatchStagingUserAssignation.lock'
|
||||||
|
|
||||||
debug=False
|
debug=args.debug
|
||||||
|
|
||||||
# Informations du serveur Airwatch
|
# Informations du serveur Airwatch
|
||||||
#airwatchServer = 'https://pp-apimagenta.phm.education.gouv.fr'
|
#airwatchServer = 'https://pp-apimagenta.phm.education.gouv.fr'
|
||||||
airwatchServer = 'https://apimagenta.phm.education.gouv.fr'
|
airwatchServer = settings["airwatchServer"]
|
||||||
airwatchAPIKey = ''
|
airwatchAPIKey = settings["airwatchAPIKey"]
|
||||||
airwatchAPIUser = ''
|
airwatchAPIUser = settings["airwatchAPIUser"]
|
||||||
airwatchAPIPassword = ''
|
airwatchAPIPassword = settings["airwatchAPIPassword"]
|
||||||
stagingUser = 'staging-pr'
|
stagingUser = settings["stagingUser"]
|
||||||
|
|
||||||
# Informations du serveur GLPI
|
# Informations du serveur GLPI
|
||||||
GLPIServer = 'http://127.0.0.1/glpi/'
|
GLPIServer = settings["glpiServer"]
|
||||||
GLPIAppToken = ''
|
GLPIAppToken = settings["glpiAppToken"]
|
||||||
GLPIUserToken = ''
|
GLPIUserToken = settings["glpiUserToken"]
|
||||||
|
|
||||||
# ====================================== #
|
# ====================================== #
|
||||||
|
|
||||||
|
|
||||||
# Vérification de la présence du verrou avant de continuer
|
# 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):
|
if(debug):
|
||||||
print('Lock file is present, exiting...')
|
print('Lock file is present, exiting...')
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|||||||
@ -11,37 +11,50 @@ parser = argparse.ArgumentParser()
|
|||||||
parser.add_argument("-debug", action=argparse.BooleanOptionalAction)
|
parser.add_argument("-debug", action=argparse.BooleanOptionalAction)
|
||||||
parser.add_argument("-searchFilter", type=str, choices=["Id", "SerialNumber", "Imei", "UserName"])
|
parser.add_argument("-searchFilter", type=str, choices=["Id", "SerialNumber", "Imei", "UserName"])
|
||||||
parser.add_argument("-searchValue", type=str)
|
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)
|
parser.add_argument("-force", action=argparse.BooleanOptionalAction)
|
||||||
|
|
||||||
args = parser.parse_args()
|
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 ========#
|
#======== Paramètres du script ========#
|
||||||
|
|
||||||
# Emplacement du verrou
|
# Emplacement du verrou
|
||||||
lockFile = './magentaGLPIUpdate.lock'
|
lockFile = './airwatchSyncGLPI.lock'
|
||||||
|
|
||||||
debug=args.debug
|
debug=args.debug
|
||||||
|
|
||||||
# Informations du serveur Airwatch
|
# Informations du serveur Airwatch
|
||||||
#airwatchServer = 'https://pp-apimagenta.phm.education.gouv.fr'
|
#airwatchServer = 'https://pp-apimagenta.phm.education.gouv.fr'
|
||||||
airwatchServer = args.airwatchServer
|
airwatchServer = settings["airwatchServer"]
|
||||||
airwatchAPIKey = args.airwatchAPIKey
|
airwatchAPIKey = settings["airwatchAPIKey"]
|
||||||
airwatchAPIUser = args.airwatchAPIUser
|
airwatchAPIUser = settings["airwatchAPIUser"]
|
||||||
airwatchAPIPassword = args.airwatchAPIPassword
|
airwatchAPIPassword = settings["airwatchAPIPassword"]
|
||||||
stagingUser = args.stagingUser
|
|
||||||
|
|
||||||
# Informations du serveur GLPI
|
# Informations du serveur GLPI
|
||||||
GLPIServer = args.glpiServer
|
GLPIServer = settings["glpiServer"]
|
||||||
GLPIAppToken = args.glpiAppToken
|
GLPIAppToken = settings["glpiAppToken"]
|
||||||
GLPIUserToken = args.glpiUserToken
|
GLPIUserToken = settings["glpiUserToken"]
|
||||||
|
|
||||||
# Filtres
|
# Filtres
|
||||||
searchFilter = args.searchFilter
|
searchFilter = args.searchFilter
|
||||||
@ -307,7 +320,7 @@ for device in devices:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
install_date = datetime.strptime(app["latest_uem_action_time"], "%Y-%m-%dT%H:%M:%S.%f").strftime("%Y-%m-%d")
|
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"] += [{
|
inventory["content"]["softwares"] += [{
|
||||||
"name": app["name"],
|
"name": app["name"],
|
||||||
"guid": app["bundle_id"],
|
"guid": app["bundle_id"],
|
||||||
|
|||||||
Reference in New Issue
Block a user