From 4387301ced95441939d594641e25acd0542eb6cc Mon Sep 17 00:00:00 2001 From: "LORENZO\\pacio" Date: Tue, 1 Jul 2025 18:05:03 +0200 Subject: [PATCH] rev --- Dockerfile | 3 +- config.yaml | 2 +- docker-compose.yml | 3 +- templates/index.html | 140 +++++++++++++++++++++++++++++++++++++++++++ watcher.py | 27 ++------- 5 files changed, 149 insertions(+), 26 deletions(-) create mode 100644 templates/index.html diff --git a/Dockerfile b/Dockerfile index 3a65e82..b70cd68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.10-slim +FROM python:3.13.3-slim WORKDIR /app @@ -7,5 +7,6 @@ RUN pip install --no-cache-dir -r requirements.txt COPY watcher.py . COPY config.yaml . +COPY templates . CMD ["python", "-u", "watcher.py"] diff --git a/config.yaml b/config.yaml index d5ebf9c..493e400 100644 --- a/config.yaml +++ b/config.yaml @@ -11,7 +11,7 @@ email: username: brass@relay.poloinformatico.it password: DMKqP9vUYn8s to: paciotti@poloinformatico.it - from: brass@poloinformatico.it + from: brass@relay.poloinformatico.it webui: enabled: true diff --git a/docker-compose.yml b/docker-compose.yml index 4539935..c7b3ebc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,7 @@ services: ports: - "48080:8080" volumes: - - ./config.yaml:/app/config.yml + - ./config.yaml:/app/config.yaml - /zucchetti/infinity:/mnt/tenants:ro + - ./templates:/app/templates:ro restart: unless-stopped diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..81f50a6 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,140 @@ + + + + + Tenant Disk Usage Dashboard + + + +
+ +
+ +

📊 Tenant Folder Disk Usage

+ + + + + + + + + + + + {% for folder, data in results.items() %} + {% set percent = (100 * data.used_gb / data.limit_gb) | round(1) %} + + + + + + + + {% endfor %} + +
TenantUsed (GB)Limit (GB)Usage %Status
{{ folder }}{{ "%.2f"|format(data.used_gb) }}{{ "%.2f"|format(data.limit_gb) }} +
+
+
+ {{ percent }}% +
+ {{ 'Exceeded' if data.exceeded else 'OK' }} +
+ + + + + + diff --git a/watcher.py b/watcher.py index 4139bc5..936b3c4 100644 --- a/watcher.py +++ b/watcher.py @@ -4,7 +4,7 @@ import yaml import psutil import threading import time -from flask import Flask, render_template_string +from flask import Flask, render_template from email.mime.text import MIMEText import subprocess @@ -83,31 +83,12 @@ def schedule_check(interval_sec): @app.route("/") def index(): - html = """ - - Tenant Disk Usage - -

Tenant Folder Disk Usage (GB)

- - - {% for folder, data in results.items() %} - - - - - - - {% endfor %} -
TenantUsed (GB)Limit (GB)Status
{{ folder }}{{ "%.2f"|format(data.used_gb) }}{{ "%.2f"|format(data.limit_gb) }}{{ 'Exceeded' if data.exceeded else 'OK' }}
-

Last updated: {{ now }}

- - - """ import datetime - return render_template_string(html, results=results, now=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + return render_template("index.html", results=results, now=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + if __name__ == "__main__": - interval = config.get("schedule", {}).get("seconds", 300) # default 5 minutes + interval = config.get("schedule", {}).get("seconds", 86400) # default 5 minutes print(f"[INFO] Starting scheduled checks every {interval} seconds.") schedule_check(interval)