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 = 'Ошибка проверки сервисов'; }); } });