Mise à jour de env et Monitor

This commit is contained in:
2025-04-22 11:31:52 +02:00
parent a8a38a0f33
commit 742baadf99
2 changed files with 11 additions and 6 deletions

4
.env
View File

@@ -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 <cuisine@bw-paris-saclay.com>
EMAIL_MEUDON=meudon@domo91.fr
EMAIL_DEFAULT=admin@domo91.fr

View File

@@ -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"""