From 742baadf99419d47a90377644ee0b3f09e3547a0 Mon Sep 17 00:00:00 2001 From: Michel Date: Tue, 22 Apr 2025 11:31:52 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20env=20et=20Monitor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 4 +++- Monitor.py | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.env b/.env index d6eb113..070422e 100644 --- a/.env +++ b/.env @@ -13,4 +13,6 @@ SMTP_PORT=465 SMTP_USER=alertes_saclay@domo91.fr SMTP_PASSWORD=Kdpke674y23Feq^H EMAIL_FROM=alertes_saclay@domo91.fr -EMAIL_DEST=services@domo91.fr +EMAIL_SACLAY=Cuisine +EMAIL_MEUDON=meudon@domo91.fr +EMAIL_DEFAULT=admin@domo91.fr diff --git a/Monitor.py b/Monitor.py index 60d51e4..dac9a76 100644 --- a/Monitor.py +++ b/Monitor.py @@ -5,6 +5,7 @@ import time import smtplib from email.mime.text import MIMEText import pandas as pd +import os # --- Config MySQL --- config = { @@ -15,17 +16,19 @@ config = { } # --- Destinataires email --- -destinataires = ['services@domo91.fr'] +def get_destinataires(lieu): + return os.getenv(f"EMAIL_{lieu.upper()}", os.getenv("EMAIL_DEFAULT")).split(",") + # --- Fonction d'envoi de mail --- def envoyer_mail(sujet, message, destinataires): msg = MIMEText(message) msg['Subject'] = sujet - msg['From'] = 'alertes_saclay@domo91.fr' + msg['From'] = os.getenv("EMAIL_FROM") msg['To'] = ', '.join(destinataires) try: - with smtplib.SMTP_SSL('smtp.mail.ovh.net', 465) as server: - server.login('alertes_saclay@domo91.fr', 'Kdpke674y23Feq^H') + with smtplib.SMTP_SSL(os.getenv("SMTP_HOST"), int(os.getenv("SMTP_PORT"))) as server: + server.login(os.getenv("SMTP_USER"), os.getenv("SMTP_PASSWORD")) server.sendmail(msg['From'], destinataires, msg.as_string()) print(f"📧 Mail envoyé à {destinataires}", flush=True) except Exception as e: @@ -92,7 +95,7 @@ def surveiller(): f"La sonde '{nom_sonde}' du site '{lieu}' a dépassé le seuil de {seuil}°C " f"depuis plus de 30 minutes.\nHeure : {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}" ) - envoyer_mail(sujet, message, destinataires) + envoyer_mail(sujet, message, get_destinataires(lieu)) # Acquittement automatique cursor.execute(f"""