check_system_status.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. 检查系统状态和可用的API端点
  5. """
  6. import requests
  7. import json
  8. def check_system_status():
  9. """检查系统状态"""
  10. base_urls = [
  11. "http://localhost:8080",
  12. "http://localhost/dev-api",
  13. "http://localhost"
  14. ]
  15. print("🔍 检查系统状态...")
  16. for base_url in base_urls:
  17. print(f"\n🌐 测试地址: {base_url}")
  18. # 测试基本连接
  19. try:
  20. response = requests.get(f"{base_url}/", timeout=5)
  21. print(f" ✅ 基础连接: {response.status_code}")
  22. except Exception as e:
  23. print(f" ❌ 基础连接失败: {str(e)}")
  24. continue
  25. # 测试登录端点
  26. try:
  27. login_endpoints = ["/auth/login", "/login"]
  28. for endpoint in login_endpoints:
  29. try:
  30. response = requests.post(f"{base_url}{endpoint}", json={}, timeout=5)
  31. print(f" 🔑 登录端点 {endpoint}: {response.status_code}")
  32. if response.status_code in [200, 400, 401, 403]:
  33. print(f" 响应: {response.text[:200]}...")
  34. except Exception as e:
  35. print(f" ❌ 登录端点 {endpoint} 失败: {str(e)}")
  36. except Exception as e:
  37. print(f" ❌ 登录测试失败: {str(e)}")
  38. # 测试API端点
  39. try:
  40. api_endpoints = [
  41. "/classMsg/classMsg/list",
  42. "/studentMsg/studentMsg/list",
  43. "/api/classMsg/classMsg/list"
  44. ]
  45. for endpoint in api_endpoints:
  46. try:
  47. response = requests.get(f"{base_url}{endpoint}", timeout=5)
  48. print(f" 📊 API端点 {endpoint}: {response.status_code}")
  49. if response.text:
  50. data = response.json()
  51. if data.get('code'):
  52. print(f" 响应码: {data.get('code')}, 消息: {data.get('msg', '')}")
  53. except Exception as e:
  54. print(f" ❌ API端点 {endpoint} 失败: {str(e)}")
  55. except Exception as e:
  56. print(f" ❌ API测试失败: {str(e)}")
  57. if __name__ == "__main__":
  58. check_system_status()