email.py 1.4 KB

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