mirror of https://github.com/zulip/zulip.git
integrations: Re-add Canarytoken integration.
This commit re-adds the integration for canarytokens.org, now separate from the primary Thinkst integration. Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
f1c9d9c2fe
commit
366cb30db1
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
|
@ -302,6 +302,7 @@ WEBHOOK_INTEGRATIONS: List[WebhookIntegration] = [
|
|||
legacy=True,
|
||||
),
|
||||
WebhookIntegration('buildbot', ['continuous-integration'], display_name='Buildbot'),
|
||||
WebhookIntegration('canarytoken', ['monitoring'], display_name='Thinkst Canarytoken'),
|
||||
WebhookIntegration('circleci', ['continuous-integration'], display_name='CircleCI'),
|
||||
WebhookIntegration('clubhouse', ['project-management']),
|
||||
WebhookIntegration('codeship', ['continuous-integration', 'deployment']),
|
||||
|
@ -559,6 +560,7 @@ DOC_SCREENSHOT_CONFIG: Dict[str, List[ScreenshotConfig]] = {
|
|||
ScreenshotConfig('repo_push_update_single_branch.json', '004.png', 'bitbucket',
|
||||
bot_name='Bitbucket Server Bot')],
|
||||
'buildbot': [ScreenshotConfig('started.json')],
|
||||
'canarytoken': [ScreenshotConfig('canarytoken_real.json')],
|
||||
'circleci': [ScreenshotConfig('github_bionic_production_build_success_multiple_parties.json', image_name='001.png'),
|
||||
ScreenshotConfig('bitbucket_private_repo_pull_request_failure.json', image_name='002.png')],
|
||||
'clubhouse': [ScreenshotConfig('story_create.json')],
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
See your Thinkst Canarytoken alerts in Zulip! This integration works with Canarytokens from
|
||||
[canarytokens.org][canarytokens], not Thinkst's paid product - see the
|
||||
[Thinkst](/integrations/doc/thinkst) integration for those!
|
||||
|
||||
1. {!create-stream.md!}
|
||||
|
||||
1. {!create-bot-construct-url-indented.md!}
|
||||
|
||||
1. Go to [canarytokens.org][canarytokens], and select the type of
|
||||
webhook that you want to create and add a reminder note.
|
||||
In the "Provide an email address of webhook URL" field, enter the constructed
|
||||
URL above.
|
||||
Finally, click **Create my canarytoken**.
|
||||
|
||||
{!congrats.md!}
|
||||
|
||||
![](/static/images/integrations/canarytoken/001.png)
|
||||
|
||||
[canarytokens]: https://canarytokens.org
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"manage_url": "http://example.com/test/url/for/webhook",
|
||||
"memo": "Congrats! The newly saved webhook works",
|
||||
"additional_data": {
|
||||
"src_ip": "1.1.1.1",
|
||||
"useragent": "Mozilla/5.0...",
|
||||
"referer": "http://example.com/referrer",
|
||||
"location": "http://example.com/location"
|
||||
},
|
||||
"channel": "HTTP",
|
||||
"time": "2020-06-09 14:04:39"
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"manage_url": "https://canarytokens.org/manage?token=foo&auth=bar",
|
||||
"memo": "Canarytoken example",
|
||||
"additional_data": {
|
||||
"src_ip": "81.151.13.3",
|
||||
"useragent": "Mozilla/5.0 (X11; Linux x86_64; rv:76.0) Gecko/20100101 Firefox/76.0",
|
||||
"referer": null,
|
||||
"location": null
|
||||
},
|
||||
"channel": "HTTP",
|
||||
"time": "2020-06-09 14:04:47 (UTC)"
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
from zerver.lib.test_classes import WebhookTestCase
|
||||
|
||||
|
||||
class CanarytokenHookTests(WebhookTestCase):
|
||||
STREAM_NAME = 'canarytoken'
|
||||
URL_TEMPLATE = "/api/v1/external/canarytoken?stream={stream}&api_key={api_key}"
|
||||
FIXTURE_DIR_NAME = 'canarytoken'
|
||||
|
||||
def test_canarytoken_new(self) -> None:
|
||||
expected_message = (
|
||||
"**:alert: Canarytoken has been triggered on 2020-06-09 14:04:39!**\n\n"
|
||||
"Congrats! The newly saved webhook works \n\n"
|
||||
"[Manage this canarytoken](http://example.com/test/url/for/webhook)"
|
||||
)
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'canarytoken_new',
|
||||
'canarytoken alert',
|
||||
expected_message,
|
||||
content_type="application/x-www-form-urlencoded"
|
||||
)
|
||||
|
||||
def test_canarytoken_real(self) -> None:
|
||||
expected_message = (
|
||||
"**:alert: Canarytoken has been triggered on 2020-06-09 14:04:47 "
|
||||
"(UTC)!**\n\n"
|
||||
"Canarytoken example \n\n"
|
||||
"[Manage this canarytoken]"
|
||||
"(https://canarytokens.org/manage?token=foo&auth=bar)"
|
||||
)
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'canarytoken_real',
|
||||
'canarytoken alert',
|
||||
expected_message,
|
||||
content_type="application/x-www-form-urlencoded"
|
||||
)
|
||||
|
||||
def test_canarytoken_with_specific_topic(self) -> None:
|
||||
self.url = self.build_webhook_url(topic='foo')
|
||||
expected_message = (
|
||||
"**:alert: Canarytoken has been triggered on 2020-06-09 14:04:47 "
|
||||
"(UTC)!**\n\n"
|
||||
"Canarytoken example \n\n"
|
||||
"[Manage this canarytoken]"
|
||||
"(https://canarytokens.org/manage?token=foo&auth=bar)"
|
||||
)
|
||||
|
||||
self.send_and_test_stream_message(
|
||||
'canarytoken_real',
|
||||
'foo',
|
||||
expected_message,
|
||||
content_type="application/x-www-form-urlencoded"
|
||||
)
|
|
@ -0,0 +1,37 @@
|
|||
# Webhooks for external integrations.
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
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
|
||||
|
||||
|
||||
@api_key_only_webhook_view('Canarytoken')
|
||||
@has_request_variables
|
||||
def api_canarytoken_webhook(
|
||||
request: HttpRequest, user_profile: UserProfile,
|
||||
message: Dict[str, Any] = REQ(argument_type='body'),
|
||||
user_specified_topic: Optional[str] = REQ('topic', default=None)
|
||||
) -> HttpResponse:
|
||||
"""
|
||||
Construct a response to a webhook event from a Thinkst canarytoken from
|
||||
canarytokens.org. Canarytokens from Thinkst's paid product have a different
|
||||
schema and should use the "thinkst" integration. See linked documentation
|
||||
below for a schema:
|
||||
|
||||
https://help.canary.tools/hc/en-gb/articles/360002426577-How-do-I-configure-notifications-for-a-Generic-Webhook-
|
||||
"""
|
||||
topic = 'canarytoken alert'
|
||||
body = (f"**:alert: Canarytoken has been triggered on {message['time']}!**\n\n"
|
||||
f"{message['memo']} \n\n"
|
||||
f"[Manage this canarytoken]({message['manage_url']})")
|
||||
|
||||
if user_specified_topic:
|
||||
topic = user_specified_topic
|
||||
|
||||
check_send_webhook_message(request, user_profile, topic, body)
|
||||
return json_success()
|
|
@ -1,4 +1,6 @@
|
|||
See your Thinkst Canary alerts in Zulip!
|
||||
See your Thinkst Canary and Canarytoken alerts in Zulip! This integration works with
|
||||
Canarytokens from Thinkst's paid product, not [canarytokens.org][canarytokens] - see the
|
||||
[Canarytoken](/integrations/doc/canarytoken) integration for those!
|
||||
|
||||
1. {!create-stream.md!}
|
||||
|
||||
|
@ -12,3 +14,5 @@ See your Thinkst Canary alerts in Zulip!
|
|||
{!congrats.md!}
|
||||
|
||||
![](/static/images/integrations/thinkst/001.png)
|
||||
|
||||
[canarytokens]: https://canarytokens.org
|
||||
|
|
Loading…
Reference in New Issue