Добавлено возвращение имени недоступного сервиса в ответе API и обновление индикатора статуса на фронтенде с соответствующими сообщениями.
This commit is contained in:
parent
3cae996048
commit
53ca2cadaa
11
main.py
11
main.py
@ -114,13 +114,14 @@ def check_services_status(services, timeout=2):
|
|||||||
import requests
|
import requests
|
||||||
for srv in services:
|
for srv in services:
|
||||||
url = srv.get('url')
|
url = srv.get('url')
|
||||||
|
name = srv.get('name', url)
|
||||||
try:
|
try:
|
||||||
resp = requests.get(url, timeout=timeout, verify=False)
|
resp = requests.get(url, timeout=timeout, verify=False)
|
||||||
if not (200 <= resp.status_code < 400):
|
if not (200 <= resp.status_code < 400):
|
||||||
return False
|
return False, name
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False, name
|
||||||
return True
|
return True, None
|
||||||
|
|
||||||
@app.route('/api/config', methods=['GET'])
|
@app.route('/api/config', methods=['GET'])
|
||||||
def get_config():
|
def get_config():
|
||||||
@ -156,8 +157,8 @@ def api_weather_forecast():
|
|||||||
def api_services_status():
|
def api_services_status():
|
||||||
config = load_config()
|
config = load_config()
|
||||||
check_online = config.get('checkOnline', [])
|
check_online = config.get('checkOnline', [])
|
||||||
status = check_services_status(check_online) if check_online else None
|
status, failed_name = check_services_status(check_online) if check_online else (None, None)
|
||||||
return jsonify({'all_services_up': status})
|
return jsonify({'all_services_up': status, 'failed_service': failed_name})
|
||||||
|
|
||||||
# config = load_config() # Удаляем глобальную переменную
|
# config = load_config() # Удаляем глобальную переменную
|
||||||
|
|
||||||
|
|||||||
@ -229,13 +229,17 @@ window.addEventListener('DOMContentLoaded', function() {
|
|||||||
fetch('/api/services-status').then(r => r.json()).then(data => {
|
fetch('/api/services-status').then(r => r.json()).then(data => {
|
||||||
if (data.all_services_up === true) {
|
if (data.all_services_up === true) {
|
||||||
indicator.style.background = '#2ecc40';
|
indicator.style.background = '#2ecc40';
|
||||||
|
indicator.title = 'Все сервисы доступны';
|
||||||
} else if (data.all_services_up === false) {
|
} else if (data.all_services_up === false) {
|
||||||
indicator.style.background = '#ff4136';
|
indicator.style.background = '#ff4136';
|
||||||
|
indicator.title = 'Недоступен: ' + (data.failed_service || 'неизвестно');
|
||||||
} else {
|
} else {
|
||||||
indicator.style.background = '#888';
|
indicator.style.background = '#888';
|
||||||
|
indicator.title = 'Статус сервисов неизвестен';
|
||||||
}
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
indicator.style.background = '#888';
|
indicator.style.background = '#888';
|
||||||
|
indicator.title = 'Ошибка проверки сервисов';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user