update_taiga_airflow.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import requests
  2. import json
  3. import urllib3
  4. import os
  5. from dotenv import load_dotenv
  6. load_dotenv()
  7. urllib3.disable_warnings()
  8. TAIGA_USER = os.environ.get('TAIGA_USER', 'FrancoisLange')
  9. TAIGA_PASS = os.environ.get('TAIGA_PASS', 'your_db_password_here')
  10. base_url = 'https://192.168.130.161/taiga/api/v1'
  11. print("Authenticating to Taiga...")
  12. auth = requests.post(f'{base_url}/auth', json={'type': 'normal', 'username': TAIGA_USER, 'password': TAIGA_PASS}, verify=False).json()
  13. h = {'Authorization': f'Bearer {auth["auth_token"]}', 'Content-Type': 'application/json'}
  14. project_id = 21
  15. print("Creating User Story...")
  16. us_payload = {
  17. "project": project_id,
  18. "subject": "Migrate to Apache Airflow Supervisor & Zabbix Telemetry",
  19. "description": "Replaced the legacy bash/cron data ingestion pipeline with a robust Apache Airflow Python DAG. Configured the Zabbix API to automatically attach a Web Scenario to the host to poll the Airflow healthcheck endpoint."
  20. }
  21. us_resp = requests.post(f'{base_url}/userstories', json=us_payload, headers=h, verify=False)
  22. if us_resp.status_code == 201:
  23. us_id = us_resp.json()['id']
  24. print(f"Created User Story ID: {us_id}")
  25. task_payload = {
  26. "project": project_id,
  27. "user_story": us_id,
  28. "subject": "Replace data_sync.sh cron with Python DAG and configure Zabbix API health checks.",
  29. "description": "Added Airflow to docker-compose.yml. Wrote dags/openfoodfacts_ingestion.py. Cleared legacy crontab. Configured Zabbix Web Scenario."
  30. }
  31. task_resp = requests.post(f'{base_url}/tasks', json=task_payload, headers=h, verify=False)
  32. if task_resp.status_code == 201:
  33. print("Created Task successfully!")
  34. else:
  35. print("Error creating task:", task_resp.text)
  36. else:
  37. print("Error creating User Story:", us_resp.text)
  38. print("Taiga update complete.")