Sécurisation .env + amélioration supervision Rév.7
This commit is contained in:
16
Monitor.py
16
Monitor.py
@@ -6,20 +6,22 @@ import smtplib
|
|||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import os
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
# --- Config MySQL ---
|
# --- Config MySQL ---
|
||||||
config = {
|
config = {
|
||||||
"host": "54.36.188.119",
|
"host": os.getenv("DB_HOST"),
|
||||||
"user": "michel",
|
"user": os.getenv("DB_USER"),
|
||||||
"password": "#SO2&1nf%mZ@jfh",
|
"password": os.getenv("DB_PASSWORD"),
|
||||||
"database": "Sondes"
|
"database": os.getenv("DB_NAME")
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- Destinataires email ---
|
# --- Fonction de sélection des destinataires selon le site ---
|
||||||
def get_destinataires(lieu):
|
def get_destinataires(lieu):
|
||||||
return os.getenv(f"EMAIL_{lieu.upper()}", os.getenv("EMAIL_DEFAULT")).split(",")
|
return os.getenv(f"EMAIL_{lieu.upper()}", os.getenv("EMAIL_DEFAULT")).split(",")
|
||||||
|
|
||||||
|
|
||||||
# --- Fonction d'envoi de mail ---
|
# --- Fonction d'envoi de mail ---
|
||||||
def envoyer_mail(sujet, message, destinataires):
|
def envoyer_mail(sujet, message, destinataires):
|
||||||
msg = MIMEText(message)
|
msg = MIMEText(message)
|
||||||
@@ -125,6 +127,6 @@ def surveiller():
|
|||||||
|
|
||||||
# --- Boucle principale ---
|
# --- Boucle principale ---
|
||||||
while True:
|
while True:
|
||||||
print(f"📡 Vérification à {datetime.now()}", flush=True)
|
print(f"🛁 Vérification à {datetime.now()}", flush=True)
|
||||||
surveiller()
|
surveiller()
|
||||||
time.sleep(300) # 5 minutes
|
time.sleep(300) # 5 minutes
|
||||||
|
|||||||
Reference in New Issue
Block a user