integrations: Add errbit integration.

Fixes #13685.
This commit is contained in:
Jonathan Cobb
2020-01-16 02:01:39 -05:00
committed by Tim Abbott
parent 46f2aec674
commit c7433c83ff
8 changed files with 102 additions and 0 deletions

View File

View File

@@ -0,0 +1,15 @@
Get Zulip notifications for the Errbit error tracker!
1. {!create-stream.md!}
1. {!create-bot-construct-url-indented.md!}
1. Go to your project's settings on the Errbit site. Click on the
**Edit** button for your Errbit app, and select **Webhook**.
1. Enter the URL constructed above, and check **Enabled**.
Click **Save**.
{!congrats.md!}
![](/static/images/integrations/errbit/001.png)

View File

@@ -0,0 +1,40 @@
{
"problem": {
"url": "https://errbit.example.com/apps/5e1ed1ff1a603f3916f4f0de/problems/5e1fe93e1a603f3916f4f0e3",
"_id": "5e1fe93e1a603f3916f4f0e3",
"app_id": "5e1ed1ff1a603f3916f4f0de",
"app_name": "ZulipIntegrationTest",
"comments_count": 0,
"created_at": "2020-01-15T23:40:30.989-05:00",
"environment": "ErrbitEnvName",
"error_class": "IllegalStateException",
"first_notice_at": "2020-01-15T23:40:30.987-05:00",
"hosts": {
"382b0f5185773fa0f67a8ed8056c7759": {
"count": 5,
"value": "N/A"
}
},
"issue_link": null,
"issue_type": null,
"last_notice_at": "2020-01-16T00:30:04.835-05:00",
"message": "Invalid state error",
"messages": {
"f721d9a468a891c5138eeb52c8b3831e": {
"count": 5,
"value": "Invalid state error"
}
},
"notices_count": 5,
"resolved": false,
"resolved_at": null,
"updated_at": "2020-01-15T23:45:19.246-05:00",
"user_agents": {
"382b0f5185773fa0f67a8ed8056c7759": {
"count": 5,
"value": "N/A"
}
},
"where": "unknown"
}
}

View File

@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase
class ErrBitHookTests(WebhookTestCase):
STREAM_NAME = 'errbit'
URL_TEMPLATE = u"/api/v1/external/errbit?stream={stream}&api_key={api_key}"
FIXTURE_DIR_NAME = 'errbit'
def test_errbit_error_message(self) -> None:
expected_topic = u"ZulipIntegrationTest / ErrbitEnvName"
expected_message = u"[IllegalStateException](https://errbit.example.com/apps/5e1ed1ff1a603f3916f4f0de/problems/5e1fe93e1a603f3916f4f0e3): \"Invalid state error\" occurred."
self.send_and_test_stream_message('error_message', expected_topic, expected_message)

View File

@@ -0,0 +1,33 @@
from typing import Any, Dict
from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
ERRBIT_TOPIC_TEMPLATE = '{project_name}'
ERRBIT_MESSAGE_TEMPLATE = '[{error_class}]({error_url}): "{error_message}" occurred.'
@api_key_only_webhook_view('Errbit')
@has_request_variables
def api_errbit_webhook(request: HttpRequest, user_profile: UserProfile,
payload: Dict[str, Any]=REQ(argument_type='body')) -> HttpResponse:
subject = get_subject(payload)
body = get_body(payload)
check_send_webhook_message(request, user_profile, subject, body)
return json_success()
def get_subject(payload: Dict[str, Any]) -> str:
project = payload['problem']['app_name'] + ' / ' + payload['problem']['environment']
return ERRBIT_TOPIC_TEMPLATE.format(project_name=project)
def get_body(payload: Dict[str, Any]) -> str:
data = {
'error_url': payload['problem']['url'],
'error_class': payload['problem']['error_class'],
'error_message': payload['problem']['message'],
}
return ERRBIT_MESSAGE_TEMPLATE.format(**data)