NEW MODAL informacje o serwerze
This commit is contained in:
30
app.py
30
app.py
@@ -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):
|
||||
|
Reference in New Issue
Block a user