estoy iniciandome en python y estoy trabajando en un pequeño proyecto para generar diferentes reportes y uno de los que quiero generar es con loggin. tengo un archivo json el cual tiene ciertos datos y me gustaria usarlos como para interactuar con python y generar un log de acuerdo a ciertos datos. primero muestro los datos de my json file:
{
"services": [
{
"name": "ac",
"version": "1.0.8",
"service": "running",
"url": "https://portal.azure.com/#home",
"disk usage": "20%"
},
{
"name": "acc",
"version": "1.0.8",
"service": "running",
"url": "https://portal.azure.com/#home",
"disk usage": "63%"
},
{
"name": "acv",
"version": "1.0.8",
"service": "running",
"url": "https://portal.azure.com/#home",
"disk usage": "37%"
},
{
"name": "acf",
"version": "1.0.8",
"service": "running",
"url": "https://portal.azure.com/#home",
"disk usage": "48%"
},
{
"name": "ach",
"version": "1.0.8",
"service": "error",
"url": "https://portal.azure.com/#home",
"disk usage": "10%"
},
{
"name": "acj",
"version": "1.0.8",
"service": "stopped",
"url": "https://portal.azure.com/#home",
"disk usage": "23%"
},
{
"name": "acq",
"version": "1.0.8",
"service": "running",
"url": "https://portal.azure.com/#home",
"disk usage": "65%"
},
{
"name": "bc",
"version": "1.0.8",
"service": "stopped",
"url": "https://portal.azure.com/#home",
"disk usage": "20%"
},
{
"name": "bcc",
"version": "1.0.8",
"service": "running",
"url": "https://portal.azure.com/#home",
"disk usage": "25%"
},
{
"name": "bcx",
"version": "1.0.8",
"service": "error",
"url": "https://portal.azure.com/#home",
"disk usage": "4%"
},
{
"name": "bcn",
"version": "1.0.8",
"service": "running",
"url": "https://portal.azure.com/#home",
"disk usage": "50%"
},
{
"name": "bcm",
"version": "1.0.8",
"service": "stopped",
"url": "https://portal.azure.com/#home",
"disk usage": "35%"
}
]
}
he creado una parte del codigo para generar un archivo log y le he seteado algunos mensajes, lo que no se como hacer es por ejemplo si el uso del disco es mayor a 40% salga un warning o si es mayor a 50% tire algun error o critical.
import logging
import json
# Logger configuration
LOG_FORMAT = "%(levelname)s %(asctime)s - %(message)s"
logging.basicConfig(filename= r"C:\Users\Maximiliano\Documents\TrainingProject\Monitoring.log",
level= logging.DEBUG,
format=LOG_FORMAT,
filemode='w')
logger = logging.getLogger()
#Messages
logger.debug("Debuggin services...")
logger.info("The service is health")
logger.warning("A service reboot will be good")
logger.error("Some Services are not working correctly")
logger.critical("service DOWN!!!")
#set up json file
def get_data():
with open('services.json') as f:
data = json.load(f)
return data
data = get_data()
agradezco su ayuda.