FetchReport handles POST /hosts/:hostId/fetch-report.
(w http.ResponseWriter, r *http.Request)
| 474 | |
| 475 | // FetchReport handles POST /hosts/:hostId/fetch-report. |
| 476 | func (h *HostsHandler) FetchReport(w http.ResponseWriter, r *http.Request) { |
| 477 | if h.queueClient == nil { |
| 478 | Error(w, http.StatusServiceUnavailable, "Queue service unavailable") |
| 479 | return |
| 480 | } |
| 481 | hostID := chi.URLParam(r, "hostId") |
| 482 | host, err := h.hosts.GetByID(r.Context(), hostID) |
| 483 | if err != nil || host == nil { |
| 484 | Error(w, http.StatusNotFound, "Host not found") |
| 485 | return |
| 486 | } |
| 487 | task, err := queue.NewReportNowTask(host.ApiID, hostFromRequest(r)) |
| 488 | if err != nil { |
| 489 | Error(w, http.StatusInternalServerError, "Failed to create fetch report task") |
| 490 | return |
| 491 | } |
| 492 | if _, err := h.queueClient.Enqueue(task); err != nil { |
| 493 | Error(w, http.StatusInternalServerError, "Failed to enqueue fetch report") |
| 494 | return |
| 495 | } |
| 496 | JSON(w, http.StatusOK, map[string]interface{}{ |
| 497 | "message": "Fetch report requested", |
| 498 | "success": true, |
| 499 | }) |
| 500 | } |
| 501 | |
| 502 | // FetchReportBulk handles POST /hosts/bulk/fetch-report. |
| 503 | func (h *HostsHandler) FetchReportBulk(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected