File size: 2,261 Bytes
e7341a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import requests

# Replace with your actual Space URL (remove the / at the end)
SPACE_URL = "https://codebaseai-ai-nids-backend.hf.space"

def run_health_check():
    print(f"πŸ” Starting Health Check for: {SPACE_URL}")
    print("-" * 50)
    
    routes_to_test = [
        "/api/logs/status",
        "/api/model/active",
        "/api/live",
        "/api/predict",
        "/api/reports"
    ]
    
    print(f"πŸš€ Testing {len(routes_to_test)} endpoints...")
    
    for route in routes_to_test:
        full_url = f"{SPACE_URL}{route}"
        try:
            # Note: Some routes might need POST, but GET is a good start to check existence
            response = requests.get(full_url, timeout=5)
            status_icon = "βœ…" if response.status_code < 400 else "❌"
            print(f"{status_icon} {response.status_code} - {route}")
        except Exception as e:
            print(f"⚠️ Error reaching {route}: {e}")

    # 1. Test Root / System Info
    try:
        # Most of your routes are under /api
        res = requests.get(f"{SPACE_URL}/api") 
        if res.status_code == 200:
            print("βœ… API Root: ONLINE")
            print(f"   Response: {res.json().get('status', 'No status field')}")
        else:
            print(f"❌ API Root: FAILED (Status: {res.status_code})")
    except Exception as e:
        print(f"❌ API Root: UNREACHABLE ({e})")

    # 2. Test Log Status
    try:
        res = requests.get(f"{SPACE_URL}/api/logs/status?model=bcc")
        if res.status_code == 200:
            print("βœ… Log System: OPERATIONAL")
            print(f"   BCC Stats: {res.json().get('by_class', {})}")
        else:
            print(f"❌ Log System: ERROR ({res.status_code})")
    except Exception as e:
        print(f"❌ Log System: FAILED ({e})")

    # 3. Test Model Switch (Check if logic works)
    try:
        res = requests.get(f"{SPACE_URL}/api/model/active")
        if res.status_code == 200:
            print(f"βœ… Active Model: {res.json().get('active_model', 'unknown')}")
        else:
            print(f"⚠️ Model API: Non-standard response ({res.status_code})")
    except Exception as e:
        print(f"❌ Model API: FAILED ({e})")

if __name__ == "__main__":
    run_health_check()