Ajout README Complet
This commit is contained in:
56
check_supervisor.py
Normal file
56
check_supervisor.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import subprocess
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
def envoyer_mail(sujet, message, destinataires):
|
||||
msg = MIMEText(message)
|
||||
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(f"📧 Mail envoyé à {destinataires}")
|
||||
except Exception as e:
|
||||
print(f"Erreur envoi mail : {e}")
|
||||
|
||||
# Liste des processus attendus
|
||||
processus_attendus = [
|
||||
"Chauffage",
|
||||
"Cuisine_Saclay",
|
||||
"Monitor",
|
||||
"Streamlit",
|
||||
"Telegram_sondes",
|
||||
"cuisine_meudon"
|
||||
]
|
||||
|
||||
# Commande supervisor
|
||||
output = subprocess.getoutput("supervisorctl status")
|
||||
|
||||
# Vérification
|
||||
anomalies = []
|
||||
for line in output.splitlines():
|
||||
for process in processus_attendus:
|
||||
if line.startswith(process) and "RUNNING" not in line:
|
||||
anomalies.append(line)
|
||||
|
||||
# Logs (facultatif)
|
||||
with open("/var/log/supervisor_alert.log", "a") as log:
|
||||
if anomalies:
|
||||
log.write("🚨 Anomalies détectées :\n")
|
||||
for a in anomalies:
|
||||
log.write(f"{a}\n")
|
||||
else:
|
||||
log.write("✅ Tous les processus sont OK.\n")
|
||||
|
||||
# Envoi de mail si nécessaire
|
||||
if anomalies:
|
||||
message = "\n".join(anomalies)
|
||||
envoyer_mail(
|
||||
sujet="🚨 Alerte Supervisor : processus en erreur",
|
||||
message=message,
|
||||
destinataires=["services@domo91.fr"]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user