diff --git a/src/sentry/integrations/opsgenie/utils.py b/src/sentry/integrations/opsgenie/utils.py index 615e3a64718919..18337afed9d33c 100644 --- a/src/sentry/integrations/opsgenie/utils.py +++ b/src/sentry/integrations/opsgenie/utils.py @@ -17,6 +17,8 @@ def build_incident_attachment(incident: Incident, new_status: IncidentStatus, me alert_key = f"incident_{incident.organization_id}_{incident.identifier}" if new_status == IncidentStatus.CLOSED: payload = {"identifier": alert_key} + return payload + priority = "P1" if new_status == IncidentStatus.WARNING: priority = "P2" diff --git a/tests/sentry/incidents/action_handlers/test_opsgenie.py b/tests/sentry/incidents/action_handlers/test_opsgenie.py index 0e6f6776431fc3..2ff7ac1de32928 100644 --- a/tests/sentry/incidents/action_handlers/test_opsgenie.py +++ b/tests/sentry/incidents/action_handlers/test_opsgenie.py @@ -95,21 +95,36 @@ def test_build_incident_attachment(self): def run_test(self, incident, method): from sentry.integrations.opsgenie.utils import build_incident_attachment - responses.add( - responses.POST, - url="https://api.opsgenie.com/v2/alerts", - json={}, - status=202, - ) + alias = f"incident_{incident.organization_id}_{incident.identifier}" + + if method == "resolve": + responses.add( + responses.POST, + url=f"https://api.opsgenie.com/v2/alerts/{alias}/acknowledge?identifierType=alias", + json={}, + status=202, + ) + expected_payload = {} + else: + update_incident_status( + incident, IncidentStatus.CRITICAL, status_method=IncidentStatusMethod.RULE_TRIGGERED + ) + responses.add( + responses.POST, + url="https://api.opsgenie.com/v2/alerts", + json={}, + status=202, + ) + expected_payload = build_incident_attachment( + incident, IncidentStatus(incident.status), metric_value=1000 + ) handler = OpsgenieActionHandler(self.action, incident, self.project) metric_value = 1000 with self.tasks(): getattr(handler, method)(metric_value, IncidentStatus(incident.status)) data = responses.calls[0].request.body - assert json.loads(data) == build_incident_attachment( - incident, IncidentStatus(incident.status), metric_value - ) + assert json.loads(data) == expected_payload @responses.activate def test_fire_metric_alert(self):