#!/bin/bash # Health check script for Telegram Marketing Agent System echo "🏥 Running Health Check for Telegram Marketing Agent System..." # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color # API Gateway URL API_GATEWAY="http://localhost:3030" # Function to check endpoint check_endpoint() { local endpoint=$1 local description=$2 response=$(curl -s -o /dev/null -w "%{http_code}" "$API_GATEWAY$endpoint") if [ "$response" = "200" ] || [ "$response" = "401" ]; then echo -e "${GREEN}✓ $description - $endpoint (HTTP $response)${NC}" return 0 else echo -e "${RED}✗ $description - $endpoint (HTTP $response)${NC}" return 1 fi } # Check API Gateway health echo -e "\n${YELLOW}Checking API Gateway...${NC}" check_endpoint "/health" "API Gateway Health" check_endpoint "/api-docs" "API Documentation" # Check service health endpoints echo -e "\n${YELLOW}Checking Service Health Endpoints...${NC}" check_endpoint "/health/services" "All Services Status" # Check authentication endpoint echo -e "\n${YELLOW}Checking Authentication...${NC}" check_endpoint "/api/v1/auth/login" "Auth Login Endpoint" # Check protected endpoints (should return 401 without auth) echo -e "\n${YELLOW}Checking Protected Endpoints (expecting 401)...${NC}" check_endpoint "/api/v1/orchestrator/campaigns" "Campaigns Endpoint" check_endpoint "/api/v1/gramjs-adapter/accounts" "Telegram Accounts Endpoint" check_endpoint "/api/v1/analytics/metrics" "Analytics Endpoint" check_endpoint "/api/v1/claude/chat" "Claude AI Endpoint" check_endpoint "/api/v1/safety/check" "Safety Guard Endpoint" check_endpoint "/api/v1/compliance/audit" "Compliance Endpoint" check_endpoint "/api/v1/ab-testing/experiments" "A/B Testing Endpoint" # Check metrics endpoint echo -e "\n${YELLOW}Checking Monitoring Endpoints...${NC}" check_endpoint "/metrics" "Prometheus Metrics" # Check frontend echo -e "\n${YELLOW}Checking Frontend...${NC}" frontend_response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:3008") if [ "$frontend_response" = "200" ]; then echo -e "${GREEN}✓ Frontend is accessible at http://localhost:3008${NC}" else echo -e "${RED}✗ Frontend is not accessible (HTTP $frontend_response)${NC}" fi # Summary echo -e "\n${YELLOW}Health Check Summary:${NC}" echo -e "- API Gateway: ${GREEN}http://localhost:3030${NC}" echo -e "- Frontend: ${GREEN}http://localhost:3008${NC}" echo -e "- API Docs: ${GREEN}http://localhost:3030/api-docs${NC}" echo -e "\n${YELLOW}Next Steps:${NC}" echo "1. Visit http://localhost:3008 to access the application" echo "2. Use the API documentation at http://localhost:3030/api-docs" echo "3. Check service logs if any health checks failed: docker-compose logs [service-name]"