Branche product nettoyée : uniquement les fichiers de prod
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
import mysql.connector
|
||||
from datetime import datetime
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
# --- Config base de données ---
|
||||
config = {
|
||||
"host": "54.36.188.119",
|
||||
"user": "michel",
|
||||
"password": "#SO2&1nf%mZ@jfh",
|
||||
"database": "Sondes"
|
||||
}
|
||||
|
||||
# --- Config email ---
|
||||
def envoyer_mail(sujet, message, destinataires):
|
||||
msg = MIMEText(message, "plain", "utf-8")
|
||||
msg['Subject'] = sujet
|
||||
msg['From'] = 'alertes_saclay@domo91.fr'
|
||||
msg['To'] = ', '.join(destinataires)
|
||||
|
||||
try:
|
||||
with smtplib.SMTP_SSL('smtp.mail.ovh.net', 465) as server:
|
||||
server.login('alertes_saclay@domo91.fr', 'Kdpke674y23Feq^H')
|
||||
server.sendmail(msg['From'], destinataires, msg.as_string())
|
||||
print("📧 Mail récapitulatif envoyé avec succès.")
|
||||
except Exception as e:
|
||||
print(f"Erreur envoi mail : {e}")
|
||||
|
||||
# --- Exécution principale ---
|
||||
try:
|
||||
conn = mysql.connector.connect(**config)
|
||||
cursor = conn.cursor(dictionary=True)
|
||||
|
||||
# Rechercher toutes les tables d'alertes
|
||||
cursor.execute("SHOW TABLES LIKE 'Alertes_%'")
|
||||
tables = [list(row.values())[0] for row in cursor.fetchall()]
|
||||
|
||||
message = ""
|
||||
total_alertes = 0
|
||||
|
||||
for table in tables:
|
||||
lieu = table.replace("Alertes_", "")
|
||||
cursor.execute(f"SELECT Sonde, Debut_defaut FROM {table} WHERE Status = 'En cours'")
|
||||
alertes = cursor.fetchall()
|
||||
|
||||
if alertes:
|
||||
message += f"\n📍 **Site : {lieu}**\n"
|
||||
for alerte in alertes:
|
||||
debut = alerte['Debut_defaut'].strftime("%Y-%m-%d %H:%M")
|
||||
message += f"🔔 Sonde : {alerte['Sonde']} | Depuis : {debut}\n"
|
||||
total_alertes += len(alertes)
|
||||
|
||||
if total_alertes > 0:
|
||||
envoyer_mail(
|
||||
sujet="🚨 Récapitulatif des alertes en cours - 7h00",
|
||||
message=message,
|
||||
destinataires=["services@domo91.fr"]
|
||||
)
|
||||
else:
|
||||
print("✅ Aucune alerte en cours à 7h00.")
|
||||
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
except Exception as e:
|
||||
print(f"Erreur script alerte journalière : {e}")
|
||||
Reference in New Issue
Block a user