def get(self, request: Request) -> Response:
        organization = Organization(slug="myorg")
        project = Project(slug="myproject", organization=organization)

        query = SnubaQuery(
            time_window=60, query="transaction:/some/transaction", aggregate="count()"
        )
        alert_rule = AlertRule(id=1, organization=organization, name="My Alert", snuba_query=query)
        incident = Incident(
            id=2,
            identifier=123,
            organization=organization,
            title="Something broke",
            alert_rule=alert_rule,
            status=IncidentStatus.CRITICAL,
        )
        trigger = AlertRuleTrigger(alert_rule=alert_rule)

        context = generate_incident_trigger_email_context(
            project, incident, trigger, TriggerStatus.ACTIVE
        )

        return MailPreview(
            text_template="sentry/emails/incidents/trigger.txt",
            html_template="sentry/emails/incidents/trigger.html",
            context=context,
        ).render(request)
    def get(self, request):
        organization = Organization(slug="myorg")
        project = Project(id=30, slug="myproj")

        incident = Incident(identifier=123,
                            organization=organization,
                            title="Something broke")
        alert_rule = AlertRule(id=1,
                               organization=organization,
                               aggregation=1,
                               query="is:unresolved")
        alert_rule_trigger = AlertRuleTrigger(id=5,
                                              alert_rule=alert_rule,
                                              alert_threshold=100,
                                              resolve_threshold=50)
        action = AlertRuleTriggerAction(id=10,
                                        alert_rule_trigger=alert_rule_trigger)

        handler = EmailActionHandler(action, incident, project)
        email = handler.build_message(
            handler.generate_email_context(TriggerStatus.ACTIVE),
            TriggerStatus.ACTIVE, 1)
        return MailPreview(html_template=email.html_template,
                           text_template=email.template,
                           context=email.context).render(request)
Example #3
0
 def get(self, request: Request) -> Response:
     organization = Organization(slug="myorg")
     user = User(id=1235, name="Hello There")
     incident = Incident(id=2,
                         identifier=123,
                         organization=organization,
                         title="Something broke")
     activity = IncidentActivity(incident=incident,
                                 user=user,
                                 type=IncidentActivityType.COMMENT.value,
                                 comment="hi")
     email = generate_incident_activity_email(activity, user)
     return MailPreview(html_template=email.html_template,
                        text_template=email.template,
                        context=email.context).render(request)
Example #4
0
 def get(self, request):
     organization = Organization(slug='myorg')
     incident = Incident(
         identifier=123,
         organization=organization,
         title='Something broke',
     )
     activity = IncidentActivity(incident=incident,
                                 user=User(name='Hello There'),
                                 type=IncidentActivityType.COMMENT.value,
                                 comment='hi')
     email = generate_incident_activity_email(activity)
     return MailPreview(
         html_template=email.html_template,
         text_template=email.template,
         context=email.context,
     ).render(request)
Example #5
0
 def test(self):
     incident = Incident()
     assert incident.current_end_date == timezone.now()
     incident.date_closed = timezone.now() - timedelta(minutes=10)
     assert incident.current_end_date == timezone.now() - timedelta(
         minutes=10)
Example #6
0
 def test(self):
     incident = Incident(date_started=timezone.now() - timedelta(minutes=5))
     assert incident.duration == timedelta(minutes=5)
     incident.date_closed = incident.date_started + timedelta(minutes=2)
     assert incident.duration == timedelta(minutes=2)
Example #7
0
 def test(self):
     incident = Incident()
     assert incident.current_end_date == timezone.now()
     incident.date_closed = timezone.now() - timedelta(minutes=10)
     assert incident.current_end_date == timezone.now() - timedelta(minutes=10)
Example #8
0
 def test(self):
     incident = Incident(date_started=timezone.now() - timedelta(minutes=5))
     assert incident.duration == timedelta(minutes=5)
     incident.date_closed = incident.date_started + timedelta(minutes=2)
     assert incident.duration == timedelta(minutes=2)