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/
This commit is contained in:
Vishnu KS 2021-03-30 23:15:06 +05:30 committed by Tim Abbott
parent 353e1a2016
commit 92316ef4d1
2 changed files with 6 additions and 5 deletions

View File

@ -6,7 +6,7 @@
}, },
"page": { "page": {
"id": "jb7j80lkgqvb", "id": "jb7j80lkgqvb",
"status_indicator": "none", "status_indicator": "critical",
"status_description": "All Systems Operational" "status_description": "All Systems Operational"
}, },
"incident": { "incident": {

View File

@ -4,6 +4,7 @@ from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import REQ, has_request_variables, webhook_view 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.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
@ -57,14 +58,14 @@ def api_statuspage_webhook(
payload: Dict[str, Any] = REQ(argument_type="body"), payload: Dict[str, Any] = REQ(argument_type="body"),
) -> HttpResponse: ) -> HttpResponse:
status = payload["page"]["status_indicator"] if "incident" in payload:
if status == "none":
topic = get_incident_topic(payload) topic = get_incident_topic(payload)
body = get_incident_events_body(payload) body = get_incident_events_body(payload)
else: elif "component" in payload:
topic = get_component_topic(payload) topic = get_component_topic(payload)
body = get_components_update_body(payload) body = get_components_update_body(payload)
else:
raise UnsupportedWebhookEventType("unknown-event")
check_send_webhook_message(request, user_profile, topic, body) check_send_webhook_message(request, user_profile, topic, body)
return json_success() return json_success()