From 92316ef4d121f4399e563b966128f872a7189abe Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Tue, 30 Mar 2021 23:15:06 +0530 Subject: [PATCH] statuspage: Properly detect the update is for component or incident. The value of "status_indicator" can be "none" for both the component and incident updates[1]. Also, it is not at all necessary that the value of "status_indicator" is always "none" for incident updates[2][3]. So our previous logic of using the value of "status_indicator" to determine whether the update is that of a component or incident was incorrect. Instead, we should use "incident" or "component" keys to determine the type of update. This commit fixes issues [1] and [2] in sentry. 1. https://sentry.io/organizations/zulip/issues/2303217561 2. https://sentry.io/organizations/zulip/issues/2303197407 3. https://support.atlassian.com/statuspage/docs/enable-webhook-notifications/ --- .../webhooks/statuspage/fixtures/incident_created.json | 2 +- zerver/webhooks/statuspage/view.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zerver/webhooks/statuspage/fixtures/incident_created.json b/zerver/webhooks/statuspage/fixtures/incident_created.json index 9dda2569b1..9c4cac54db 100644 --- a/zerver/webhooks/statuspage/fixtures/incident_created.json +++ b/zerver/webhooks/statuspage/fixtures/incident_created.json @@ -6,7 +6,7 @@ }, "page": { "id": "jb7j80lkgqvb", - "status_indicator": "none", + "status_indicator": "critical", "status_description": "All Systems Operational" }, "incident": { diff --git a/zerver/webhooks/statuspage/view.py b/zerver/webhooks/statuspage/view.py index 564b0967de..140331df01 100644 --- a/zerver/webhooks/statuspage/view.py +++ b/zerver/webhooks/statuspage/view.py @@ -4,6 +4,7 @@ from typing import Any, Dict from django.http import HttpRequest, HttpResponse from zerver.decorator import REQ, has_request_variables, webhook_view +from zerver.lib.exceptions import UnsupportedWebhookEventType from zerver.lib.response import json_success from zerver.lib.webhooks.common import check_send_webhook_message from zerver.models import UserProfile @@ -57,14 +58,14 @@ def api_statuspage_webhook( payload: Dict[str, Any] = REQ(argument_type="body"), ) -> HttpResponse: - status = payload["page"]["status_indicator"] - - if status == "none": + if "incident" in payload: topic = get_incident_topic(payload) body = get_incident_events_body(payload) - else: + elif "component" in payload: topic = get_component_topic(payload) body = get_components_update_body(payload) + else: + raise UnsupportedWebhookEventType("unknown-event") check_send_webhook_message(request, user_profile, topic, body) return json_success()