-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 18feca6
Showing
8 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Dependencies and Build | ||
node_modules | ||
now-secrets.json | ||
now-required.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Ian Mitchell | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# sentry-discord | ||
|
||
This is a basic `micro` server that accepts an incoming [Sentry](https://sentry.io) webhook and transforms it to the format expected by [Discord](https://discordapp.com/). | ||
|
||
## Usage | ||
|
||
This repository is configured to run with [Zeit Now](https://zeit.co/now). | ||
|
||
First you'll need to create a Discord Webhook in the channel you wish to send alerts to. Once you've created a webhook, clone this repository. Remove the | ||
|
||
``` | ||
"alias": "sentry-discord", | ||
``` | ||
|
||
line from `now.json` and run | ||
|
||
``` | ||
$ now | ||
``` | ||
|
||
Now will prompt you for the Webhook URL - paste the Discord Webhook URL you created. After that, Now should give you the URL to your new deployment. | ||
|
||
Finally, add a new Webhook alert to Sentry by pasting in the Now deployment URL. When you click `Test Plugin` on Sentry, you should receieve an alert on Discord. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require('now-env'); | ||
const { json } = require('micro'); | ||
const handler = require('serve-handler'); | ||
const fetch = require('node-fetch'); | ||
const dedent = require('dedent-js'); | ||
|
||
const COLORS = { | ||
'debug': parseInt('fbe14f', 16), | ||
'info': parseInt('2788ce', 16), | ||
'warning': parseInt('f18500', 16), | ||
'error': parseInt('e03e2f', 16), | ||
'fatal': parseInt('d20f2a', 16), | ||
}; | ||
|
||
module.exports = async (request, response) => { | ||
if (request.method === 'GET') { | ||
return handler(request, response); | ||
} | ||
|
||
const body = await json(request); | ||
|
||
const payload = { | ||
username: 'Sentry', | ||
avatar_url: `${process.env.NOW_URL}/sentry-icon.png`, | ||
embeds: [ | ||
{ | ||
title: body.project_name, | ||
type: 'rich', | ||
description: body.message, | ||
url: body.url, | ||
timestamp: (new Date(body.event.received * 1000)).toISOString(), | ||
color: COLORS[body.level] || COLORS.error, | ||
footer: { | ||
icon_url: 'https://github.com/fluidicon.png', | ||
text: 'ianmitchell/sentry-discord', | ||
}, | ||
fields: [ | ||
{ | ||
name: `${body.event.template.filename}:${body.event.template.lineno}`, | ||
value: dedent` | ||
\`\`\` | ||
${body.event.template.context_line} | ||
\`\`\` | ||
`, | ||
} | ||
] | ||
} | ||
] | ||
}; | ||
|
||
if (body.event.tags) { | ||
payload.embeds[0].fields.push({ | ||
name: '**Tags**', | ||
value: body.event.tags.map(([key, value]) => `${key}: ${value}`).join('\n'), | ||
inline: true, | ||
}); | ||
} | ||
|
||
if (body.event.user) { | ||
payload.embeds[0].fields.push({ | ||
name: '**User**', | ||
value: body.event.user.username, | ||
inline: true, | ||
}); | ||
} | ||
|
||
console.log(payload.embeds[0].fields); | ||
|
||
const val = await fetch(process.env.WEBHOOK, { | ||
method: 'POST', | ||
body: JSON.stringify(payload), | ||
headers: { 'Content-Type': 'application/json' }, | ||
}); | ||
|
||
console.log(val); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "sentry-discord", | ||
"alias": "sentry-discord", | ||
"env": [ | ||
"WEBHOOK" | ||
], | ||
"scale": { | ||
"sfo1": { | ||
"min": 1, | ||
"max": 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "sentry-discord", | ||
"version": "1.0.0", | ||
"description": "Routes Sentry Webhooks to Discord", | ||
"author": { | ||
"name": "Ian Mitchell", | ||
"email": "[email protected]", | ||
"url": "http://ianmitchell.io" | ||
}, | ||
"repository": "ianmitchell/sentry-discord", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "micro" | ||
}, | ||
"dependencies": { | ||
"dedent-js": "^1.0.1", | ||
"micro": "^9.3.3", | ||
"node-fetch": "^2.2.0", | ||
"now-env": "^3.1.0", | ||
"serve-handler": "^5.0.5" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
ansi-styles@^3.2.1: | ||
version "3.2.1" | ||
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" | ||
dependencies: | ||
color-convert "^1.9.0" | ||
|
||
[email protected]: | ||
version "2.0.0" | ||
resolved "http://registry.npmjs.org/arg/-/arg-2.0.0.tgz#c06e7ff69ab05b3a4a03ebe0407fac4cba657545" | ||
|
||
balanced-match@^1.0.0: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" | ||
|
||
brace-expansion@^1.1.7: | ||
version "1.1.11" | ||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" | ||
dependencies: | ||
balanced-match "^1.0.0" | ||
concat-map "0.0.1" | ||
|
||
[email protected]: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048" | ||
|
||
[email protected]: | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.0.tgz#a060a297a6b57e15b61ca63ce84995daa0fe6e52" | ||
dependencies: | ||
ansi-styles "^3.2.1" | ||
escape-string-regexp "^1.0.5" | ||
supports-color "^5.3.0" | ||
|
||
color-convert@^1.9.0: | ||
version "1.9.3" | ||
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" | ||
dependencies: | ||
color-name "1.1.3" | ||
|
||
[email protected]: | ||
version "1.1.3" | ||
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" | ||
|
||
[email protected]: | ||
version "0.5.2" | ||
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.2.tgz#0cf68bb9ddf5f2be7961c3a85178cb85dba78cb4" | ||
|
||
[email protected]: | ||
version "1.0.4" | ||
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b" | ||
|
||
dedent-js@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/dedent-js/-/dedent-js-1.0.1.tgz#bee5fb7c9e727d85dffa24590d10ec1ab1255305" | ||
|
||
[email protected]: | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.1.tgz#5783b4e1c459f06fa5ca27f991f3d06e7a310359" | ||
|
||
escape-string-regexp@^1.0.5: | ||
version "1.0.5" | ||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" | ||
|
||
[email protected]: | ||
version "1.1.3" | ||
resolved "https://registry.yarnpkg.com/fast-url-parser/-/fast-url-parser-1.1.3.tgz#f4af3ea9f34d8a271cf58ad2b3759f431f0b318d" | ||
dependencies: | ||
punycode "^1.3.2" | ||
|
||
has-flag@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" | ||
|
||
[email protected]: | ||
version "1.6.2" | ||
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.2.tgz#0a002cc85707192a7e7946ceedc11155f60ec736" | ||
dependencies: | ||
depd "1.1.1" | ||
inherits "2.0.3" | ||
setprototypeof "1.0.3" | ||
statuses ">= 1.3.1 < 2" | ||
|
||
[email protected]: | ||
version "0.4.19" | ||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b" | ||
|
||
[email protected]: | ||
version "2.0.3" | ||
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" | ||
|
||
[email protected]: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" | ||
|
||
micro@^9.3.3: | ||
version "9.3.3" | ||
resolved "https://registry.yarnpkg.com/micro/-/micro-9.3.3.tgz#32728c7be15e807691ead85da27fd8117a8bca24" | ||
dependencies: | ||
arg "2.0.0" | ||
chalk "2.4.0" | ||
content-type "1.0.4" | ||
is-stream "1.1.0" | ||
raw-body "2.3.2" | ||
|
||
mime-db@~1.33.0: | ||
version "1.33.0" | ||
resolved "http://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz#a3492050a5cb9b63450541e39d9788d2272783db" | ||
|
||
[email protected]: | ||
version "2.1.18" | ||
resolved "http://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz#6f323f60a83d11146f831ff11fd66e2fe5503bb8" | ||
dependencies: | ||
mime-db "~1.33.0" | ||
|
||
[email protected]: | ||
version "3.0.4" | ||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" | ||
dependencies: | ||
brace-expansion "^1.1.7" | ||
|
||
node-fetch@^2.2.0: | ||
version "2.2.0" | ||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.2.0.tgz#4ee79bde909262f9775f731e3656d0db55ced5b5" | ||
|
||
now-env@^3.1.0: | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/now-env/-/now-env-3.1.0.tgz#e0198b67279d387229cfd4b25de4c2fc7156943f" | ||
|
||
[email protected]: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53" | ||
|
||
[email protected]: | ||
version "2.2.1" | ||
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-2.2.1.tgz#90b617025a16381a879bc82a38d4e8bdeb2bcf45" | ||
|
||
punycode@^1.3.2: | ||
version "1.4.1" | ||
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" | ||
|
||
[email protected]: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e" | ||
|
||
[email protected]: | ||
version "2.3.2" | ||
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.2.tgz#bcd60c77d3eb93cde0050295c3f379389bc88f89" | ||
dependencies: | ||
bytes "3.0.0" | ||
http-errors "1.6.2" | ||
iconv-lite "0.4.19" | ||
unpipe "1.0.0" | ||
|
||
serve-handler@^5.0.5: | ||
version "5.0.5" | ||
resolved "https://registry.yarnpkg.com/serve-handler/-/serve-handler-5.0.5.tgz#58707d2d5e3774098433469d7f51151ccb9a5d05" | ||
dependencies: | ||
bytes "3.0.0" | ||
content-disposition "0.5.2" | ||
fast-url-parser "1.1.3" | ||
mime-types "2.1.18" | ||
minimatch "3.0.4" | ||
path-is-inside "1.0.2" | ||
path-to-regexp "2.2.1" | ||
range-parser "1.2.0" | ||
|
||
[email protected]: | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.0.3.tgz#66567e37043eeb4f04d91bd658c0cbefb55b8e04" | ||
|
||
"statuses@>= 1.3.1 < 2": | ||
version "1.5.0" | ||
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c" | ||
|
||
supports-color@^5.3.0: | ||
version "5.5.0" | ||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" | ||
dependencies: | ||
has-flag "^3.0.0" | ||
|
||
[email protected]: | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" |