diff --git a/update-gitops-status.sh b/update-gitops-status.sh index ec7150c..cf0a108 100644 --- a/update-gitops-status.sh +++ b/update-gitops-status.sh @@ -176,30 +176,66 @@ echo "" echo "Step 4/4: Sending status to gitops-status-server..." echo " URL: $GITOPS_STATUS_SERVER_URL/api/status" echo " Method: POST" +echo "" -# POST the JSON to the gitops-status-server API -# gitops-status-server should accept the JSON and update its internal state -HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \ +# Create temporary files for response +RESPONSE_BODY=$(mktemp) +trap "rm -f $RESPONSE_BODY" EXIT + +# POST the JSON to the gitops-status-server API with full error reporting +# Capture both response code and body for debugging +HTTP_CODE=$(curl -s -w "%{http_code}" \ -X POST \ -H "Content-Type: application/json" \ -d "$STATUS_JSON" \ - "$GITOPS_STATUS_SERVER_URL/api/status" || true) + "$GITOPS_STATUS_SERVER_URL/api/status" \ + -o "$RESPONSE_BODY" 2>&1 || true) + +# Extract HTTP code (last 3 digits) +HTTP_CODE="${HTTP_CODE: -3}" echo " Response: HTTP $HTTP_CODE" +# Show response body for debugging (especially on error) +if [ -s "$RESPONSE_BODY" ]; then + echo " Response Body:" + sed 's/^/ /' "$RESPONSE_BODY" +fi +echo "" + if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then - echo "" echo "═══════════════════════════════════════════════════════════════════════════════" - echo " ✓ Status update successful" - echo " Grafana Infinity datasource will now read the updated JSON from" - echo " gitops-status-server" + echo " ✓ Status update successful (HTTP $HTTP_CODE)" + echo " JSON has been sent to gitops-status-server" + echo "" + + # Verify the JSON was actually received and stored + echo " Verifying JSON storage on gitops-status-server..." + sleep 1 # Brief delay to ensure server processed the POST + + VERIFY_JSON=$(curl -s "$GITOPS_STATUS_SERVER_URL/status.json" 2>&1 || true) + if echo "$VERIFY_JSON" | grep -q "\"repo\".*\"$REPO_NAME\""; then + echo " ✓ Verified: Latest JSON stored correctly on server" + echo "" + echo " Grafana Infinity datasource will now read the updated JSON from:" + echo " $GITOPS_STATUS_SERVER_URL/status.json" + else + echo " ⚠ Warning: Could not verify JSON storage" + echo " Response from /status.json:" + echo " $VERIFY_JSON" | sed 's/^/ /' + fi + echo "═══════════════════════════════════════════════════════════════════════════════" exit 0 else - echo "" echo "═══════════════════════════════════════════════════════════════════════════════" echo " ✗ ERROR: Status update failed with HTTP $HTTP_CODE" - echo " Check gitops-status-server connectivity and API availability" + echo " Debugging Information:" + echo " - Server URL: $GITOPS_STATUS_SERVER_URL" + echo " - Endpoint: /api/status" + echo " - Check gitops-status-server connectivity (ping/nslookup)" + echo " - Verify service port and internal port mapping" + echo " - Ensure /api/status endpoint accepts POST requests" echo "═══════════════════════════════════════════════════════════════════════════════" exit 1 fi