обавлен индикатор статуса сервисов (зелёный/красный квадратик после даты) на главной странице, проверка через Uptime Kuma и другие сервисы из config.yaml

This commit is contained in:
Vlad 2025-07-11 14:15:27 +03:00
parent 7a9341fbd7
commit 3c813fa0b1
4 changed files with 54 additions and 12 deletions

View File

@ -21,4 +21,8 @@
- Перенесены ассеты из example/home_files в static/
## [fix] Мгновенное применение изменений config.yaml на главной странице
- Исправлено: после сохранения config.yaml главная страница теперь сразу отображает актуальные данные (конфиг перечитывается при каждом запросе, кэш убран)
- Исправлено: после сохранения config.yaml главная страница теперь сразу отображает актуальные данные (конфиг перечитывается при каждом запросе, кэш убран)
## [feature] Индикатор статуса сервисов на главной странице
- Добавлен индикатор (зелёный/красный квадратик после даты) для отображения доступности всех сервисов из config.yaml (включая Uptime Kuma)
- Проверка доступности реализована через HTTP-запросы при каждом открытии главной страницы

View File

@ -119,14 +119,7 @@ bookmarks:
- name: auto.ru
url: http://auto.ru/
icon_name: truck
- group: Work
links:
- name: COPART
url: https://www.copart.com/
icon_name: briefcase
- name: IAAI
url: https://www.iaai.com/
icon_name: briefcase
- group: 3D
links:
- name: cults3d
@ -165,6 +158,13 @@ bookmarks:
- name: Salvagedb
url: https://salvagedb.com/
icon_name: database
- name: COPART
url: https://www.copart.com/
icon_name: briefcase
- name: IAAI
url: https://www.iaai.com/
icon_name: briefcase
- group: VPN
links:
- name: 3ui gui
@ -177,5 +177,17 @@ bookmarks:
weather:
api_key: "8e548386d3c6492f8ef220308231903"
lat: 55.751244
lon: 37,618423
cache_ttl: 60
lon: 37.618423
cache_ttl: 60
services:
- name: Uptime Kuma
url: http://192.168.1.222:3001/
- name: PiHole X86
url: https://192.168.1.11/admin
- name: Router
url: http://192.168.1.1/
- name: Portainer
url: https://portainer.ddl.su/
- name: Grafana
url: http://192.168.1.143:3000/

21
main.py
View File

@ -5,6 +5,7 @@ import os
import requests
import time
import locale
import socket
app = Flask(__name__)
@ -104,6 +105,22 @@ def get_weather_forecast():
except:
return {'_error': str(e)}
def check_services_status(services, timeout=2):
"""
Проверяет доступность всех сервисов из списка.
Возвращает True, если все доступны, иначе False.
"""
import requests
for srv in services:
url = srv.get('url')
try:
resp = requests.get(url, timeout=timeout, verify=False)
if not (200 <= resp.status_code < 400):
return False
except Exception:
return False
return True
@app.route('/api/config', methods=['GET'])
def get_config():
try:
@ -151,7 +168,9 @@ def index():
current_time = now.strftime('%H:%M:%S')
weather = get_weather()
config = load_config() # Загружаем актуальный конфиг при каждом запросе
return render_template('index.html', applications=config['applications'], bookmarks=config['bookmarks'], now=now_str, current_time=current_time, weather=weather)
services = config.get('services', [])
all_services_up = check_services_status(services) if services else None
return render_template('index.html', applications=config['applications'], bookmarks=config['bookmarks'], now=now_str, current_time=current_time, weather=weather, all_services_up=all_services_up)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')

View File

@ -29,6 +29,13 @@
<div style="display:flex; flex-direction:row; align-items:center; gap:12px;">
<span style="font-size:1.6em; color: var(--color-primary);">{{ current_time }}</span>
<span style="font-size:1.6em; color: var(--color-primary);">{{ now }}</span>
{% if all_services_up is not none %}
{% if all_services_up %}
<span title="Статус сервисов" style="display:inline-block; width:18px; height:18px; border-radius:4px; margin-left:8px; background:#2ecc40; border:1.5px solid #444;"></span>
{% else %}
<span title="Статус сервисов" style="display:inline-block; width:18px; height:18px; border-radius:4px; margin-left:8px; background:#ff4136; border:1.5px solid #444;"></span>
{% endif %}
{% endif %}
</div>
<div class="WeatherWidget_WeatherWidget__3XlYt" id="weather-area" style="cursor:pointer;">
<div>