email.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.conf import settings
  2. from django.contrib.auth import get_user_model
  3. from django.utils import timezone
  4. from django.utils.translation import gettext_lazy as _
  5. from glitchtip.email import DetailEmail
  6. from users.models import User
  7. from .models import MonitorCheck
  8. User = get_user_model()
  9. class MonitorEmail(DetailEmail):
  10. html_template_name = "uptime/uptime-drip.html"
  11. text_template_name = "uptime/alert.txt"
  12. subject_template_name = "uptime/alert-subject.txt"
  13. model = MonitorCheck
  14. went_down = True
  15. last_change = None
  16. def get_context_data(self, **kwargs):
  17. context = super().get_context_data(**kwargs)
  18. monitor = self.object.monitor
  19. base_url = settings.GLITCHTIP_URL.geturl()
  20. org_slug = monitor.project.organization.slug
  21. context["monitor_link"] = f"{base_url}/{org_slug}/uptime-monitors/{monitor.id}"
  22. context[
  23. "project_notification_settings_link"
  24. ] = f"{base_url}/{org_slug}/settings/projects/{monitor.project.slug}"
  25. context["monitor_name"] = monitor.name
  26. context["monitor_url"] = monitor.url
  27. if self.object.reason:
  28. context["reason"] = self.object.get_reason_display
  29. context["start_check"] = self.object.start_check
  30. if self.went_down:
  31. context["status_msg"] = _("is down")
  32. else:
  33. context["status_msg"] = _("is back up")
  34. return context
  35. def get_users(self):
  36. return User.objects.uptime_monitor_recipients(self.object.monitor)