Fix busy binary reinstall and add per-node log viewing.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user