From 1d106d9c5230bd849d4688008cd298dbb5fadc39 Mon Sep 17 00:00:00 2001 From: fluzzi32 Date: Mon, 22 Jul 2024 18:57:14 -0300 Subject: [PATCH] update --- app.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index d1ef2de..31fb126 100644 --- a/app.py +++ b/app.py @@ -1,12 +1,16 @@ from flask import Flask, render_template -import requests import re +import docker +import requests app = Flask(__name__) TRAEFIK_API_URL = "https://norman.lan/api/http/routers" REGEX_PATTERNS = [r".*\.gederico\.dynu\.net"] +client = docker.from_env() +containers = client.containers.list(all=True) # Get all containers + def get_routers(): response = requests.get(TRAEFIK_API_URL, verify=False) # Ignore SSL certificate verification if response.status_code == 200: @@ -28,13 +32,11 @@ def filter_routers(routers): def get_router_description(router_name): try: service_name = router_name.split('@')[0] - response = requests.get("http://localhost:2375/containers/json?filters={%22name%22:[%22" + service_name + "%22]}") - containers = response.json() - if containers: - container = containers[0] - labels = container.get('Labels', {}) - print(labels) - return labels.get('traefik.http.routers.' + service_name + '.description', 'No description available') + for container in containers: + labels = container.attrs.get('Config', {}).get('Labels', {}) + description = labels.get('traefik-frontend.http.routers.' + service_name + '.description') + if description: + return description except Exception as e: print(f"Error fetching description for {router_name}: {e}") return 'No description available' @@ -50,5 +52,5 @@ def index(): return render_template('index.html', routers=routers) if __name__ == '__main__': - app.run(debug=True) + app.run(host='0.0.0.0', debug=True)