package collect import ( "encoding/json" "fmt" "net/http" "strings" "time" ) // RepoISO is the health summary of a RepoISO portal running on the same host // (GET /api/integration/status). Reachable=false means the API did not answer. type RepoISO struct { URL string `json:"url"` Reachable bool `json:"reachable"` Error string `json:"error,omitempty"` CheckedAt time.Time `json:"checked_at"` Version string `json:"version"` WorkerAlive bool `json:"worker_alive"` WorkerHeartbeat string `json:"worker_heartbeat"` Images int `json:"images"` ImagesBytes uint64 `json:"images_bytes"` ImagesPending int `json:"images_pending"` ImagesError int `json:"images_error"` Publications int `json:"publications"` PublicationsError int `json:"publications_error"` JobsActive int `json:"jobs_active"` JobsFailed24h int `json:"jobs_failed_24h"` Exports int `json:"exports"` } var repoisoClient = &http.Client{Timeout: 5 * time.Second} // FetchRepoISO queries the RepoISO status endpoint; errors are reported in the result. func FetchRepoISO(base string) RepoISO { base = strings.TrimRight(base, "/") r := RepoISO{URL: base, CheckedAt: time.Now()} resp, err := repoisoClient.Get(base + "/api/integration/status") if err != nil { r.Error = err.Error() return r } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { r.Error = fmt.Sprintf("HTTP %d", resp.StatusCode) return r } if err := json.NewDecoder(resp.Body).Decode(&r); err != nil { r.Error = "bad response: " + err.Error() return r } r.URL, r.Reachable, r.Error = base, true, "" return r }