2022-04-14 15:33:53 +03:00
|
|
|
import logging
|
|
|
|
from app.classes.web.base_api_handler import BaseApiHandler
|
2022-06-01 23:52:49 +02:00
|
|
|
from app.classes.controllers.servers_controller import ServersController
|
2022-04-14 15:33:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class ApiServersServerStatsHandler(BaseApiHandler):
|
|
|
|
def get(self, server_id: str):
|
|
|
|
auth_data = self.authenticate_user()
|
|
|
|
if not auth_data:
|
|
|
|
return
|
|
|
|
|
|
|
|
if server_id not in [str(x["server_id"]) for x in auth_data[0]]:
|
|
|
|
# if the user doesn't have access to the server, return an error
|
|
|
|
return self.finish_json(400, {"status": "error", "error": "NOT_AUTHORIZED"})
|
|
|
|
|
2022-06-01 23:52:49 +02:00
|
|
|
srv = ServersController().get_server_instance_by_id(server_id)
|
|
|
|
latest = srv.stats_helper.get_latest_server_stats()
|
|
|
|
|
2022-04-14 15:33:53 +03:00
|
|
|
self.finish_json(
|
|
|
|
200,
|
|
|
|
{
|
|
|
|
"status": "ok",
|
2022-06-01 23:52:49 +02:00
|
|
|
"data": latest,
|
2022-04-14 15:33:53 +03:00
|
|
|
},
|
|
|
|
)
|