Skip to content

Commit

Permalink
Merge 4571dd5 into d6ae934
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh570 committed Jan 7, 2018
2 parents d6ae934 + 4571dd5 commit 290b2de
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 0 deletions.
Binary file added static/images/integrations/logos/statuspage.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/integrations/statuspage/001.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/integrations/statuspage/002.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/integrations/statuspage/003.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions zerver/lib/integrations.py
Expand Up @@ -336,6 +336,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']),
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions zerver/webhooks/statuspage/doc.md
@@ -0,0 +1,22 @@
Receive real-time notifications from statuspage.io whenever any
company(of your interest) creates or updates an incident, or updates a component's
status.

{!create-stream.md!}

{!create-bot-construct-url.md!}

1. What company needs to do:
Go to `subscribers settings` in `notifications` tab and **enable** notifications delivery through **webhook**

![](/static/images/integrations/statuspage/001.png)


2. What users need to do:
Go to the company's statuspage.io site(which is example.statuspage.io) and click `SUBSCRIBE TO UPDATES` and
provide there the Webhook URL.
![](/static/images/integrations/statuspage/002.png)

{!congrats.md!}

![](/static/images/integrations/statuspage/003.png)
32 changes: 32 additions & 0 deletions 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"
}
}
75 changes: 75 additions & 0 deletions 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
}
]
}
}
96 changes: 96 additions & 0 deletions 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
}
]
}
}
31 changes: 31 additions & 0 deletions zerver/webhooks/statuspage/tests.py
@@ -0,0 +1,31 @@
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"Statuspage"
expected_message = u"Incident Report :\n **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"Statuspage"
expected_message = u"Incident Report :\n **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"Statuspage"
expected_message = u"Component status changed :\n **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")
36 changes: 36 additions & 0 deletions zerver/webhooks/statuspage/view.py
@@ -0,0 +1,36 @@
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, Iterable, Optional, Text


@api_key_only_webhook_view('Statuspage')
@has_request_variables
def api_statuspage_webhook(request, UserProfile,
payload=REQ(argument_type='body'),
stream=REQ(default='statuspage-test'),
topic=REQ(default='Statuspage')):

# type: (HttpRequest, UserProfile, Dict[str, Any], str, str) -> HttpResponse

status = payload["page"]["status_description"]

if status == "All Systems Operational":
name = payload["incident"]["name"]
state = payload["incident"]["status"]
content = payload["incident"]["incident_updates"][0]["body"]
body = u"Incident Report :\n **{}** \n * State: **{}** \n * Description: {} \n"
body = body.format(name, state, content)

if status != "All Systems Operational":
name = payload["component"]["name"]
old_status = payload["component_update"]["old_status"]
new_status = payload["component_update"]["new_status"]
body = u"Component status changed :\n **{}** has changed status from **{}** to **{}**"
body = body.format(name, old_status, new_status)

check_send_stream_message(UserProfile, request.client, stream, topic, body)
return json_success()

0 comments on commit 290b2de

Please sign in to comment.