create_zabbix_dashboard.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import requests
  2. ZABBIX_API_URL = "http://localhost:8081/api_jsonrpc.php"
  3. ZABBIX_USER = "Admin"
  4. ZABBIX_PASSWORD = "zabbix"
  5. def authenticate():
  6. payload = {
  7. "jsonrpc": "2.0",
  8. "method": "user.login",
  9. "params": {"user": ZABBIX_USER, "password": ZABBIX_PASSWORD},
  10. "id": 1
  11. }
  12. try:
  13. response = requests.post(ZABBIX_API_URL, json=payload).json()
  14. return response.get('result')
  15. except Exception as e:
  16. print(f"Error connecting to Zabbix API: {e}")
  17. return None
  18. def create_dashboard(auth_token):
  19. print("Creating Food AI RAG Telemetry Dashboard...")
  20. payload = {
  21. "jsonrpc": "2.0",
  22. "method": "dashboard.create",
  23. "params": {
  24. "name": "Food AI RAG Telemetry",
  25. "userid": "1",
  26. "pages": [
  27. {
  28. "name": "SNMP Trap Activity",
  29. "widgets": [
  30. {
  31. "type": "svggraph",
  32. "name": "Ingestion Activity",
  33. "x": 0, "y": 0, "width": 12, "height": 5,
  34. "fields": [
  35. {"type": 1, "name": "ds.0.color", "value": "FF0000"}
  36. ]
  37. },
  38. {
  39. "type": "systeminfo",
  40. "name": "Server Status",
  41. "x": 12, "y": 0, "width": 12, "height": 5
  42. }
  43. ]
  44. }
  45. ]
  46. },
  47. "id": 2,
  48. "auth": auth_token
  49. }
  50. response = requests.post(ZABBIX_API_URL, json=payload).json()
  51. if 'result' in response:
  52. print(f"✅ Dashboard Created successfully! ID: {response['result']['dashboardids'][0]}")
  53. else:
  54. print(f"⚠️ Failed to create dashboard: {response}")
  55. if __name__ == "__main__":
  56. token = authenticate()
  57. if token:
  58. create_dashboard(token)
  59. else:
  60. print("❌ Could not authenticate to Zabbix. Ensure the server is fully started on port 8081.")