Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Fixed a bug in sentry discord notifications webhook microservice
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasK33 committed Dec 22, 2020
1 parent c0dc2f9 commit 76bca0c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
7 changes: 4 additions & 3 deletions devops/kubernetes/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class Fortify extends Chart {
new WebService(this, "sentry-discord-webhook", {
name: "sentry-discord-webhook",
replicas: 1,
version: "1.1.2",
version: "1.1.3",
env: [
{ name: "LISTEN_ADDRESS", value: ":8080" },
{ name: "WEBHOOK_ENV", value: "prod" },
Expand All @@ -277,8 +277,8 @@ export class Fortify extends Chart {
new WebService(this, "sentry-discord-dev-webhook", {
name: "sentry-discord-dev-webhook",
replicas: 1,
version: "1.1.2",
image: REGISTRY + "sentry-discord-webhook:1.1.2",
version: "1.1.3",
image: REGISTRY + "sentry-discord-webhook:1.1.3",
env: [
{ name: "LISTEN_ADDRESS", value: ":8080" },
{
Expand Down Expand Up @@ -441,6 +441,7 @@ export class Fortify extends Chart {
version: jobsPackage.version,

// Every hour
suspend: true,
schedule: "0 * * * *",
script: "clean_db",

Expand Down
3 changes: 3 additions & 0 deletions devops/kubernetes/src/cronjob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface FortifyCronJobOptions {
readonly env?: EnvVar[] | undefined;
readonly configmaps?: KubeConfigMap[];
readonly secrets?: KubeSecret[];

readonly suspend?: boolean;
}

export class FortifyCronJob extends Construct {
Expand Down Expand Up @@ -57,6 +59,7 @@ export class FortifyCronJob extends Construct {
},
spec: {
schedule: options.schedule,
suspend: options.suspend ?? false,
jobTemplate: {
spec: {
template: {
Expand Down
2 changes: 1 addition & 1 deletion services/sentry-discord-webhook/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"

services:
discord-webhook:
image: ghcr.io/fortify-labs/fortify/sentry-discord-webhook:1.1.2
image: ghcr.io/fortify-labs/fortify/sentry-discord-webhook:1.1.3
build: .

ports:
Expand Down
6 changes: 3 additions & 3 deletions services/sentry-discord-webhook/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ require (
github.com/hashicorp/vault/api v1.0.4
github.com/heptiolabs/healthcheck v0.0.0-20180807145615-6ff867650f40
github.com/joho/godotenv v1.3.0
github.com/klauspost/compress v1.11.3 // indirect
github.com/klauspost/compress v1.11.4 // indirect
github.com/mitchellh/mapstructure v1.4.0
github.com/pierrec/lz4 v2.6.0+incompatible // indirect
github.com/prometheus/client_golang v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 // indirect
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/net v0.0.0-20201216054612-986b41b23924 // indirect
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742 // indirect
golang.org/x/sys v0.0.0-20201221093633-bc327ba9c2f0 // indirect
golang.org/x/text v0.3.4 // indirect
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect
google.golang.org/protobuf v1.25.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions services/sentry-discord-webhook/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.10.7 h1:7rix8v8GpI3ZBb0nSozFRgbtXKv+hOe+qfEpZqybrAg=
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.3 h1:dB4Bn0tN3wdCzQxnS8r06kV74qN/TAfaIS0bVE8h3jc=
github.com/klauspost/compress v1.11.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.11.4 h1:kz40R/YWls3iqT9zX9AHN3WoVsrAWVyui5sxuLqiXqU=
github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
Expand Down Expand Up @@ -377,8 +377,8 @@ golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620 h1:3wPMTskHO3+O6jqTEXyFcsnuxMQOqYSaHsDxcbUXpqA=
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand Down Expand Up @@ -443,8 +443,8 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201210223839-7e3030f88018/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742 h1:+CBz4km/0KPU3RGTwARGh/noP3bEwtHcq+0YcBQM2JQ=
golang.org/x/sys v0.0.0-20201218084310-7d0127a74742/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201221093633-bc327ba9c2f0 h1:n+DPcgTwkgWzIFpLmoimYR2K2b0Ga5+Os4kayIN0vGo=
golang.org/x/sys v0.0.0-20201221093633-bc327ba9c2f0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
6 changes: 6 additions & 0 deletions services/sentry-discord-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func main() {
app.Post("/sentry", func(c *fiber.Ctx) error {
body := c.Body()

defer func() {
if r := recover(); r != nil {
sugar.Errorw("Could not handle ", "body", string(body), "r", r)
}
}()

if !sentry.VerifySignature(body, c.Get("Sentry-Hook-Signature")) {
return c.SendStatus(401)
}
Expand Down
5 changes: 5 additions & 0 deletions services/sentry-discord-webhook/pkg/discord/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func SendMessage(alert *sentry.IssueAlert) {
defer logger.Sync() // flushes buffer, if any
sugar := logger.Sugar()

if alert.Data.TriggeredRule == nil || alert.Data.Event == nil {
sugar.Infow("TriggeredRule or Event is nil")
return
}

webhook := Webhook{
Username: "Fortify Monitoring",
AvatarURL: "https://fortify.gg/favicon.ico",
Expand Down

0 comments on commit 76bca0c

Please sign in to comment.