webhooks.py 823 B

12345678910111213141516171819202122232425262728
  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 = "The monitored site has gone down." if went_down else "The monitored site is back up."
  19. attachment = WebhookAttachment(str(monitor.name), monitor.get_detail_url(), message)
  20. section = MSTeamsSection(str(monitor.name), message)
  21. message = "GlitchTip Uptime Alert"
  22. return send_webhook(url, message, [attachment], [section])