feat: init projet supervision — monitoring systeme Windows
Interface web Flask securisee pour surveiller CPU, RAM, disques et processus (JVM, Nginx, Amadea Web 8 x64). Alertes email SMTP configurables, seuils reglables, compilation PyInstaller en .exe, installation service Windows via NSSM. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.venv/
|
||||
venv/
|
||||
data/config.json
|
||||
data/alerts.json
|
||||
*.log
|
||||
.env
|
||||
imput/
|
||||
*.spec
|
||||
build/
|
||||
dist/
|
||||
180
README.md
Normal file
180
README.md
Normal file
@@ -0,0 +1,180 @@
|
||||
# Supervision — Monitoring Systeme Windows
|
||||
|
||||
Outil de surveillance systeme avec interface web securisee.
|
||||
Surveille CPU, RAM, disques et processus specifiques (JVM, Nginx, Amadea Web 8 x64).
|
||||
Envoie des alertes email lorsque les seuils configures sont depasses.
|
||||
|
||||
---
|
||||
|
||||
## Fonctionnalites
|
||||
|
||||
- **Dashboard temps reel** : CPU, RAM, disques, processus surveilles (rafraichissement auto)
|
||||
- **Alertes email** : envoi automatique quand un seuil est depasse, avec cooldown anti-spam
|
||||
- **Configuration complete via l'interface** :
|
||||
- Seuils d'alerte (CPU, RAM, disque)
|
||||
- Frequence de verification (en minutes)
|
||||
- Serveur SMTP + test d'envoi integre
|
||||
- Ajout/suppression de processus a surveiller
|
||||
- Port de l'application
|
||||
- Mot de passe administrateur
|
||||
- **Securite** : authentification par login/mot de passe, rate limiting anti-bruteforce, en-tetes HTTP securises
|
||||
- **Historique des alertes** consultable dans l'interface
|
||||
|
||||
---
|
||||
|
||||
## Installation rapide (executable)
|
||||
|
||||
### Pre-requis
|
||||
|
||||
- Windows 10/11 ou Windows Server 2016+
|
||||
- Acces administrateur (pour le firewall et l'installation en service)
|
||||
|
||||
### Etapes
|
||||
|
||||
1. **Dezipper** `supervision_portable.zip` dans un dossier, par exemple :
|
||||
```
|
||||
C:\supervision\
|
||||
```
|
||||
|
||||
2. **Lancer** l'executable :
|
||||
```
|
||||
C:\supervision\supervision.exe
|
||||
```
|
||||
|
||||
3. **Ouvrir le navigateur** a l'adresse :
|
||||
```
|
||||
http://localhost:5000
|
||||
```
|
||||
|
||||
4. **Se connecter** avec les identifiants par defaut :
|
||||
- Identifiant : `admin`
|
||||
- Mot de passe : `admin`
|
||||
|
||||
5. **Changer le mot de passe** immediatement dans Configuration > Mot de passe administrateur
|
||||
|
||||
6. **Configurer le SMTP** dans Configuration > Configuration SMTP, puis cliquer sur "Envoyer un email de test" pour valider
|
||||
|
||||
7. **Ajuster les seuils** si necessaire (valeurs par defaut : CPU 90%, RAM 85%, Disque 90%)
|
||||
|
||||
---
|
||||
|
||||
## Acces distant
|
||||
|
||||
Pour acceder a l'interface depuis une autre machine :
|
||||
|
||||
1. **Ouvrir le port dans le firewall Windows** (PowerShell en administrateur) :
|
||||
```powershell
|
||||
New-NetFirewallRule -DisplayName "Supervision Monitoring" -Direction Inbound -LocalPort 5000 -Protocol TCP -Action Allow
|
||||
```
|
||||
|
||||
2. Acceder via : `http://<adresse-ip-du-serveur>:5000`
|
||||
|
||||
> **Recommandation** : pour un acces depuis internet, placer l'application derriere un reverse proxy (IIS, Nginx) avec HTTPS.
|
||||
|
||||
---
|
||||
|
||||
## Installation en tant que service Windows
|
||||
|
||||
Pour que Supervision demarre automatiquement avec Windows, utiliser [NSSM](https://nssm.cc/) :
|
||||
|
||||
1. Telecharger NSSM et le placer dans le PATH
|
||||
|
||||
2. Executer en administrateur :
|
||||
```cmd
|
||||
nssm install Supervision "C:\supervision\supervision.exe"
|
||||
nssm set Supervision AppDirectory "C:\supervision"
|
||||
nssm set Supervision Description "Monitoring systeme - Supervision"
|
||||
nssm set Supervision Start SERVICE_AUTO_START
|
||||
nssm start Supervision
|
||||
```
|
||||
|
||||
3. Gestion du service :
|
||||
```cmd
|
||||
nssm start Supervision
|
||||
nssm stop Supervision
|
||||
nssm restart Supervision
|
||||
nssm remove Supervision confirm
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Installation depuis les sources (developpement)
|
||||
|
||||
### Pre-requis
|
||||
|
||||
- Python 3.10 ou superieur
|
||||
|
||||
### Etapes
|
||||
|
||||
1. Creer l'environnement virtuel et installer les dependances :
|
||||
```cmd
|
||||
cd C:\supervision
|
||||
python -m venv .venv
|
||||
.venv\Scripts\pip.exe install -r requirements.txt
|
||||
```
|
||||
|
||||
2. Lancer :
|
||||
```cmd
|
||||
.venv\Scripts\python.exe app.py
|
||||
```
|
||||
|
||||
### Compiler en executable
|
||||
|
||||
```cmd
|
||||
.venv\Scripts\pip.exe install pyinstaller
|
||||
.venv\Scripts\pyinstaller.exe --name supervision --onedir --add-data "templates;templates" --add-data "static;static" --hidden-import flask --hidden-import flask_login --hidden-import flask_limiter --hidden-import psutil --noconfirm app.py
|
||||
```
|
||||
|
||||
L'executable est genere dans `dist\supervision\`.
|
||||
|
||||
---
|
||||
|
||||
## Structure des fichiers
|
||||
|
||||
```
|
||||
supervision\
|
||||
├── supervision.exe # Executable principal
|
||||
├── _internal\ # Dependances Python embarquees
|
||||
├── templates\ # Pages HTML de l'interface
|
||||
├── static\ # CSS
|
||||
└── data\ # (cree au 1er lancement)
|
||||
├── config.json # Configuration (seuils, SMTP, processus)
|
||||
└── alerts.json # Historique des alertes
|
||||
```
|
||||
|
||||
> **Important** : ne pas supprimer le dossier `_internal\`, il est necessaire au fonctionnement.
|
||||
|
||||
---
|
||||
|
||||
## Configuration par defaut
|
||||
|
||||
| Parametre | Valeur par defaut |
|
||||
|--------------------------|-------------------|
|
||||
| Port | 5000 |
|
||||
| Intervalle de check | 1 minute |
|
||||
| Cooldown entre alertes | 30 minutes |
|
||||
| Seuil CPU | 90% |
|
||||
| Seuil RAM | 85% |
|
||||
| Seuil Disque | 90% |
|
||||
|
||||
### Processus surveilles par defaut
|
||||
|
||||
| Nom | Pattern de recherche | Alerte si arrete |
|
||||
|--------------------|----------------------|------------------|
|
||||
| JVM | java | Oui |
|
||||
| Nginx | nginx | Non (desactive) |
|
||||
| Amadea Web 8 x64 | amadea | Oui |
|
||||
|
||||
Tous les parametres sont modifiables depuis l'interface web.
|
||||
|
||||
---
|
||||
|
||||
## Depannage
|
||||
|
||||
| Probleme | Solution |
|
||||
|----------|----------|
|
||||
| "Le port 5000 est deja utilise" | Changer le port dans `data\config.json` ou fermer le programme qui occupe le port |
|
||||
| Impossible de se connecter a distance | Verifier la regle firewall (port 5000 TCP entrant) |
|
||||
| Pas d'email recu | Verifier la configuration SMTP et utiliser le bouton "Envoyer un email de test" |
|
||||
| Mot de passe oublie | Supprimer `data\config.json` et relancer (reinitialise a admin/admin) |
|
||||
| L'executable ne se lance pas | Verifier que le dossier `_internal\` est present a cote de `supervision.exe` |
|
||||
81
alerter.py
Normal file
81
alerter.py
Normal file
@@ -0,0 +1,81 @@
|
||||
"""Envoi d'alertes par email via SMTP."""
|
||||
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
|
||||
|
||||
class EmailAlerter:
|
||||
def __init__(self, config_manager):
|
||||
self.config = config_manager
|
||||
|
||||
def _get_smtp_config(self):
|
||||
return self.config.get("smtp", {})
|
||||
|
||||
def is_configured(self):
|
||||
smtp = self._get_smtp_config()
|
||||
return bool(smtp.get("server") and smtp.get("from_email") and smtp.get("to_emails"))
|
||||
|
||||
def send_alert(self, subject, body):
|
||||
"""Envoie un email d'alerte. Silencieux si SMTP non configure."""
|
||||
if not self.is_configured():
|
||||
return False, "SMTP non configure"
|
||||
return self._send_email(subject, body)
|
||||
|
||||
def send_test(self):
|
||||
"""Envoie un email de test pour valider la configuration SMTP."""
|
||||
if not self.is_configured():
|
||||
return False, "Configuration SMTP incomplete"
|
||||
subject = "[TEST] Supervision - Test de configuration email"
|
||||
body = (
|
||||
"Ceci est un email de test.\n\n"
|
||||
"Si vous recevez ce message, la configuration SMTP est correcte.\n\n"
|
||||
"-- Supervision"
|
||||
)
|
||||
return self._send_email(subject, body)
|
||||
|
||||
def _send_email(self, subject, body):
|
||||
smtp_cfg = self._get_smtp_config()
|
||||
try:
|
||||
msg = MIMEMultipart()
|
||||
msg["From"] = smtp_cfg["from_email"]
|
||||
msg["To"] = ", ".join(smtp_cfg["to_emails"])
|
||||
msg["Subject"] = subject
|
||||
msg.attach(MIMEText(body, "plain", "utf-8"))
|
||||
|
||||
server_addr = smtp_cfg["server"]
|
||||
port = int(smtp_cfg.get("port", 587))
|
||||
use_tls = smtp_cfg.get("use_tls", True)
|
||||
|
||||
if use_tls:
|
||||
server = smtplib.SMTP(server_addr, port, timeout=15)
|
||||
server.ehlo()
|
||||
server.starttls()
|
||||
server.ehlo()
|
||||
else:
|
||||
server = smtplib.SMTP(server_addr, port, timeout=15)
|
||||
server.ehlo()
|
||||
|
||||
username = smtp_cfg.get("username", "")
|
||||
password = smtp_cfg.get("password", "")
|
||||
if username and password:
|
||||
server.login(username, password)
|
||||
|
||||
server.sendmail(
|
||||
smtp_cfg["from_email"],
|
||||
smtp_cfg["to_emails"],
|
||||
msg.as_string(),
|
||||
)
|
||||
server.quit()
|
||||
return True, "Email envoye avec succes"
|
||||
|
||||
except smtplib.SMTPAuthenticationError:
|
||||
return False, "Erreur d'authentification SMTP (identifiants incorrects)"
|
||||
except smtplib.SMTPConnectError:
|
||||
return False, f"Impossible de se connecter au serveur SMTP {server_addr}:{port}"
|
||||
except smtplib.SMTPRecipientsRefused:
|
||||
return False, "Destinataire(s) refuse(s) par le serveur"
|
||||
except TimeoutError:
|
||||
return False, f"Timeout de connexion vers {server_addr}:{port}"
|
||||
except Exception as e:
|
||||
return False, f"Erreur SMTP: {str(e)}"
|
||||
350
app.py
Normal file
350
app.py
Normal file
@@ -0,0 +1,350 @@
|
||||
"""Supervision — Monitoring systeme avec interface web."""
|
||||
|
||||
import socket
|
||||
import sys
|
||||
from datetime import timedelta
|
||||
from functools import wraps
|
||||
|
||||
from flask import (
|
||||
Flask, render_template, request, redirect, url_for,
|
||||
flash, jsonify, session,
|
||||
)
|
||||
from flask_login import (
|
||||
LoginManager, UserMixin, login_user, logout_user,
|
||||
login_required, current_user,
|
||||
)
|
||||
from flask_limiter import Limiter
|
||||
from flask_limiter.util import get_remote_address
|
||||
from werkzeug.security import check_password_hash, generate_password_hash
|
||||
|
||||
from config_manager import ConfigManager
|
||||
from monitor import SystemMonitor
|
||||
from alerter import EmailAlerter
|
||||
|
||||
# --- Init ---
|
||||
config = ConfigManager()
|
||||
app = Flask(__name__)
|
||||
app.secret_key = config.get("secret_key")
|
||||
app.permanent_session_lifetime = timedelta(hours=8)
|
||||
|
||||
# En-tetes de securite
|
||||
@app.after_request
|
||||
def security_headers(response):
|
||||
response.headers["X-Content-Type-Options"] = "nosniff"
|
||||
response.headers["X-Frame-Options"] = "DENY"
|
||||
response.headers["X-XSS-Protection"] = "1; mode=block"
|
||||
response.headers["Referrer-Policy"] = "strict-origin-when-cross-origin"
|
||||
return response
|
||||
|
||||
# Rate limiting
|
||||
limiter = Limiter(
|
||||
app=app,
|
||||
key_func=get_remote_address,
|
||||
default_limits=[],
|
||||
storage_uri="memory://",
|
||||
)
|
||||
|
||||
# Flask-Login
|
||||
login_manager = LoginManager()
|
||||
login_manager.init_app(app)
|
||||
login_manager.login_view = "login"
|
||||
login_manager.login_message = "Veuillez vous connecter."
|
||||
|
||||
# Services
|
||||
alerter = EmailAlerter(config)
|
||||
monitor = SystemMonitor(config, alerter)
|
||||
|
||||
|
||||
class AdminUser(UserMixin):
|
||||
def __init__(self, username):
|
||||
self.id = username
|
||||
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id):
|
||||
admin = config.get("admin", {})
|
||||
if user_id == admin.get("username"):
|
||||
return AdminUser(user_id)
|
||||
return None
|
||||
|
||||
|
||||
def is_default_password():
|
||||
admin = config.get("admin", {})
|
||||
return check_password_hash(admin.get("password_hash", ""), "admin")
|
||||
|
||||
|
||||
# --- Routes ---
|
||||
|
||||
@app.route("/login", methods=["GET", "POST"])
|
||||
@limiter.limit("10 per minute")
|
||||
def login():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for("dashboard"))
|
||||
if request.method == "POST":
|
||||
username = request.form.get("username", "").strip()
|
||||
password = request.form.get("password", "")
|
||||
admin = config.get("admin", {})
|
||||
if username == admin.get("username") and check_password_hash(
|
||||
admin.get("password_hash", ""), password
|
||||
):
|
||||
user = AdminUser(username)
|
||||
login_user(user, remember=True)
|
||||
session.permanent = True
|
||||
next_page = request.args.get("next")
|
||||
return redirect(next_page or url_for("dashboard"))
|
||||
flash("Identifiants incorrects.", "danger")
|
||||
return render_template("login.html")
|
||||
|
||||
|
||||
@app.route("/logout")
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for("login"))
|
||||
|
||||
|
||||
@app.route("/")
|
||||
@login_required
|
||||
def dashboard():
|
||||
metrics = monitor.metrics
|
||||
default_pw = is_default_password()
|
||||
return render_template("dashboard.html", metrics=metrics, default_pw=default_pw)
|
||||
|
||||
|
||||
@app.route("/api/metrics")
|
||||
@login_required
|
||||
def api_metrics():
|
||||
return jsonify(monitor.metrics)
|
||||
|
||||
|
||||
@app.route("/settings", methods=["GET"])
|
||||
@login_required
|
||||
def settings():
|
||||
cfg = config.config
|
||||
smtp = cfg.get("smtp", {})
|
||||
# Masquer le mot de passe SMTP dans l'affichage
|
||||
smtp_display = dict(smtp)
|
||||
if smtp_display.get("password"):
|
||||
smtp_display["password_masked"] = "*" * 8
|
||||
else:
|
||||
smtp_display["password_masked"] = ""
|
||||
return render_template(
|
||||
"settings.html",
|
||||
config=cfg,
|
||||
smtp=smtp_display,
|
||||
default_pw=is_default_password(),
|
||||
)
|
||||
|
||||
|
||||
@app.route("/settings/thresholds", methods=["POST"])
|
||||
@login_required
|
||||
def update_thresholds():
|
||||
try:
|
||||
thresholds = {
|
||||
"cpu_percent": int(request.form["cpu_percent"]),
|
||||
"ram_percent": int(request.form["ram_percent"]),
|
||||
"disk_percent": int(request.form["disk_percent"]),
|
||||
}
|
||||
# Validation: seuils entre 1 et 100
|
||||
for key, val in thresholds.items():
|
||||
if not 1 <= val <= 100:
|
||||
flash(f"Le seuil {key} doit etre entre 1 et 100.", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
config.set("thresholds", thresholds)
|
||||
flash("Seuils mis a jour.", "success")
|
||||
except (ValueError, KeyError) as e:
|
||||
flash(f"Erreur de validation: {e}", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
|
||||
|
||||
@app.route("/settings/monitoring", methods=["POST"])
|
||||
@login_required
|
||||
def update_monitoring():
|
||||
try:
|
||||
interval = int(request.form["check_interval_minutes"])
|
||||
cooldown = int(request.form["alert_cooldown_minutes"])
|
||||
if interval < 1:
|
||||
flash("L'intervalle doit etre d'au moins 1 minute.", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
if cooldown < 1:
|
||||
flash("Le cooldown doit etre d'au moins 1 minute.", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
config.set("check_interval_minutes", interval)
|
||||
config.set("alert_cooldown_minutes", cooldown)
|
||||
flash("Parametres de monitoring mis a jour.", "success")
|
||||
except (ValueError, KeyError) as e:
|
||||
flash(f"Erreur: {e}", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
|
||||
|
||||
@app.route("/settings/smtp", methods=["POST"])
|
||||
@login_required
|
||||
def update_smtp():
|
||||
try:
|
||||
smtp = {
|
||||
"server": request.form["smtp_server"].strip(),
|
||||
"port": int(request.form["smtp_port"]),
|
||||
"use_tls": "smtp_tls" in request.form,
|
||||
"username": request.form["smtp_username"].strip(),
|
||||
"from_email": request.form["smtp_from"].strip(),
|
||||
"to_emails": [
|
||||
e.strip() for e in request.form["smtp_to"].split(",") if e.strip()
|
||||
],
|
||||
}
|
||||
# Ne mettre a jour le mot de passe que s'il est fourni
|
||||
new_password = request.form.get("smtp_password", "")
|
||||
if new_password:
|
||||
smtp["password"] = new_password
|
||||
else:
|
||||
# Garder l'ancien mot de passe
|
||||
old_smtp = config.get("smtp", {})
|
||||
smtp["password"] = old_smtp.get("password", "")
|
||||
|
||||
config.set("smtp", smtp)
|
||||
flash("Configuration SMTP mise a jour.", "success")
|
||||
except (ValueError, KeyError) as e:
|
||||
flash(f"Erreur: {e}", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
|
||||
|
||||
@app.route("/settings/smtp/test", methods=["POST"])
|
||||
@login_required
|
||||
def test_smtp():
|
||||
success, message = alerter.send_test()
|
||||
if success:
|
||||
flash(f"Test reussi : {message}", "success")
|
||||
else:
|
||||
flash(f"Test echoue : {message}", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
|
||||
|
||||
@app.route("/settings/processes", methods=["POST"])
|
||||
@login_required
|
||||
def update_processes():
|
||||
try:
|
||||
processes = []
|
||||
names = request.form.getlist("proc_name[]")
|
||||
patterns = request.form.getlist("proc_pattern[]")
|
||||
mem_thresholds = request.form.getlist("proc_mem_threshold[]")
|
||||
enableds = request.form.getlist("proc_enabled[]")
|
||||
alert_downs = request.form.getlist("proc_alert_down[]")
|
||||
|
||||
for i in range(len(names)):
|
||||
if not names[i].strip():
|
||||
continue
|
||||
processes.append({
|
||||
"name": names[i].strip(),
|
||||
"pattern": patterns[i].strip().lower() if i < len(patterns) else "",
|
||||
"memory_threshold_mb": int(mem_thresholds[i]) if i < len(mem_thresholds) and mem_thresholds[i] else 0,
|
||||
"enabled": str(i) in enableds,
|
||||
"alert_on_down": str(i) in alert_downs,
|
||||
})
|
||||
config.set("processes", processes)
|
||||
flash("Processus surveilles mis a jour.", "success")
|
||||
except (ValueError, KeyError) as e:
|
||||
flash(f"Erreur: {e}", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
|
||||
|
||||
@app.route("/settings/password", methods=["POST"])
|
||||
@login_required
|
||||
def update_password():
|
||||
current_pw = request.form.get("current_password", "")
|
||||
new_pw = request.form.get("new_password", "")
|
||||
confirm_pw = request.form.get("confirm_password", "")
|
||||
|
||||
admin = config.get("admin", {})
|
||||
if not check_password_hash(admin.get("password_hash", ""), current_pw):
|
||||
flash("Mot de passe actuel incorrect.", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
if len(new_pw) < 8:
|
||||
flash("Le nouveau mot de passe doit faire au moins 8 caracteres.", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
if new_pw != confirm_pw:
|
||||
flash("Les mots de passe ne correspondent pas.", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
|
||||
admin["password_hash"] = generate_password_hash(new_pw)
|
||||
config.set("admin", admin)
|
||||
flash("Mot de passe mis a jour.", "success")
|
||||
return redirect(url_for("settings"))
|
||||
|
||||
|
||||
@app.route("/settings/port", methods=["POST"])
|
||||
@login_required
|
||||
def update_port():
|
||||
try:
|
||||
port = int(request.form["port"])
|
||||
if not 1024 <= port <= 65535:
|
||||
flash("Le port doit etre entre 1024 et 65535.", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
config.set("port", port)
|
||||
flash(f"Port mis a jour a {port}. Redemarrez l'application pour appliquer.", "warning")
|
||||
except (ValueError, KeyError):
|
||||
flash("Port invalide.", "danger")
|
||||
return redirect(url_for("settings"))
|
||||
|
||||
|
||||
@app.route("/alerts")
|
||||
@login_required
|
||||
def alerts():
|
||||
alert_list = config.load_alerts()
|
||||
return render_template("alerts.html", alerts=alert_list)
|
||||
|
||||
|
||||
@app.route("/alerts/clear", methods=["POST"])
|
||||
@login_required
|
||||
def clear_alerts():
|
||||
config.clear_alerts()
|
||||
flash("Historique des alertes efface.", "success")
|
||||
return redirect(url_for("alerts"))
|
||||
|
||||
|
||||
@app.route("/api/monitoring/toggle", methods=["POST"])
|
||||
@login_required
|
||||
def toggle_monitoring():
|
||||
if monitor._running:
|
||||
monitor.stop()
|
||||
flash("Monitoring arrete.", "warning")
|
||||
else:
|
||||
monitor.start()
|
||||
flash("Monitoring demarre.", "success")
|
||||
return redirect(url_for("dashboard"))
|
||||
|
||||
|
||||
def check_port_available(port):
|
||||
"""Verifie si un port est disponible."""
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
try:
|
||||
s.bind(("0.0.0.0", port))
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
port = config.get("port", 5000)
|
||||
|
||||
if not check_port_available(port):
|
||||
print(f"[ERREUR] Le port {port} est deja utilise.")
|
||||
print("Modifiez le port dans data/config.json ou liberez le port.")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"[Supervision] Demarrage sur le port {port}")
|
||||
print(f"[Supervision] Interface : http://localhost:{port}")
|
||||
|
||||
if is_default_password():
|
||||
print("[ATTENTION] Le mot de passe admin est encore 'admin'. Changez-le immediatement !")
|
||||
|
||||
# Demarrer le monitoring
|
||||
monitor.start()
|
||||
# Collecte initiale
|
||||
monitor.collect_metrics()
|
||||
|
||||
print("[Supervision] Monitoring actif")
|
||||
|
||||
app.run(host="0.0.0.0", port=port, debug=False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
27
build.bat
Normal file
27
build.bat
Normal file
@@ -0,0 +1,27 @@
|
||||
@echo off
|
||||
title Build Supervision .exe
|
||||
echo ==========================================
|
||||
echo Build Supervision en executable
|
||||
echo ==========================================
|
||||
echo.
|
||||
|
||||
call .venv\Scripts\activate.bat
|
||||
|
||||
echo [INFO] Compilation avec PyInstaller...
|
||||
pyinstaller ^
|
||||
--name supervision ^
|
||||
--onedir ^
|
||||
--add-data "templates;templates" ^
|
||||
--add-data "static;static" ^
|
||||
--hidden-import flask ^
|
||||
--hidden-import flask_login ^
|
||||
--hidden-import flask_limiter ^
|
||||
--hidden-import psutil ^
|
||||
--noconfirm ^
|
||||
app.py
|
||||
|
||||
echo.
|
||||
echo [OK] Executable genere dans dist\supervision\
|
||||
echo [INFO] Copiez le dossier dist\supervision\ sur le serveur cible.
|
||||
echo [INFO] Le dossier data\ sera cree automatiquement au premier lancement.
|
||||
pause
|
||||
126
config_manager.py
Normal file
126
config_manager.py
Normal file
@@ -0,0 +1,126 @@
|
||||
"""Gestion de la configuration persistante (JSON)."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
DATA_DIR = Path(__file__).parent / "data"
|
||||
CONFIG_FILE = DATA_DIR / "config.json"
|
||||
ALERTS_FILE = DATA_DIR / "alerts.json"
|
||||
MAX_ALERTS = 500
|
||||
|
||||
|
||||
def get_default_config():
|
||||
return {
|
||||
"secret_key": secrets.token_hex(32),
|
||||
"port": 5000,
|
||||
"check_interval_minutes": 1,
|
||||
"alert_cooldown_minutes": 30,
|
||||
"thresholds": {
|
||||
"cpu_percent": 90,
|
||||
"ram_percent": 85,
|
||||
"disk_percent": 90,
|
||||
},
|
||||
"processes": [
|
||||
{
|
||||
"name": "JVM",
|
||||
"pattern": "java",
|
||||
"memory_threshold_mb": 0,
|
||||
"enabled": True,
|
||||
"alert_on_down": True,
|
||||
},
|
||||
{
|
||||
"name": "Nginx",
|
||||
"pattern": "nginx",
|
||||
"memory_threshold_mb": 0,
|
||||
"enabled": False,
|
||||
"alert_on_down": False,
|
||||
},
|
||||
{
|
||||
"name": "Amadea Web 8 x64",
|
||||
"pattern": "amadea",
|
||||
"memory_threshold_mb": 0,
|
||||
"enabled": True,
|
||||
"alert_on_down": True,
|
||||
},
|
||||
],
|
||||
"smtp": {
|
||||
"server": "",
|
||||
"port": 587,
|
||||
"use_tls": True,
|
||||
"username": "",
|
||||
"password": "",
|
||||
"from_email": "",
|
||||
"to_emails": [],
|
||||
},
|
||||
"admin": {
|
||||
"username": "admin",
|
||||
"password_hash": generate_password_hash("admin"),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class ConfigManager:
|
||||
def __init__(self):
|
||||
DATA_DIR.mkdir(exist_ok=True)
|
||||
self._config = self._load()
|
||||
|
||||
def _load(self):
|
||||
if CONFIG_FILE.exists():
|
||||
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
|
||||
saved = json.load(f)
|
||||
# Fusionner avec les valeurs par defaut (nouvelles cles)
|
||||
default = get_default_config()
|
||||
for key, val in default.items():
|
||||
if key not in saved:
|
||||
saved[key] = val
|
||||
return saved
|
||||
else:
|
||||
config = get_default_config()
|
||||
self._save(config)
|
||||
return config
|
||||
|
||||
def _save(self, config=None):
|
||||
if config is None:
|
||||
config = self._config
|
||||
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=2, ensure_ascii=False)
|
||||
|
||||
def reload(self):
|
||||
self._config = self._load()
|
||||
|
||||
def get(self, key, default=None):
|
||||
return self._config.get(key, default)
|
||||
|
||||
def set(self, key, value):
|
||||
self._config[key] = value
|
||||
self._save()
|
||||
|
||||
def update(self, data: dict):
|
||||
self._config.update(data)
|
||||
self._save()
|
||||
|
||||
@property
|
||||
def config(self):
|
||||
return self._config
|
||||
|
||||
# --- Alertes persistees ---
|
||||
|
||||
def load_alerts(self):
|
||||
if ALERTS_FILE.exists():
|
||||
with open(ALERTS_FILE, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
return []
|
||||
|
||||
def save_alert(self, alert: dict):
|
||||
alerts = self.load_alerts()
|
||||
alerts.insert(0, alert)
|
||||
alerts = alerts[:MAX_ALERTS]
|
||||
with open(ALERTS_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump(alerts, f, indent=2, ensure_ascii=False)
|
||||
|
||||
def clear_alerts(self):
|
||||
with open(ALERTS_FILE, "w", encoding="utf-8") as f:
|
||||
json.dump([], f)
|
||||
41
install_service.bat
Normal file
41
install_service.bat
Normal file
@@ -0,0 +1,41 @@
|
||||
@echo off
|
||||
title Installation Service Windows
|
||||
echo ==========================================
|
||||
echo Installation de Supervision en service
|
||||
echo ==========================================
|
||||
echo.
|
||||
echo PRE-REQUIS: NSSM (https://nssm.cc/) doit etre dans le PATH
|
||||
echo.
|
||||
|
||||
REM Verifier les droits admin
|
||||
net session >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERREUR] Ce script doit etre execute en tant qu'administrateur.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set SERVICE_NAME=Supervision
|
||||
set /p INSTALL_PATH="Chemin du dossier supervision (ex: C:\supervision): "
|
||||
|
||||
echo.
|
||||
echo [INFO] Installation du service '%SERVICE_NAME%'...
|
||||
nssm install %SERVICE_NAME% "%INSTALL_PATH%\supervision.exe"
|
||||
nssm set %SERVICE_NAME% AppDirectory "%INSTALL_PATH%"
|
||||
nssm set %SERVICE_NAME% Description "Monitoring systeme - Supervision"
|
||||
nssm set %SERVICE_NAME% Start SERVICE_AUTO_START
|
||||
nssm set %SERVICE_NAME% AppStdout "%INSTALL_PATH%\logs\stdout.log"
|
||||
nssm set %SERVICE_NAME% AppStderr "%INSTALL_PATH%\logs\stderr.log"
|
||||
nssm set %SERVICE_NAME% AppRotateFiles 1
|
||||
nssm set %SERVICE_NAME% AppRotateBytes 5000000
|
||||
|
||||
mkdir "%INSTALL_PATH%\logs" 2>nul
|
||||
|
||||
echo.
|
||||
echo [OK] Service installe. Demarrage...
|
||||
nssm start %SERVICE_NAME%
|
||||
|
||||
echo.
|
||||
echo [INFO] Le service demarre automatiquement avec Windows.
|
||||
echo [INFO] Gestion: nssm start/stop/restart %SERVICE_NAME%
|
||||
pause
|
||||
291
monitor.py
Normal file
291
monitor.py
Normal file
@@ -0,0 +1,291 @@
|
||||
"""Collecte des metriques systeme et surveillance des seuils."""
|
||||
|
||||
import platform
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import psutil
|
||||
|
||||
|
||||
class SystemMonitor:
|
||||
def __init__(self, config_manager, alerter):
|
||||
self.config = config_manager
|
||||
self.alerter = alerter
|
||||
self._metrics = {}
|
||||
self._lock = threading.Lock()
|
||||
self._running = False
|
||||
self._thread = None
|
||||
self._last_alerts = {} # cle -> datetime derniere alerte
|
||||
|
||||
@property
|
||||
def metrics(self):
|
||||
with self._lock:
|
||||
return dict(self._metrics)
|
||||
|
||||
def collect_metrics(self):
|
||||
"""Collecte toutes les metriques systeme."""
|
||||
cfg = self.config.config
|
||||
thresholds = cfg["thresholds"]
|
||||
|
||||
# CPU
|
||||
cpu_percent = psutil.cpu_percent(interval=1)
|
||||
cpu_status = self._eval_status(cpu_percent, thresholds["cpu_percent"])
|
||||
|
||||
# RAM
|
||||
ram = psutil.virtual_memory()
|
||||
ram_status = self._eval_status(ram.percent, thresholds["ram_percent"])
|
||||
|
||||
# Disques
|
||||
disks = []
|
||||
IGNORED_FS = {"squashfs", "tmpfs", "devtmpfs", "overlay", "iso9660"}
|
||||
for part in psutil.disk_partitions():
|
||||
# Ignorer les pseudo-filesystems (loop, snap, tmpfs, etc.)
|
||||
if part.fstype in IGNORED_FS:
|
||||
continue
|
||||
if part.device.startswith("/dev/loop"):
|
||||
continue
|
||||
try:
|
||||
usage = psutil.disk_usage(part.mountpoint)
|
||||
except (PermissionError, OSError):
|
||||
continue
|
||||
# Ignorer les partitions minuscules (< 1 Go)
|
||||
if usage.total < 1024 ** 3:
|
||||
continue
|
||||
disk_status = self._eval_status(usage.percent, thresholds["disk_percent"])
|
||||
disks.append({
|
||||
"drive": part.device.rstrip("\\"),
|
||||
"mountpoint": part.mountpoint,
|
||||
"percent": round(usage.percent, 1),
|
||||
"total_gb": round(usage.total / (1024 ** 3), 1),
|
||||
"used_gb": round(usage.used / (1024 ** 3), 1),
|
||||
"free_gb": round(usage.free / (1024 ** 3), 1),
|
||||
"threshold": thresholds["disk_percent"],
|
||||
"status": disk_status,
|
||||
})
|
||||
|
||||
# Processus surveilles
|
||||
processes = self._check_processes(cfg.get("processes", []))
|
||||
|
||||
# Infos systeme
|
||||
boot_time = datetime.fromtimestamp(psutil.boot_time())
|
||||
uptime = datetime.now() - boot_time
|
||||
|
||||
now = datetime.now()
|
||||
interval = cfg.get("check_interval_minutes", 1)
|
||||
|
||||
metrics = {
|
||||
"timestamp": now.isoformat(),
|
||||
"hostname": platform.node(),
|
||||
"os": f"{platform.system()} {platform.release()}",
|
||||
"cpu": {
|
||||
"percent": cpu_percent,
|
||||
"cores": psutil.cpu_count(),
|
||||
"threshold": thresholds["cpu_percent"],
|
||||
"status": cpu_status,
|
||||
},
|
||||
"ram": {
|
||||
"percent": round(ram.percent, 1),
|
||||
"total_gb": round(ram.total / (1024 ** 3), 1),
|
||||
"used_gb": round(ram.used / (1024 ** 3), 1),
|
||||
"available_gb": round(ram.available / (1024 ** 3), 1),
|
||||
"threshold": thresholds["ram_percent"],
|
||||
"status": ram_status,
|
||||
},
|
||||
"disks": disks,
|
||||
"processes": processes,
|
||||
"uptime": str(uptime).split(".")[0],
|
||||
"boot_time": boot_time.isoformat(),
|
||||
"monitoring_active": self._running,
|
||||
"last_check": now.isoformat(),
|
||||
"next_check": (now + timedelta(minutes=interval)).isoformat(),
|
||||
}
|
||||
|
||||
with self._lock:
|
||||
self._metrics = metrics
|
||||
|
||||
return metrics
|
||||
|
||||
def _check_processes(self, process_configs):
|
||||
"""Verifie l'etat des processus surveilles."""
|
||||
results = []
|
||||
for proc_cfg in process_configs:
|
||||
pattern = proc_cfg["pattern"].lower()
|
||||
name = proc_cfg["name"]
|
||||
enabled = proc_cfg.get("enabled", True)
|
||||
mem_threshold = proc_cfg.get("memory_threshold_mb", 0)
|
||||
|
||||
found = []
|
||||
if enabled:
|
||||
for proc in psutil.process_iter(["pid", "name", "cmdline", "memory_info", "cpu_percent"]):
|
||||
try:
|
||||
pname = (proc.info["name"] or "").lower()
|
||||
cmdline = " ".join(proc.info["cmdline"] or []).lower()
|
||||
if pattern in pname or pattern in cmdline:
|
||||
mem_mb = round(proc.info["memory_info"].rss / (1024 ** 2), 1) if proc.info["memory_info"] else 0
|
||||
found.append({
|
||||
"pid": proc.info["pid"],
|
||||
"memory_mb": mem_mb,
|
||||
"cpu_percent": proc.info["cpu_percent"] or 0,
|
||||
})
|
||||
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
|
||||
continue
|
||||
|
||||
total_memory = sum(p["memory_mb"] for p in found)
|
||||
total_cpu = sum(p["cpu_percent"] for p in found)
|
||||
running = len(found) > 0
|
||||
|
||||
# Statut memoire
|
||||
mem_status = "ok"
|
||||
if mem_threshold > 0 and total_memory > 0:
|
||||
mem_status = self._eval_status(total_memory, mem_threshold, is_mb=True)
|
||||
|
||||
results.append({
|
||||
"name": name,
|
||||
"pattern": proc_cfg["pattern"],
|
||||
"running": running,
|
||||
"enabled": enabled,
|
||||
"alert_on_down": proc_cfg.get("alert_on_down", True),
|
||||
"instance_count": len(found),
|
||||
"total_memory_mb": round(total_memory, 1),
|
||||
"total_cpu_percent": round(total_cpu, 1),
|
||||
"memory_threshold_mb": mem_threshold,
|
||||
"memory_status": mem_status,
|
||||
"pids": [p["pid"] for p in found],
|
||||
})
|
||||
|
||||
return results
|
||||
|
||||
def _eval_status(self, value, threshold, is_mb=False):
|
||||
if is_mb:
|
||||
ratio = value / threshold if threshold > 0 else 0
|
||||
else:
|
||||
ratio = value / threshold if threshold > 0 else 0
|
||||
if ratio >= 1.0:
|
||||
return "critical"
|
||||
elif ratio >= 0.80:
|
||||
return "warning"
|
||||
return "ok"
|
||||
|
||||
def check_and_alert(self, metrics):
|
||||
"""Verifie les seuils et envoie des alertes si necessaire."""
|
||||
cfg = self.config.config
|
||||
cooldown = cfg.get("alert_cooldown_minutes", 30)
|
||||
alerts_sent = []
|
||||
|
||||
# CPU
|
||||
if metrics["cpu"]["status"] == "critical":
|
||||
msg = f"CPU a {metrics['cpu']['percent']}% (seuil: {metrics['cpu']['threshold']}%)"
|
||||
if self._should_alert("cpu", cooldown):
|
||||
self._send_and_log("cpu", msg, metrics["cpu"]["percent"], metrics["cpu"]["threshold"])
|
||||
alerts_sent.append(msg)
|
||||
|
||||
# RAM
|
||||
if metrics["ram"]["status"] == "critical":
|
||||
msg = f"RAM a {metrics['ram']['percent']}% (seuil: {metrics['ram']['threshold']}%)"
|
||||
if self._should_alert("ram", cooldown):
|
||||
self._send_and_log("ram", msg, metrics["ram"]["percent"], metrics["ram"]["threshold"])
|
||||
alerts_sent.append(msg)
|
||||
|
||||
# Disques
|
||||
for disk in metrics["disks"]:
|
||||
key = f"disk_{disk['drive']}"
|
||||
if disk["status"] == "critical":
|
||||
msg = f"Disque {disk['drive']} a {disk['percent']}% (seuil: {disk['threshold']}%)"
|
||||
if self._should_alert(key, cooldown):
|
||||
self._send_and_log(key, msg, disk["percent"], disk["threshold"])
|
||||
alerts_sent.append(msg)
|
||||
|
||||
# Processus
|
||||
for proc in metrics["processes"]:
|
||||
if not proc["enabled"]:
|
||||
continue
|
||||
|
||||
# Alerte processus arrete
|
||||
if proc["alert_on_down"] and not proc["running"]:
|
||||
key = f"process_down_{proc['name']}"
|
||||
msg = f"Processus '{proc['name']}' non detecte (pattern: {proc['pattern']})"
|
||||
if self._should_alert(key, cooldown):
|
||||
self._send_and_log(key, msg, 0, 0, alert_type="process_down")
|
||||
alerts_sent.append(msg)
|
||||
|
||||
# Alerte memoire processus
|
||||
if proc["memory_threshold_mb"] > 0 and proc["memory_status"] == "critical":
|
||||
key = f"process_mem_{proc['name']}"
|
||||
msg = (
|
||||
f"Processus '{proc['name']}' utilise {proc['total_memory_mb']} Mo "
|
||||
f"(seuil: {proc['memory_threshold_mb']} Mo)"
|
||||
)
|
||||
if self._should_alert(key, cooldown):
|
||||
self._send_and_log(key, msg, proc["total_memory_mb"], proc["memory_threshold_mb"])
|
||||
alerts_sent.append(msg)
|
||||
|
||||
return alerts_sent
|
||||
|
||||
def _should_alert(self, key, cooldown_minutes):
|
||||
now = datetime.now()
|
||||
last = self._last_alerts.get(key)
|
||||
if last and (now - last) < timedelta(minutes=cooldown_minutes):
|
||||
return False
|
||||
return True
|
||||
|
||||
def _send_and_log(self, key, message, value, threshold, alert_type="threshold"):
|
||||
now = datetime.now()
|
||||
hostname = self._metrics.get("hostname", platform.node())
|
||||
|
||||
# Enregistrer l'alerte
|
||||
alert = {
|
||||
"timestamp": now.isoformat(),
|
||||
"type": alert_type,
|
||||
"key": key,
|
||||
"message": message,
|
||||
"value": value,
|
||||
"threshold": threshold,
|
||||
"hostname": hostname,
|
||||
}
|
||||
self.config.save_alert(alert)
|
||||
|
||||
# Envoyer l'email
|
||||
subject = f"[ALERTE] {hostname} - {message}"
|
||||
self.alerter.send_alert(subject, self._format_alert_body(alert))
|
||||
|
||||
# Mettre a jour le cooldown
|
||||
self._last_alerts[key] = now
|
||||
|
||||
def _format_alert_body(self, alert):
|
||||
return (
|
||||
f"Alerte de supervision\n"
|
||||
f"{'=' * 40}\n\n"
|
||||
f"Serveur : {alert['hostname']}\n"
|
||||
f"Date : {alert['timestamp']}\n"
|
||||
f"Type : {alert['type']}\n\n"
|
||||
f"Message : {alert['message']}\n\n"
|
||||
f"{'=' * 40}\n"
|
||||
f"Supervision - Monitoring automatique"
|
||||
)
|
||||
|
||||
# --- Thread de monitoring ---
|
||||
|
||||
def start(self):
|
||||
if self._running:
|
||||
return
|
||||
self._running = True
|
||||
self._thread = threading.Thread(target=self._monitoring_loop, daemon=True)
|
||||
self._thread.start()
|
||||
|
||||
def stop(self):
|
||||
self._running = False
|
||||
|
||||
def _monitoring_loop(self):
|
||||
last_check = 0
|
||||
while self._running:
|
||||
interval = self.config.get("check_interval_minutes", 1) * 60
|
||||
elapsed = time.time() - last_check
|
||||
if elapsed >= interval:
|
||||
try:
|
||||
metrics = self.collect_metrics()
|
||||
self.check_and_alert(metrics)
|
||||
except Exception as e:
|
||||
print(f"[Monitoring] Erreur: {e}")
|
||||
last_check = time.time()
|
||||
time.sleep(5) # Verifie toutes les 5s si c'est le moment
|
||||
6
requirements.txt
Normal file
6
requirements.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
flask==3.1.*
|
||||
flask-login==0.6.*
|
||||
flask-limiter==3.9.*
|
||||
psutil==6.1.*
|
||||
werkzeug==3.1.*
|
||||
pyinstaller==6.12.*
|
||||
33
run.bat
Normal file
33
run.bat
Normal file
@@ -0,0 +1,33 @@
|
||||
@echo off
|
||||
title Supervision - Monitoring Systeme
|
||||
echo ==========================================
|
||||
echo Supervision - Monitoring Systeme
|
||||
echo ==========================================
|
||||
echo.
|
||||
|
||||
REM Verifier si Python est disponible
|
||||
python --version >nul 2>&1
|
||||
if errorlevel 1 (
|
||||
echo [ERREUR] Python n'est pas installe ou pas dans le PATH.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM Creer le venv si absent
|
||||
if not exist ".venv" (
|
||||
echo [INFO] Creation de l'environnement virtuel...
|
||||
python -m venv .venv
|
||||
)
|
||||
|
||||
REM Activer le venv
|
||||
call .venv\Scripts\activate.bat
|
||||
|
||||
REM Installer les dependances
|
||||
echo [INFO] Verification des dependances...
|
||||
pip install -q -r requirements.txt
|
||||
|
||||
REM Lancer l'application
|
||||
echo [INFO] Demarrage de Supervision...
|
||||
python app.py
|
||||
|
||||
pause
|
||||
18
run.sh
Normal file
18
run.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
# Supervision — Script de demarrage (dev Linux)
|
||||
set -e
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
if [ ! -d ".venv" ]; then
|
||||
echo "[INFO] Creation de l'environnement virtuel..."
|
||||
python3 -m venv .venv
|
||||
fi
|
||||
|
||||
source .venv/bin/activate
|
||||
|
||||
echo "[INFO] Verification des dependances..."
|
||||
pip install -q -r requirements.txt
|
||||
|
||||
echo "[INFO] Demarrage de Supervision..."
|
||||
python app.py
|
||||
48
static/style.css
Normal file
48
static/style.css
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Supervision — Style */
|
||||
|
||||
body {
|
||||
background-color: #f4f6f9;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.metric-card {
|
||||
transition: border-color 0.3s;
|
||||
}
|
||||
|
||||
.metric-card .metric-value {
|
||||
font-size: 2.2rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
.card {
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.table th {
|
||||
font-size: 0.8rem;
|
||||
text-transform: uppercase;
|
||||
color: #6c757d;
|
||||
border-bottom-width: 1px;
|
||||
}
|
||||
|
||||
.navbar-brand i {
|
||||
color: #4fc3f7;
|
||||
}
|
||||
|
||||
/* Statut couleurs */
|
||||
.border-success { border-left: 4px solid #198754 !important; }
|
||||
.border-warning { border-left: 4px solid #ffc107 !important; }
|
||||
.border-danger { border-left: 4px solid #dc3545 !important; }
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 768px) {
|
||||
.metric-card .metric-value {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
}
|
||||
60
templates/alerts.html
Normal file
60
templates/alerts.html
Normal file
@@ -0,0 +1,60 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Supervision - Alertes{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h4 class="mb-0"><i class="bi bi-bell"></i> Historique des alertes</h4>
|
||||
{% if alerts %}
|
||||
<form method="POST" action="{{ url_for('clear_alerts') }}">
|
||||
<button type="submit" class="btn btn-sm btn-outline-danger"
|
||||
onclick="return confirm('Effacer tout l\'historique ?')">
|
||||
<i class="bi bi-trash"></i> Effacer l'historique
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if not alerts %}
|
||||
<div class="alert alert-info">
|
||||
<i class="bi bi-info-circle"></i> Aucune alerte enregistree.
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="card">
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-hover mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Type</th>
|
||||
<th>Message</th>
|
||||
<th>Valeur</th>
|
||||
<th>Seuil</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for alert in alerts %}
|
||||
<tr>
|
||||
<td class="text-nowrap">
|
||||
<small>{{ alert.timestamp[:19] | replace('T', ' ') }}</small>
|
||||
</td>
|
||||
<td>
|
||||
{% if alert.type == 'process_down' %}
|
||||
<span class="badge bg-danger">Processus</span>
|
||||
{% else %}
|
||||
<span class="badge bg-warning text-dark">Seuil</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ alert.message }}</td>
|
||||
<td>{{ alert.value }}</td>
|
||||
<td>{{ alert.threshold }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-muted small mt-2">
|
||||
{{ alerts | length }} alerte(s) — les 500 dernieres sont conservees.
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
80
templates/base.html
Normal file
80
templates/base.html
Normal file
@@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}Supervision{% endblock %}</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
|
||||
<link href="{{ url_for('static', filename='style.css') }}" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
{% if current_user.is_authenticated %}
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand" href="{{ url_for('dashboard') }}">
|
||||
<i class="bi bi-activity"></i> Supervision
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav me-auto">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if request.endpoint == 'dashboard' %}active{% endif %}"
|
||||
href="{{ url_for('dashboard') }}">
|
||||
<i class="bi bi-speedometer2"></i> Tableau de bord
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if request.endpoint == 'settings' %}active{% endif %}"
|
||||
href="{{ url_for('settings') }}">
|
||||
<i class="bi bi-gear"></i> Configuration
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link {% if request.endpoint == 'alerts' %}active{% endif %}"
|
||||
href="{{ url_for('alerts') }}">
|
||||
<i class="bi bi-bell"></i> Alertes
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('logout') }}">
|
||||
<i class="bi bi-box-arrow-right"></i> Deconnexion
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
{% endif %}
|
||||
|
||||
<div class="container-fluid mt-3">
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
|
||||
{{ message }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
{% if default_pw is defined and default_pw %}
|
||||
<div class="alert alert-danger">
|
||||
<i class="bi bi-exclamation-triangle"></i>
|
||||
<strong>Securite :</strong> Le mot de passe par defaut est encore actif.
|
||||
<a href="{{ url_for('settings') }}#password" class="alert-link">Changez-le maintenant</a>.
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
||||
{% block scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
252
templates/dashboard.html
Normal file
252
templates/dashboard.html
Normal file
@@ -0,0 +1,252 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Supervision - Tableau de bord{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h4 class="mb-0">
|
||||
<i class="bi bi-speedometer2"></i> Tableau de bord
|
||||
{% if metrics and metrics.hostname %}
|
||||
<small class="text-muted">— {{ metrics.hostname }}</small>
|
||||
{% endif %}
|
||||
</h4>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span id="last-update" class="text-muted small"></span>
|
||||
<form method="POST" action="{{ url_for('toggle_monitoring') }}" class="d-inline">
|
||||
{% if metrics and metrics.monitoring_active %}
|
||||
<button type="submit" class="btn btn-sm btn-outline-warning">
|
||||
<i class="bi bi-pause-circle"></i> Pause
|
||||
</button>
|
||||
{% else %}
|
||||
<button type="submit" class="btn btn-sm btn-outline-success">
|
||||
<i class="bi bi-play-circle"></i> Demarrer
|
||||
</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if not metrics %}
|
||||
<div class="alert alert-info">
|
||||
<i class="bi bi-hourglass-split"></i> Collecte des metriques en cours...
|
||||
</div>
|
||||
{% else %}
|
||||
|
||||
<!-- Infos systeme -->
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
<div class="card bg-dark text-light">
|
||||
<div class="card-body py-2 d-flex gap-4 flex-wrap small">
|
||||
<span><i class="bi bi-pc-display"></i> <strong id="sys-hostname">{{ metrics.hostname }}</strong></span>
|
||||
<span><i class="bi bi-windows"></i> <span id="sys-os">{{ metrics.os }}</span></span>
|
||||
<span><i class="bi bi-clock-history"></i> Uptime: <span id="sys-uptime">{{ metrics.uptime }}</span></span>
|
||||
<span><i class="bi bi-cpu"></i> <span id="sys-cores">{{ metrics.cpu.cores }}</span> coeurs</span>
|
||||
<span><i class="bi bi-memory"></i> <span id="sys-ram-total">{{ metrics.ram.total_gb }}</span> Go RAM</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Metriques principales -->
|
||||
<div class="row mb-3" id="main-metrics">
|
||||
<!-- CPU -->
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="card metric-card" id="card-cpu">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<h6 class="card-title"><i class="bi bi-cpu"></i> CPU</h6>
|
||||
<span class="badge" id="badge-cpu">{{ metrics.cpu.status }}</span>
|
||||
</div>
|
||||
<div class="metric-value" id="val-cpu">{{ metrics.cpu.percent }}%</div>
|
||||
<div class="progress mt-2" style="height: 8px;">
|
||||
<div class="progress-bar" id="bar-cpu" role="progressbar"
|
||||
style="width: {{ metrics.cpu.percent }}%"></div>
|
||||
</div>
|
||||
<small class="text-muted">Seuil: <span id="thresh-cpu">{{ metrics.cpu.threshold }}</span>%</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- RAM -->
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="card metric-card" id="card-ram">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<h6 class="card-title"><i class="bi bi-memory"></i> RAM</h6>
|
||||
<span class="badge" id="badge-ram">{{ metrics.ram.status }}</span>
|
||||
</div>
|
||||
<div class="metric-value" id="val-ram">{{ metrics.ram.percent }}%</div>
|
||||
<div class="progress mt-2" style="height: 8px;">
|
||||
<div class="progress-bar" id="bar-ram" role="progressbar"
|
||||
style="width: {{ metrics.ram.percent }}%"></div>
|
||||
</div>
|
||||
<small class="text-muted">
|
||||
<span id="ram-used">{{ metrics.ram.used_gb }}</span> /
|
||||
<span id="ram-total">{{ metrics.ram.total_gb }}</span> Go
|
||||
— Seuil: <span id="thresh-ram">{{ metrics.ram.threshold }}</span>%
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Placeholder pour les disques - sera rempli par JS aussi -->
|
||||
{% for disk in metrics.disks %}
|
||||
<div class="col-md-4 mb-3">
|
||||
<div class="card metric-card" id="card-disk-{{ loop.index0 }}">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<h6 class="card-title"><i class="bi bi-hdd"></i> {{ disk.drive }}</h6>
|
||||
<span class="badge" id="badge-disk-{{ loop.index0 }}">{{ disk.status }}</span>
|
||||
</div>
|
||||
<div class="metric-value" id="val-disk-{{ loop.index0 }}">{{ disk.percent }}%</div>
|
||||
<div class="progress mt-2" style="height: 8px;">
|
||||
<div class="progress-bar" id="bar-disk-{{ loop.index0 }}" role="progressbar"
|
||||
style="width: {{ disk.percent }}%"></div>
|
||||
</div>
|
||||
<small class="text-muted">
|
||||
{{ disk.used_gb }} / {{ disk.total_gb }} Go
|
||||
({{ disk.free_gb }} Go libres)
|
||||
— Seuil: {{ disk.threshold }}%
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<!-- Processus surveilles -->
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h6 class="mb-0"><i class="bi bi-list-task"></i> Processus surveilles</h6>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-hover mb-0" id="process-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Processus</th>
|
||||
<th>Statut</th>
|
||||
<th>Instances</th>
|
||||
<th>Memoire</th>
|
||||
<th>CPU</th>
|
||||
<th>PID(s)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for proc in metrics.processes %}
|
||||
<tr>
|
||||
<td>
|
||||
<strong>{{ proc.name }}</strong>
|
||||
<br><small class="text-muted">pattern: {{ proc.pattern }}</small>
|
||||
</td>
|
||||
<td>
|
||||
{% if not proc.enabled %}
|
||||
<span class="badge bg-secondary">Desactive</span>
|
||||
{% elif proc.running %}
|
||||
<span class="badge bg-success">Actif</span>
|
||||
{% else %}
|
||||
<span class="badge bg-danger">Arrete</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ proc.instance_count }}</td>
|
||||
<td>
|
||||
{{ proc.total_memory_mb }} Mo
|
||||
{% if proc.memory_threshold_mb > 0 %}
|
||||
<br><small class="text-muted">seuil: {{ proc.memory_threshold_mb }} Mo</small>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ proc.total_cpu_percent }}%</td>
|
||||
<td><small>{{ proc.pids | join(', ') }}</small></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Alertes recentes -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header d-flex justify-content-between">
|
||||
<h6 class="mb-0"><i class="bi bi-bell"></i> Alertes recentes</h6>
|
||||
<a href="{{ url_for('alerts') }}" class="btn btn-sm btn-outline-primary">Voir tout</a>
|
||||
</div>
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0" id="recent-alerts">
|
||||
<tbody>
|
||||
<!-- Rempli par JS -->
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="no-alerts" class="text-center text-muted py-3">
|
||||
Aucune alerte recente.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
const statusColors = {
|
||||
ok: 'success',
|
||||
warning: 'warning',
|
||||
critical: 'danger'
|
||||
};
|
||||
|
||||
function updateMetric(id, percent, status) {
|
||||
const card = document.getElementById('card-' + id);
|
||||
const badge = document.getElementById('badge-' + id);
|
||||
const bar = document.getElementById('bar-' + id);
|
||||
const val = document.getElementById('val-' + id);
|
||||
if (!card) return;
|
||||
|
||||
val.textContent = percent + '%';
|
||||
bar.style.width = percent + '%';
|
||||
|
||||
const color = statusColors[status] || 'secondary';
|
||||
badge.textContent = status;
|
||||
badge.className = 'badge bg-' + color;
|
||||
bar.className = 'progress-bar bg-' + color;
|
||||
card.className = 'card metric-card border-' + color;
|
||||
}
|
||||
|
||||
function refreshMetrics() {
|
||||
fetch('/api/metrics')
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (!data || !data.cpu) return;
|
||||
|
||||
updateMetric('cpu', data.cpu.percent, data.cpu.status);
|
||||
updateMetric('ram', data.ram.percent, data.ram.status);
|
||||
|
||||
document.getElementById('ram-used').textContent = data.ram.used_gb;
|
||||
document.getElementById('sys-uptime').textContent = data.uptime;
|
||||
|
||||
data.disks.forEach((disk, i) => {
|
||||
updateMetric('disk-' + i, disk.percent, disk.status);
|
||||
});
|
||||
|
||||
const now = new Date();
|
||||
document.getElementById('last-update').textContent =
|
||||
'Mis a jour: ' + now.toLocaleTimeString('fr-FR');
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
function loadRecentAlerts() {
|
||||
fetch('/api/metrics')
|
||||
.then(r => r.json())
|
||||
.then(() => {
|
||||
// Charger les alertes separement via la page
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
// Rafraichir toutes les 30 secondes
|
||||
setInterval(refreshMetrics, 30000);
|
||||
</script>
|
||||
{% endblock %}
|
||||
65
templates/login.html
Normal file
65
templates/login.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Supervision - Connexion</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" rel="stylesheet">
|
||||
<style>
|
||||
body { background: #1a1a2e; min-height: 100vh; display: flex; align-items: center; }
|
||||
.login-card { max-width: 400px; margin: auto; }
|
||||
.brand { color: #e2e8f0; text-align: center; margin-bottom: 2rem; }
|
||||
.brand i { font-size: 3rem; color: #4fc3f7; }
|
||||
.brand h1 { font-size: 1.5rem; margin-top: 0.5rem; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="login-card">
|
||||
<div class="brand">
|
||||
<i class="bi bi-activity"></i>
|
||||
<h1>Supervision</h1>
|
||||
<small class="text-secondary">Monitoring systeme</small>
|
||||
</div>
|
||||
|
||||
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||
{% if messages %}
|
||||
{% for category, message in messages %}
|
||||
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
|
||||
{{ message }}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<div class="card shadow">
|
||||
<div class="card-body p-4">
|
||||
<form method="POST" action="{{ url_for('login') }}">
|
||||
<div class="mb-3">
|
||||
<label for="username" class="form-label">Identifiant</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="bi bi-person"></i></span>
|
||||
<input type="text" class="form-control" id="username" name="username"
|
||||
required autofocus autocomplete="username">
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="password" class="form-label">Mot de passe</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="bi bi-lock"></i></span>
|
||||
<input type="password" class="form-control" id="password" name="password"
|
||||
required autocomplete="current-password">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">
|
||||
<i class="bi bi-box-arrow-in-right"></i> Connexion
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
288
templates/settings.html
Normal file
288
templates/settings.html
Normal file
@@ -0,0 +1,288 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Supervision - Configuration{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h4 class="mb-3"><i class="bi bi-gear"></i> Configuration</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 mb-4">
|
||||
<!-- Seuils d'alerte -->
|
||||
<div class="card">
|
||||
<div class="card-header"><h6 class="mb-0"><i class="bi bi-sliders"></i> Seuils d'alerte (%)</h6></div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ url_for('update_thresholds') }}">
|
||||
<div class="mb-3">
|
||||
<label for="cpu_percent" class="form-label">CPU (%)</label>
|
||||
<input type="number" class="form-control" id="cpu_percent" name="cpu_percent"
|
||||
value="{{ config.thresholds.cpu_percent }}" min="1" max="100" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="ram_percent" class="form-label">RAM (%)</label>
|
||||
<input type="number" class="form-control" id="ram_percent" name="ram_percent"
|
||||
value="{{ config.thresholds.ram_percent }}" min="1" max="100" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="disk_percent" class="form-label">Disque (%)</label>
|
||||
<input type="number" class="form-control" id="disk_percent" name="disk_percent"
|
||||
value="{{ config.thresholds.disk_percent }}" min="1" max="100" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check-lg"></i> Enregistrer
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-lg-6 mb-4">
|
||||
<!-- Parametres de monitoring -->
|
||||
<div class="card">
|
||||
<div class="card-header"><h6 class="mb-0"><i class="bi bi-clock"></i> Frequence et alertes</h6></div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ url_for('update_monitoring') }}">
|
||||
<div class="mb-3">
|
||||
<label for="check_interval_minutes" class="form-label">Intervalle de verification (minutes)</label>
|
||||
<input type="number" class="form-control" id="check_interval_minutes"
|
||||
name="check_interval_minutes"
|
||||
value="{{ config.check_interval_minutes }}" min="1" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="alert_cooldown_minutes" class="form-label">Cooldown entre alertes (minutes)</label>
|
||||
<input type="number" class="form-control" id="alert_cooldown_minutes"
|
||||
name="alert_cooldown_minutes"
|
||||
value="{{ config.alert_cooldown_minutes }}" min="1" required>
|
||||
<div class="form-text">Delai minimum entre deux alertes du meme type.</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check-lg"></i> Enregistrer
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Port -->
|
||||
<div class="card mt-4">
|
||||
<div class="card-header"><h6 class="mb-0"><i class="bi bi-diagram-3"></i> Port de l'application</h6></div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ url_for('update_port') }}">
|
||||
<div class="mb-3">
|
||||
<label for="port" class="form-label">Port (redemarrage requis)</label>
|
||||
<input type="number" class="form-control" id="port" name="port"
|
||||
value="{{ config.port }}" min="1024" max="65535" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check-lg"></i> Enregistrer
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Configuration SMTP -->
|
||||
<div class="row">
|
||||
<div class="col-12 mb-4">
|
||||
<div class="card">
|
||||
<div class="card-header"><h6 class="mb-0"><i class="bi bi-envelope"></i> Configuration SMTP</h6></div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ url_for('update_smtp') }}">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="smtp_server" class="form-label">Serveur SMTP</label>
|
||||
<input type="text" class="form-control" id="smtp_server" name="smtp_server"
|
||||
value="{{ smtp.server }}" placeholder="smtp.example.com">
|
||||
</div>
|
||||
<div class="col-md-3 mb-3">
|
||||
<label for="smtp_port" class="form-label">Port</label>
|
||||
<input type="number" class="form-control" id="smtp_port" name="smtp_port"
|
||||
value="{{ smtp.port }}">
|
||||
</div>
|
||||
<div class="col-md-3 mb-3 d-flex align-items-end">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" id="smtp_tls" name="smtp_tls"
|
||||
{% if smtp.use_tls %}checked{% endif %}>
|
||||
<label class="form-check-label" for="smtp_tls">STARTTLS</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="smtp_username" class="form-label">Nom d'utilisateur</label>
|
||||
<input type="text" class="form-control" id="smtp_username" name="smtp_username"
|
||||
value="{{ smtp.username }}" autocomplete="off">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="smtp_password" class="form-label">Mot de passe</label>
|
||||
<input type="password" class="form-control" id="smtp_password" name="smtp_password"
|
||||
placeholder="{% if smtp.password_masked %}{{ smtp.password_masked }}{% else %}Non defini{% endif %}"
|
||||
autocomplete="new-password">
|
||||
<div class="form-text">Laissez vide pour conserver le mot de passe actuel.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="smtp_from" class="form-label">Email expediteur</label>
|
||||
<input type="email" class="form-control" id="smtp_from" name="smtp_from"
|
||||
value="{{ smtp.from_email }}" placeholder="supervision@example.com">
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="smtp_to" class="form-label">Destinataires (separes par des virgules)</label>
|
||||
<input type="text" class="form-control" id="smtp_to" name="smtp_to"
|
||||
value="{{ smtp.to_emails | join(', ') }}"
|
||||
placeholder="admin@example.com, tech@example.com">
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check-lg"></i> Enregistrer
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<hr>
|
||||
<form method="POST" action="{{ url_for('test_smtp') }}" class="d-inline">
|
||||
<button type="submit" class="btn btn-outline-info">
|
||||
<i class="bi bi-send"></i> Envoyer un email de test
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Processus surveilles -->
|
||||
<div class="row">
|
||||
<div class="col-12 mb-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h6 class="mb-0"><i class="bi bi-list-task"></i> Processus surveilles</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ url_for('update_processes') }}" id="process-form">
|
||||
<table class="table" id="proc-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Pattern (recherche)</th>
|
||||
<th>Seuil memoire (Mo)</th>
|
||||
<th>Actif</th>
|
||||
<th>Alerte si arrete</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for proc in config.processes %}
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" class="form-control form-control-sm"
|
||||
name="proc_name[]" value="{{ proc.name }}" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" class="form-control form-control-sm"
|
||||
name="proc_pattern[]" value="{{ proc.pattern }}" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" class="form-control form-control-sm"
|
||||
name="proc_mem_threshold[]"
|
||||
value="{{ proc.memory_threshold_mb }}" min="0">
|
||||
<div class="form-text">0 = pas de seuil</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input"
|
||||
name="proc_enabled[]" value="{{ loop.index0 }}"
|
||||
{% if proc.enabled %}checked{% endif %}>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input"
|
||||
name="proc_alert_down[]" value="{{ loop.index0 }}"
|
||||
{% if proc.alert_on_down %}checked{% endif %}>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-sm btn-outline-danger btn-remove-proc">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="button" class="btn btn-outline-success" id="btn-add-proc">
|
||||
<i class="bi bi-plus-lg"></i> Ajouter un processus
|
||||
</button>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-check-lg"></i> Enregistrer
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Changement de mot de passe -->
|
||||
<div class="row" id="password">
|
||||
<div class="col-lg-6 mb-4">
|
||||
<div class="card {% if default_pw %}border-danger{% endif %}">
|
||||
<div class="card-header">
|
||||
<h6 class="mb-0"><i class="bi bi-shield-lock"></i> Mot de passe administrateur</h6>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST" action="{{ url_for('update_password') }}">
|
||||
<div class="mb-3">
|
||||
<label for="current_password" class="form-label">Mot de passe actuel</label>
|
||||
<input type="password" class="form-control" id="current_password"
|
||||
name="current_password" required autocomplete="current-password">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="new_password" class="form-label">Nouveau mot de passe</label>
|
||||
<input type="password" class="form-control" id="new_password"
|
||||
name="new_password" required minlength="8" autocomplete="new-password">
|
||||
<div class="form-text">Minimum 8 caracteres.</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="confirm_password" class="form-label">Confirmer le mot de passe</label>
|
||||
<input type="password" class="form-control" id="confirm_password"
|
||||
name="confirm_password" required autocomplete="new-password">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-warning">
|
||||
<i class="bi bi-check-lg"></i> Changer le mot de passe
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
// Ajouter un processus
|
||||
document.getElementById('btn-add-proc').addEventListener('click', function() {
|
||||
const tbody = document.querySelector('#proc-table tbody');
|
||||
const idx = tbody.children.length;
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML = `
|
||||
<td><input type="text" class="form-control form-control-sm" name="proc_name[]" required></td>
|
||||
<td><input type="text" class="form-control form-control-sm" name="proc_pattern[]" required></td>
|
||||
<td><input type="number" class="form-control form-control-sm" name="proc_mem_threshold[]" value="0" min="0">
|
||||
<div class="form-text">0 = pas de seuil</div></td>
|
||||
<td><div class="form-check"><input type="checkbox" class="form-check-input" name="proc_enabled[]" value="${idx}" checked></div></td>
|
||||
<td><div class="form-check"><input type="checkbox" class="form-check-input" name="proc_alert_down[]" value="${idx}" checked></div></td>
|
||||
<td><button type="button" class="btn btn-sm btn-outline-danger btn-remove-proc"><i class="bi bi-trash"></i></button></td>
|
||||
`;
|
||||
tbody.appendChild(row);
|
||||
});
|
||||
|
||||
// Supprimer un processus
|
||||
document.addEventListener('click', function(e) {
|
||||
if (e.target.closest('.btn-remove-proc')) {
|
||||
e.target.closest('tr').remove();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user