webhooks.py 856 B

1234567891011121314151617181920212223242526272829303132
  1. from datetime import datetime
  2. from typing import List
  3. from alerts.webhooks import (
  4. MSTeamsSection,
  5. WebhookAttachment,
  6. WebhookPayload,
  7. send_webhook,
  8. )
  9. from .models import MonitorCheck
  10. def send_uptime_as_webhook(
  11. url, monitor_check_id: int, went_down: bool, last_change: datetime
  12. ):
  13. """
  14. Notification about uptime event via webhook.
  15. """
  16. monitor_check = MonitorCheck.objects.get(pk=monitor_check_id)
  17. monitor = monitor_check.monitor
  18. message = (
  19. "The monitored site has gone down."
  20. if went_down
  21. else "The monitored site is back up."
  22. )
  23. attachment = WebhookAttachment(str(monitor.name), monitor.get_detail_url(), message)
  24. section = MSTeamsSection(str(monitor.name), message)
  25. message = "GlitchTip Uptime Alert"
  26. return send_webhook(url, message, [attachment], [section])