mirror of https://github.com/zulip/zulip.git
integration: Add statuspage.io webhook integration.
This commit is contained in:
parent
d7903d25e9
commit
1303248b0b
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
|
@ -350,6 +350,7 @@ WEBHOOK_INTEGRATIONS = [
|
|||
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']),
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
Get Zulip notifications for your Statuspage.io subscriptions!
|
||||
|
||||
{!create-stream.md!}
|
||||
|
||||
{!create-bot-construct-url.md!}
|
||||
|
||||
If you'd like to subscribe to your own organization's Statuspage.io
|
||||
notifications, go to the **Settings** in **Notifications** tab and
|
||||
enable notifications delivery through **WEBHOOK**.
|
||||
|
||||
![](/static/images/integrations/statuspage/001.png)
|
||||
|
||||
In order to subscribe to another company's Statuspage.io
|
||||
notifications, you need to use a slightly different process:
|
||||
|
||||
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)
|
|
@ -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"
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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")
|
|
@ -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()
|
Loading…
Reference in New Issue