From 53ca2cadaa3280c1e253b34d55cb55070ce5ea0a Mon Sep 17 00:00:00 2001 From: Vlad Date: Fri, 11 Jul 2025 14:36:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D1=81=D0=B5=D1=80=D0=B2=D0=B8=D1=81=D0=B0=20=D0=B2=20?= =?UTF-8?q?=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=B5=20API=20=D0=B8=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=BD=D0=B4=D0=B8=D0=BA=D0=B0=D1=82=D0=BE=D1=80=D0=B0=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20=D0=BD=D0=B0=20=D1=84?= =?UTF-8?q?=D1=80=D0=BE=D0=BD=D1=82=D0=B5=D0=BD=D0=B4=D0=B5=20=D1=81=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D1=83=D1=8E=D1=89=D0=B8=D0=BC=D0=B8=20=D1=81=D0=BE=D0=BE=D0=B1?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 11 ++++++----- templates/index.html | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index a218f9f..720736f 100644 --- a/main.py +++ b/main.py @@ -114,13 +114,14 @@ def check_services_status(services, timeout=2): import requests for srv in services: url = srv.get('url') + name = srv.get('name', url) try: resp = requests.get(url, timeout=timeout, verify=False) if not (200 <= resp.status_code < 400): - return False + return False, name except Exception: - return False - return True + return False, name + return True, None @app.route('/api/config', methods=['GET']) def get_config(): @@ -156,8 +157,8 @@ def api_weather_forecast(): def api_services_status(): config = load_config() check_online = config.get('checkOnline', []) - status = check_services_status(check_online) if check_online else None - return jsonify({'all_services_up': status}) + status, failed_name = check_services_status(check_online) if check_online else (None, None) + return jsonify({'all_services_up': status, 'failed_service': failed_name}) # config = load_config() # Удаляем глобальную переменную diff --git a/templates/index.html b/templates/index.html index 7af10eb..d518983 100644 --- a/templates/index.html +++ b/templates/index.html @@ -229,13 +229,17 @@ window.addEventListener('DOMContentLoaded', function() { fetch('/api/services-status').then(r => r.json()).then(data => { if (data.all_services_up === true) { indicator.style.background = '#2ecc40'; + indicator.title = 'Все сервисы доступны'; } else if (data.all_services_up === false) { indicator.style.background = '#ff4136'; + indicator.title = 'Недоступен: ' + (data.failed_service || 'неизвестно'); } else { indicator.style.background = '#888'; + indicator.title = 'Статус сервисов неизвестен'; } }).catch(() => { indicator.style.background = '#888'; + indicator.title = 'Ошибка проверки сервисов'; }); } });