Добавлено возвращение имени недоступного сервиса в ответе API и обновление индикатора статуса на фронтенде с соответствующими сообщениями.

This commit is contained in:
Vlad 2025-07-11 14:36:43 +03:00
parent 3cae996048
commit 53ca2cadaa
2 changed files with 10 additions and 5 deletions

11
main.py
View File

@ -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() # Удаляем глобальную переменную

View File

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