Skip to content

Commit 18feca6

Browse files
committed
Initial commit
0 parents  commit 18feca6

8 files changed

+351
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Dependencies and Build
2+
node_modules
3+
now-secrets.json
4+
now-required.json

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Ian Mitchell
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# sentry-discord
2+
3+
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/).
4+
5+
## Usage
6+
7+
This repository is configured to run with [Zeit Now](https://zeit.co/now).
8+
9+
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
10+
11+
```
12+
"alias": "sentry-discord",
13+
```
14+
15+
line from `now.json` and run
16+
17+
```
18+
$ now
19+
```
20+
21+
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.
22+
23+
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.

index.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
require('now-env');
2+
const { json } = require('micro');
3+
const handler = require('serve-handler');
4+
const fetch = require('node-fetch');
5+
const dedent = require('dedent-js');
6+
7+
const COLORS = {
8+
'debug': parseInt('fbe14f', 16),
9+
'info': parseInt('2788ce', 16),
10+
'warning': parseInt('f18500', 16),
11+
'error': parseInt('e03e2f', 16),
12+
'fatal': parseInt('d20f2a', 16),
13+
};
14+
15+
module.exports = async (request, response) => {
16+
if (request.method === 'GET') {
17+
return handler(request, response);
18+
}
19+
20+
const body = await json(request);
21+
22+
const payload = {
23+
username: 'Sentry',
24+
avatar_url: `${process.env.NOW_URL}/sentry-icon.png`,
25+
embeds: [
26+
{
27+
title: body.project_name,
28+
type: 'rich',
29+
description: body.message,
30+
url: body.url,
31+
timestamp: (new Date(body.event.received * 1000)).toISOString(),
32+
color: COLORS[body.level] || COLORS.error,
33+
footer: {
34+
icon_url: 'https://github.com/fluidicon.png',
35+
text: 'ianmitchell/sentry-discord',
36+
},
37+
fields: [
38+
{
39+
name: `${body.event.template.filename}:${body.event.template.lineno}`,
40+
value: dedent`
41+
\`\`\`
42+
${body.event.template.context_line}
43+
\`\`\`
44+
`,
45+
}
46+
]
47+
}
48+
]
49+
};
50+
51+
if (body.event.tags) {
52+
payload.embeds[0].fields.push({
53+
name: '**Tags**',
54+
value: body.event.tags.map(([key, value]) => `${key}: ${value}`).join('\n'),
55+
inline: true,
56+
});
57+
}
58+
59+
if (body.event.user) {
60+
payload.embeds[0].fields.push({
61+
name: '**User**',
62+
value: body.event.user.username,
63+
inline: true,
64+
});
65+
}
66+
67+
console.log(payload.embeds[0].fields);
68+
69+
const val = await fetch(process.env.WEBHOOK, {
70+
method: 'POST',
71+
body: JSON.stringify(payload),
72+
headers: { 'Content-Type': 'application/json' },
73+
});
74+
75+
console.log(val);
76+
}

now.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "sentry-discord",
3+
"alias": "sentry-discord",
4+
"env": [
5+
"WEBHOOK"
6+
],
7+
"scale": {
8+
"sfo1": {
9+
"min": 1,
10+
"max": 1
11+
}
12+
}
13+
}

package.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "sentry-discord",
3+
"version": "1.0.0",
4+
"description": "Routes Sentry Webhooks to Discord",
5+
"author": {
6+
"name": "Ian Mitchell",
7+
"email": "ian.mitchel1@live.com",
8+
"url": "http://ianmitchell.io"
9+
},
10+
"repository": "ianmitchell/sentry-discord",
11+
"license": "MIT",
12+
"main": "index.js",
13+
"scripts": {
14+
"start": "micro"
15+
},
16+
"dependencies": {
17+
"dedent-js": "^1.0.1",
18+
"micro": "^9.3.3",
19+
"node-fetch": "^2.2.0",
20+
"now-env": "^3.1.0",
21+
"serve-handler": "^5.0.5"
22+
}
23+
}

sentry-icon.png

5.87 KB
Loading

yarn.lock

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
ansi-styles@^3.2.1:
6+
version "3.2.1"
7+
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
8+
dependencies:
9+
color-convert "^1.9.0"
10+
11+
arg@2.0.0:
12+
version "2.0.0"
13+
resolved "http://registry.npmjs.org/arg/-/arg-2.0.0.tgz#c06e7ff69ab05b3a4a03ebe0407fac4cba657545"
14+
15+
balanced-match@^1.0.0:
16+
version "1.0.0"
17+
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
18+
19+
brace-expansion@^1.1.7:
20+
version "1.1.11"
21+
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
22+
dependencies:
23+
balanced-match "^1.0.0"
24+
concat-map "0.0.1"
25+
26+
bytes@3.0.0:
27+
version "3.0.0"
28+
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
29+
30+
chalk@2.4.0:
31+
version "2.4.0"
32+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.0.tgz#a060a297a6b57e15b61ca63ce84995daa0fe6e52"
33+
dependencies:
34+
ansi-styles "^3.2.1"
35+
escape-string-regexp "^1.0.5"
36+
supports-color "^5.3.0"
37+
38+
color-convert@^1.9.0:
39+
version "1.9.3"
40+
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
41+
dependencies:
42+
color-name "1.1.3"
43+
44+
color-name@1.1.3:
45+
version "1.1.3"
46+
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
47+
48+
concat-map@0.0.1:
49+
version "0.0.1"
50+
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
51+
52+
content-disposition@0.5.2:
53+
version "0.5.2"
54+
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.2.tgz#0cf68bb9ddf5f2be7961c3a85178cb85dba78cb4"
55+
56+
content-type@1.0.4:
57+
version "1.0.4"
58+
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"
59+
60+
dedent-js@^1.0.1:
61+
version "1.0.1"
62+
resolved "https://registry.yarnpkg.com/dedent-js/-/dedent-js-1.0.1.tgz#bee5fb7c9e727d85dffa24590d10ec1ab1255305"
63+
64+
depd@1.1.1:
65+
version "1.1.1"
66+
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.1.tgz#5783b4e1c459f06fa5ca27f991f3d06e7a310359"
67+
68+
escape-string-regexp@^1.0.5:
69+
version "1.0.5"
70+
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
71+
72+
fast-url-parser@1.1.3:
73+
version "1.1.3"
74+
resolved "https://registry.yarnpkg.com/fast-url-parser/-/fast-url-parser-1.1.3.tgz#f4af3ea9f34d8a271cf58ad2b3759f431f0b318d"
75+
dependencies:
76+
punycode "^1.3.2"
77+
78+
has-flag@^3.0.0:
79+
version "3.0.0"
80+
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
81+
82+
http-errors@1.6.2:
83+
version "1.6.2"
84+
resolved "https://registry.yarnpkg.com/http-errors/-/http-errors-1.6.2.tgz#0a002cc85707192a7e7946ceedc11155f60ec736"
85+
dependencies:
86+
depd "1.1.1"
87+
inherits "2.0.3"
88+
setprototypeof "1.0.3"
89+
statuses ">= 1.3.1 < 2"
90+
91+
iconv-lite@0.4.19:
92+
version "0.4.19"
93+
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
94+
95+
inherits@2.0.3:
96+
version "2.0.3"
97+
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
98+
99+
is-stream@1.1.0:
100+
version "1.1.0"
101+
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
102+
103+
micro@^9.3.3:
104+
version "9.3.3"
105+
resolved "https://registry.yarnpkg.com/micro/-/micro-9.3.3.tgz#32728c7be15e807691ead85da27fd8117a8bca24"
106+
dependencies:
107+
arg "2.0.0"
108+
chalk "2.4.0"
109+
content-type "1.0.4"
110+
is-stream "1.1.0"
111+
raw-body "2.3.2"
112+
113+
mime-db@~1.33.0:
114+
version "1.33.0"
115+
resolved "http://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz#a3492050a5cb9b63450541e39d9788d2272783db"
116+
117+
mime-types@2.1.18:
118+
version "2.1.18"
119+
resolved "http://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz#6f323f60a83d11146f831ff11fd66e2fe5503bb8"
120+
dependencies:
121+
mime-db "~1.33.0"
122+
123+
minimatch@3.0.4:
124+
version "3.0.4"
125+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
126+
dependencies:
127+
brace-expansion "^1.1.7"
128+
129+
node-fetch@^2.2.0:
130+
version "2.2.0"
131+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.2.0.tgz#4ee79bde909262f9775f731e3656d0db55ced5b5"
132+
133+
now-env@^3.1.0:
134+
version "3.1.0"
135+
resolved "https://registry.yarnpkg.com/now-env/-/now-env-3.1.0.tgz#e0198b67279d387229cfd4b25de4c2fc7156943f"
136+
137+
path-is-inside@1.0.2:
138+
version "1.0.2"
139+
resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53"
140+
141+
path-to-regexp@2.2.1:
142+
version "2.2.1"
143+
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-2.2.1.tgz#90b617025a16381a879bc82a38d4e8bdeb2bcf45"
144+
145+
punycode@^1.3.2:
146+
version "1.4.1"
147+
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
148+
149+
range-parser@1.2.0:
150+
version "1.2.0"
151+
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"
152+
153+
raw-body@2.3.2:
154+
version "2.3.2"
155+
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.2.tgz#bcd60c77d3eb93cde0050295c3f379389bc88f89"
156+
dependencies:
157+
bytes "3.0.0"
158+
http-errors "1.6.2"
159+
iconv-lite "0.4.19"
160+
unpipe "1.0.0"
161+
162+
serve-handler@^5.0.5:
163+
version "5.0.5"
164+
resolved "https://registry.yarnpkg.com/serve-handler/-/serve-handler-5.0.5.tgz#58707d2d5e3774098433469d7f51151ccb9a5d05"
165+
dependencies:
166+
bytes "3.0.0"
167+
content-disposition "0.5.2"
168+
fast-url-parser "1.1.3"
169+
mime-types "2.1.18"
170+
minimatch "3.0.4"
171+
path-is-inside "1.0.2"
172+
path-to-regexp "2.2.1"
173+
range-parser "1.2.0"
174+
175+
setprototypeof@1.0.3:
176+
version "1.0.3"
177+
resolved "https://registry.yarnpkg.com/setprototypeof/-/setprototypeof-1.0.3.tgz#66567e37043eeb4f04d91bd658c0cbefb55b8e04"
178+
179+
"statuses@>= 1.3.1 < 2":
180+
version "1.5.0"
181+
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.5.0.tgz#161c7dac177659fd9811f43771fa99381478628c"
182+
183+
supports-color@^5.3.0:
184+
version "5.5.0"
185+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
186+
dependencies:
187+
has-flag "^3.0.0"
188+
189+
unpipe@1.0.0:
190+
version "1.0.0"
191+
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"

0 commit comments

Comments
 (0)