Fix busy binary reinstall and add per-node log viewing.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
orohi
2026-07-29 04:31:09 +03:00
co-authored by Cursor
parent 2d8b1d4438
commit 1fb87f5f6c
10 changed files with 222 additions and 19 deletions
+34
View File
@@ -78,3 +78,37 @@ func PushConfig(n *models.Node, cfg map[string]any) error {
}
return nil
}
func FetchLogs(n *models.Node, lines int) (string, error) {
if lines <= 0 {
lines = 300
}
url := fmt.Sprintf("http://%s:%d/api/v1/logs?lines=%d", n.Host, n.NodePort, lines)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return "", err
}
req.Header.Set("Authorization", "Bearer "+n.SecretKey)
client := &http.Client{Timeout: 10 * time.Second}
res, err := client.Do(req)
if err != nil {
return "", err
}
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
if res.StatusCode != http.StatusOK {
return "", fmt.Errorf("status %d: %s", res.StatusCode, string(body))
}
var payload struct {
OK bool `json:"ok"`
Logs string `json:"logs"`
}
if err := json.Unmarshal(body, &payload); err != nil {
return string(body), nil
}
if payload.Logs == "" {
return "(empty agent logs)", nil
}
return payload.Logs, nil
}