diff --git a/.gitignore b/.gitignore index 9f34037..87c637d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ .vscode .idea -debug -vendor -Gopkg.lock xmpp-webhook diff --git a/Dockerfile b/Dockerfile index 7619d77..40261b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM golang:1.13-alpine3.10 as builder +FROM golang:1.15-alpine3.13 as builder MAINTAINER Thomas Maier RUN apk add --no-cache git COPY . /build WORKDIR /build RUN GOOS=linux GOARCH=amd64 go build -FROM alpine:3.10 +FROM alpine:3.13 RUN apk add --no-cache ca-certificates COPY --from=builder /build/xmpp-webhook /xmpp-webhook RUN adduser -D -g '' xmpp-webhook diff --git a/LICENSE b/LICENSE index a90a478..6a2a1c0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Thomas Maier +Copyright (c) 2021 Thomas Maier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 49a8134..18647dd 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ `xmpp-webhook` currently support: - Grafana Webhook alerts +- Alertmanager Webhooks - Slack Incoming Webhooks (Feedback appreciated) Check https://github.com/tmsmr/xmpp-webhook/blob/master/parser/ to learn how to support more source services. @@ -18,11 +19,12 @@ Check https://github.com/tmsmr/xmpp-webhook/blob/master/parser/ to learn how to - `XMPP_SKIP_VERIFY` - Skip TLS verification (Optional) - `XMPP_OVER_TLS` - Use dedicated TLS port (Optional) - `XMPP_WEBHOOK_LISTEN_ADDRESS` - Bind address (Optional) -- After startup, `xmpp-webhook` tries to connect to the XMPP server and provides the implemented HTTP enpoints (on `:4321`). e.g.: +- After startup, `xmpp-webhook` tries to connect to the XMPP server and provides the implemented HTTP enpoints. e.g.: ``` -curl -X POST -d @grafana-webhook-alert-example.json localhost:4321/grafana -curl -X POST -d @slack-compatible-notification-example.json localhost:4321/slack +curl -X POST -d @dev/grafana-webhook-alert-example.json localhost:4321/grafana +curl -X POST -d @dev/alertmanager-example.json localhost:4321/alertmanager +curl -X POST -d @dev/slack-compatible-notification-example.json localhost:4321/slack ``` - After parsing the body in the appropriate `parserFunc`, the notification is then distributed to the configured receivers. @@ -34,10 +36,6 @@ curl -X POST -d @slack-compatible-notification-example.json localhost:4321/slack - Run: `docker run -e "XMPP_ID=alerts@example.org" -e "XMPP_PASS=xxx" -e "XMPP_RECEIVERS=receiver1@example.org,receiver2@example.org" -p 4321:4321 -d --name xmpp-webhook tmsmr/xmpp-webhook:latest` ## Installation -~~IMPORTANT NOTE: For the sake of simplicity, `xmpp-webhook` is not reconnecting to the XMPP server after a connection-loss. If you use the provided `xmpp-webhook.service` - Systemd will manage the reconnect by restarting the service.~~. - --> https://github.com/mellium/xmpp automatically reconnects after a failure. - - Download and extract the latest tarball (GitHub release page) - Install the binary: `install -D -m 744 xmpp-webhook /usr/local/bin/xmpp-webhook` - Install the service: `install -D -m 644 xmpp-webhook.service /etc/systemd/system/xmpp-webhook.service` @@ -62,6 +60,7 @@ systemctl start xmpp-webhook - Clone the sources - Change in the project folder: - Build `xmpp-webhook`: `go build` +- `dev/xmpp-dev-stack` starts Prosody (With "auth_any" and "roster_allinall" enabled) and two XMPP-clients for easy testing ## Need help? Feel free to contact me! diff --git a/go.mod b/go.mod index ee3974e..002a89c 100644 --- a/go.mod +++ b/go.mod @@ -9,4 +9,4 @@ require ( mellium.im/xmpp v0.18.0 ) -go 1.13 +go 1.15 diff --git a/main.go b/main.go index aa974db..72aa8fa 100644 --- a/main.go +++ b/main.go @@ -166,7 +166,7 @@ func main() { } }() - // initialize handlers with accociated parser functions + // initialize handlers with associated parser functions http.Handle("/grafana", newMessageHandler(messages, parser.GrafanaParserFunc)) http.Handle("/slack", newMessageHandler(messages, parser.SlackParserFunc)) http.Handle("/alertmanager", newMessageHandler(messages, parser.AlertmanagerParserFunc)) diff --git a/parser/alertmanager.go b/parser/alertmanager.go index 3304f68..dc2f785 100644 --- a/parser/alertmanager.go +++ b/parser/alertmanager.go @@ -29,7 +29,7 @@ func AlertmanagerParserFunc(r *http.Request) (string, error) { return "", errors.New(parseErr) } - // contruct alert message + // construct alert message var message string for _, alert := range payload.Alerts { if alert.Status == "resolved" { diff --git a/parser/grafana.go b/parser/grafana.go index e1c93f9..f37c58b 100644 --- a/parser/grafana.go +++ b/parser/grafana.go @@ -27,7 +27,7 @@ func GrafanaParserFunc(r *http.Request) (string, error) { return "", errors.New(parseErr) } - // contruct alert message + // construct alert message var message string switch alert.State { case "ok": diff --git a/parser/slack-compatible.go b/parser/slack-compatible.go index 9ff703b..e1f952e 100644 --- a/parser/slack-compatible.go +++ b/parser/slack-compatible.go @@ -29,7 +29,7 @@ func SlackParserFunc(r *http.Request) (string, error) { return "", errors.New(parseErr) } - // contruct alert message + // construct alert message message := alert.Text for _, attachment := range alert.Attachments { if len(message) > 0 {