Enhance /admin with full panel and subscription health checks
This commit is contained in:
@@ -17,14 +17,6 @@ type Client struct {
|
||||
http *http.Client
|
||||
}
|
||||
|
||||
type PanelStatus struct {
|
||||
OK bool
|
||||
StatusCode int
|
||||
Users int
|
||||
Nodes int
|
||||
Detail string
|
||||
}
|
||||
|
||||
func NewClient(baseURL, apiToken, caddyToken string) *Client {
|
||||
return &Client{
|
||||
baseURL: strings.TrimRight(baseURL, "/"),
|
||||
@@ -36,38 +28,6 @@ func NewClient(baseURL, apiToken, caddyToken string) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) Check(ctx context.Context) (PanelStatus, error) {
|
||||
st := PanelStatus{}
|
||||
|
||||
resp, body, err := c.get(ctx, "/api/system/stats/recap")
|
||||
if err != nil {
|
||||
return st, err
|
||||
}
|
||||
st.StatusCode = resp.StatusCode
|
||||
|
||||
switch resp.StatusCode {
|
||||
case http.StatusOK:
|
||||
st.OK = true
|
||||
st.Detail = "API панели отвечает"
|
||||
case http.StatusUnauthorized, http.StatusForbidden:
|
||||
return st, fmt.Errorf("доступ запрещён (HTTP %d): проверьте REMNAWAVE_API_TOKEN", resp.StatusCode)
|
||||
default:
|
||||
return st, fmt.Errorf("панель вернула HTTP %d: %s", resp.StatusCode, trimBody(body, 200))
|
||||
}
|
||||
|
||||
users, err := c.countFromEndpoint(ctx, "/api/users", "users")
|
||||
if err == nil {
|
||||
st.Users = users
|
||||
}
|
||||
|
||||
nodes, err := c.countFromEndpoint(ctx, "/api/nodes", "nodes")
|
||||
if err == nil {
|
||||
st.Nodes = nodes
|
||||
}
|
||||
|
||||
return st, nil
|
||||
}
|
||||
|
||||
func (c *Client) countFromEndpoint(ctx context.Context, path, arrayKey string) (int, error) {
|
||||
resp, body, err := c.get(ctx, path)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user