diff --git a/static/images/integrations/logos/statuspage.png b/static/images/integrations/logos/statuspage.png new file mode 100644 index 00000000000000..a8401eed09017e Binary files /dev/null and b/static/images/integrations/logos/statuspage.png differ diff --git a/static/images/integrations/statuspage/001.png b/static/images/integrations/statuspage/001.png new file mode 100644 index 00000000000000..18b6194af35851 Binary files /dev/null and b/static/images/integrations/statuspage/001.png differ diff --git a/static/images/integrations/statuspage/002.png b/static/images/integrations/statuspage/002.png new file mode 100644 index 00000000000000..54108056d8a013 Binary files /dev/null and b/static/images/integrations/statuspage/002.png differ diff --git a/static/images/integrations/statuspage/003.png b/static/images/integrations/statuspage/003.png new file mode 100644 index 00000000000000..31a0e8887b7b9a Binary files /dev/null and b/static/images/integrations/statuspage/003.png differ diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index e304eb360af95e..3707a05bf7340f 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -349,6 +349,7 @@ def __init__(self, name: str, *args: Any, **kwargs: Any) -> None: WebhookIntegration('slack', ['communication']), WebhookIntegration('solano', ['continuous-integration'], display_name='Solano Labs'), WebhookIntegration('splunk', ['monitoring'], display_name='Splunk'), + WebhookIntegration('statuspage', ['customer-support'], display_name='Statuspage'), WebhookIntegration('stripe', ['financial'], display_name='Stripe'), WebhookIntegration('taiga', ['project-management']), WebhookIntegration('teamcity', ['continuous-integration']), diff --git a/zerver/webhooks/statuspage/__init__.py b/zerver/webhooks/statuspage/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/zerver/webhooks/statuspage/doc.md b/zerver/webhooks/statuspage/doc.md new file mode 100644 index 00000000000000..e851e0e1b95fcb --- /dev/null +++ b/zerver/webhooks/statuspage/doc.md @@ -0,0 +1,23 @@ +Get Zulip notifications for your Statuspage.io subscriptions! + +{!create-stream.md!} + +{!create-bot-construct-url.md!} + +What company needs to do: +Go to the **subscribers settings** in **notifications** tab and enable notifications delivery through **WEBHOOK**. + +![](/static/images/integrations/statuspage/001.png) + +In order to subscribe to a company's Statuspage.io notifications: + +1. Go to the company's Statuspage.io site (for instance, `example.statuspage.io`). +2. Click on **SUBSCRIBE TO UPDATES** +3. Enter the webhook URL constructed above in the **Target Webhook** field. +4. Click on **SUBSCRIBE TO NOTIFICATIONS**. + +![](/static/images/integrations/statuspage/002.png) + +{!congrats.md!} + +![](/static/images/integrations/statuspage/003.png) diff --git a/zerver/webhooks/statuspage/fixtures/component_status_update.json b/zerver/webhooks/statuspage/fixtures/component_status_update.json new file mode 100644 index 00000000000000..cb0afcff1a1100 --- /dev/null +++ b/zerver/webhooks/statuspage/fixtures/component_status_update.json @@ -0,0 +1,32 @@ +{ + "meta": { + "unsubscribe": "http://mycompany24.statuspage.io/?unsubscribe=zjcdb6727vmj", + "documentation": "http://doers.statuspage.io/customer-notifications/webhooks/", + "generated_at": "2017-12-26T07:59:09.498Z" + }, + "page": { + "id": "jb7j80lkgqvb", + "status_indicator": "maintenance", + "status_description": "Service Under Maintenance" + }, + "component": { + "status": "under_maintenance", + "name": "Database component", + "created_at": "2017-12-26T07:57:28.743Z", + "updated_at": "2017-12-26T07:59:09.371Z", + "position": 3, + "description": null, + "showcase": true, + "id": "sqm6pl84wzjc", + "page_id": "jb7j80lkgqvb", + "group_id": null + }, + "component_update": { + "old_status": "operational", + "new_status": "under_maintenance", + "created_at": "2017-12-26T07:59:09.379Z", + "component_type": "Component", + "id": "nd963wv4j30b", + "component_id": "sqm6pl84wzjc" + } +} diff --git a/zerver/webhooks/statuspage/fixtures/incident_created.json b/zerver/webhooks/statuspage/fixtures/incident_created.json new file mode 100644 index 00000000000000..adbdfcb39c8175 --- /dev/null +++ b/zerver/webhooks/statuspage/fixtures/incident_created.json @@ -0,0 +1,75 @@ +{ + "meta": { + "unsubscribe": "http://mycompany24.statuspage.io/?unsubscribe=zjcdb6727vmj", + "documentation": "http://doers.statuspage.io/customer-notifications/webhooks/", + "generated_at": "2017-12-26T07:32:00.770Z" + }, + "page": { + "id": "jb7j80lkgqvb", + "status_indicator": "none", + "status_description": "All Systems Operational" + }, + "incident": { + "name": "Database query delays", + "status": "identified", + "created_at": "2017-12-26T07:32:00.507Z", + "updated_at": "2017-12-26T07:32:00.603Z", + "monitoring_at": null, + "resolved_at": null, + "impact": "none", + "shortlink": "http://stspg.io/646947c1e", + "postmortem_ignored": false, + "postmortem_body": null, + "postmortem_body_last_updated_at": null, + "postmortem_published_at": null, + "postmortem_notified_subscribers": false, + "postmortem_notified_twitter": false, + "backfilled": false, + "scheduled_for": null, + "scheduled_until": null, + "scheduled_remind_prior": false, + "scheduled_reminded_at": null, + "impact_override": null, + "scheduled_auto_in_progress": false, + "scheduled_auto_completed": false, + "id": "z3lct0r596n4", + "page_id": "jb7j80lkgqvb", + "incident_updates": [ + { + "status": "identified", + "body": "We just encountered that database queries are timing out resulting in inconvenience to our end users...we'll do quick fix latest by tommorow !!!", + "created_at": "2017-12-26T07:32:00.548Z", + "wants_twitter_update": false, + "twitter_updated_at": null, + "updated_at": "2017-12-26T07:32:00.548Z", + "display_at": "2017-12-26T07:32:00.548Z", + "affected_components": [ + { + "code": "zvdm6f7gf76j", + "name": "Management Portal (example)", + "old_status": "operational", + "new_status": "operational" + } + ], + "custom_tweet": null, + "deliver_notifications": true, + "id": "qm8bgczn0p2n", + "incident_id": "z3lct0r596n4" + } + ], + "components": [ + { + "status": "operational", + "name": "Management Portal (example)", + "created_at": "2017-12-25T18:44:27.901Z", + "updated_at": "2017-12-25T18:44:27.901Z", + "position": 2, + "description": null, + "showcase": true, + "id": "zvdm6f7gf76j", + "page_id": "jb7j80lkgqvb", + "group_id": null + } + ] + } +} diff --git a/zerver/webhooks/statuspage/fixtures/incident_update.json b/zerver/webhooks/statuspage/fixtures/incident_update.json new file mode 100644 index 00000000000000..8704a684ba4dfc --- /dev/null +++ b/zerver/webhooks/statuspage/fixtures/incident_update.json @@ -0,0 +1,96 @@ +{ + "meta": { + "unsubscribe": "http://mycompany24.statuspage.io/?unsubscribe=zjcdb6727vmj", + "documentation": "http://doers.statuspage.io/customer-notifications/webhooks/", + "generated_at": "2017-12-26T07:37:21.000Z" + }, + "page": { + "id": "jb7j80lkgqvb", + "status_indicator": "none", + "status_description": "All Systems Operational" + }, + "incident": { + "name": "Database query delays", + "status": "resolved", + "created_at": "2017-12-26T07:32:00.507Z", + "updated_at": "2017-12-26T07:37:20.837Z", + "monitoring_at": null, + "resolved_at": "2017-12-26T07:37:20.785Z", + "impact": "none", + "shortlink": "http://stspg.io/646947c1e", + "postmortem_ignored": false, + "postmortem_body": null, + "postmortem_body_last_updated_at": null, + "postmortem_published_at": null, + "postmortem_notified_subscribers": false, + "postmortem_notified_twitter": false, + "backfilled": false, + "scheduled_for": null, + "scheduled_until": null, + "scheduled_remind_prior": false, + "scheduled_reminded_at": null, + "impact_override": null, + "scheduled_auto_in_progress": false, + "scheduled_auto_completed": false, + "id": "z3lct0r596n4", + "page_id": "jb7j80lkgqvb", + "incident_updates": [ + { + "status": "resolved", + "body": "The database issue is resolved.", + "created_at": "2017-12-26T07:37:20.785Z", + "wants_twitter_update": false, + "twitter_updated_at": null, + "updated_at": "2017-12-26T07:37:20.785Z", + "display_at": "2017-12-26T07:37:20.785Z", + "affected_components": [ + { + "code": "zvdm6f7gf76j", + "name": "Management Portal (example)", + "old_status": "operational", + "new_status": "operational" + } + ], + "custom_tweet": null, + "deliver_notifications": true, + "id": "cdwfdrjlp53y", + "incident_id": "z3lct0r596n4" + }, + { + "status": "identified", + "body": "We just encountered that database queries are timing out resulting in inconvenience to our end users...we'll do quick fix latest by tommorow !!!", + "created_at": "2017-12-26T07:32:00.548Z", + "wants_twitter_update": false, + "twitter_updated_at": null, + "updated_at": "2017-12-26T07:32:00.548Z", + "display_at": "2017-12-26T07:32:00.548Z", + "affected_components": [ + { + "code": "zvdm6f7gf76j", + "name": "Management Portal (example)", + "old_status": "operational", + "new_status": "operational" + } + ], + "custom_tweet": null, + "deliver_notifications": true, + "id": "qm8bgczn0p2n", + "incident_id": "z3lct0r596n4" + } + ], + "components": [ + { + "status": "operational", + "name": "Management Portal (example)", + "created_at": "2017-12-25T18:44:27.901Z", + "updated_at": "2017-12-25T18:44:27.901Z", + "position": 2, + "description": null, + "showcase": true, + "id": "zvdm6f7gf76j", + "page_id": "jb7j80lkgqvb", + "group_id": null + } + ] + } +} diff --git a/zerver/webhooks/statuspage/tests.py b/zerver/webhooks/statuspage/tests.py new file mode 100644 index 00000000000000..1cd6c8e8d96b87 --- /dev/null +++ b/zerver/webhooks/statuspage/tests.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +from typing import Text +from zerver.lib.test_classes import WebhookTestCase + +class StatuspageHookTests(WebhookTestCase): + STREAM_NAME = 'statuspage-test' + URL_TEMPLATE = u"/api/v1/external/statuspage?api_key={api_key}" + + def test_statuspage_incident(self) -> None: + expected_subject = u"Database query delays: All Systems Operational" + expected_message = u"**Database query delays** \n * State: **identified** \n \ +* Description: We just encountered that database queries are timing out resulting in inconvenience \ +to our end users...we'll do quick fix latest by tommorow !!!" + self.send_and_test_stream_message('incident_created', + expected_subject, + expected_message, + content_type="application/x-www-form-urlencoded") + + def test_statuspage_incident_update(self) -> None: + expected_subject = u"Database query delays: All Systems Operational" + expected_message = u"**Database query delays** \n * State: **resolved** \n \ +* Description: The database issue is resolved." + self.send_and_test_stream_message('incident_update', + expected_subject, + expected_message, + content_type="application/x-www-form-urlencoded") + + def test_statuspage_component(self) -> None: + expected_subject = u"Database component: Service Under Maintenance" + expected_message = u"**Database component** has changed status \ +from **operational** to **under_maintenance**" + self.send_and_test_stream_message('component_status_update', + expected_subject, + expected_message, + content_type="application/x-www-form-urlencoded") + + def get_body(self, fixture_name: Text) -> Text: + return self.fixture_data("statuspage", fixture_name, file_type="json") diff --git a/zerver/webhooks/statuspage/view.py b/zerver/webhooks/statuspage/view.py new file mode 100644 index 00000000000000..0a87cfc7e0a986 --- /dev/null +++ b/zerver/webhooks/statuspage/view.py @@ -0,0 +1,60 @@ +# Webhooks for external integrations. +from django.utils.translation import ugettext as _ +from zerver.lib.actions import check_send_stream_message +from zerver.lib.response import json_success +from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view +from zerver.models import get_client, UserProfile +from django.http import HttpRequest, HttpResponse +from typing import Dict, Any, Text + +INCIDENT_TEMPLATE = u'**{name}** \n * State: **{state}** \n * Description: {content}' +COMPONENT_TEMPLATE = u'**{name}** has changed status from **{old_status}** to **{new_status}**' +TOPIC_TEMPLATE = u'{name}: {description}' + +def get_incident_events_body(payload: Dict[Text, Any]) -> Text: + return INCIDENT_TEMPLATE.format( + name = payload["incident"]["name"], + state = payload["incident"]["status"], + content = payload["incident"]["incident_updates"][0]["body"], + ) + +def get_components_update_body(payload: Dict[Text, Any]) -> Text: + return COMPONENT_TEMPLATE.format( + name = payload["component"]["name"], + old_status = payload["component_update"]["old_status"], + new_status = payload["component_update"]["new_status"], + ) + +def get_incident_topic(payload: Dict[Text, Any]) -> Text: + return TOPIC_TEMPLATE.format( + name = payload["incident"]["name"], + description = payload["page"]["status_description"], + ) + +def get_component_topic(payload: Dict[Text, Any]) -> Text: + return TOPIC_TEMPLATE.format( + name = payload["component"]["name"], + description = payload["page"]["status_description"], + ) + +@api_key_only_webhook_view('Statuspage') +@has_request_variables +def api_statuspage_webhook(request: HttpRequest, user_profile: UserProfile, + payload: Dict[str, Any]=REQ(argument_type='body'), + stream: str=REQ(default='statuspage-test')) -> HttpResponse: + + status = payload["page"]["status_indicator"] + + if status == "none": + topic = get_incident_topic(payload) + body = get_incident_events_body(payload) + else: + topic = get_component_topic(payload) + body = get_components_update_body(payload) + + check_send_stream_message(user_profile, + request.client, + stream, + topic, + body) + return json_success()