NEW MODAL informacje o serwerze

This commit is contained in:
Mateusz Gruszczyński
2025-03-09 14:17:17 +01:00
parent 985d3465c8
commit 942ce73975
3 changed files with 131 additions and 11 deletions

30
app.py
View File

@@ -1621,6 +1621,36 @@ def scheduled_deployments():
setting.last_deploy_time = now
db.session.commit()
@app.route('/server-info/<int:id>', methods=['GET'])
def server_info(id):
if 'user_id' not in session:
return {"error": "Unauthorized"}, 401
host = db.session.get(Host, id)
if not host or host.user_id != session['user_id']:
return {"error": "Host not found or unauthorized"}, 404
if host.use_daemon and host.type == 'linux':
import requests
headers = {"Authorization": host.daemon_token}
sysinfo_url = host.daemon_url.rstrip('/') + '/system-info'
try:
resp = requests.get(sysinfo_url, headers=headers, verify=False, timeout=5)
if resp.status_code == 200:
data = resp.json()
return {
"hostname": format_host(host),
"ip": host.raw_ip,
"cpu": data.get('cpu_percent'),
"mem": data.get('memory_percent'),
"disk": data.get('disk_percent'),
"uptime_seconds": data.get('uptime_seconds')
}
else:
return {"error": f"Błąd demona: {resp.status_code}"}, 500
except Exception as e:
return {"error": str(e)}, 500
else:
return {"error": "This server does not use daemon."}, 400
@app.errorhandler(404)
def page_not_found(error):