kopia lustrzana https://github.com/tmsmr/xmpp-webhook
Updates README / Fixes some typos / Update to go 1.15
rodzic
dc1d33cf31
commit
0e65215b17
|
@ -1,6 +1,3 @@
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
debug
|
|
||||||
vendor
|
|
||||||
Gopkg.lock
|
|
||||||
xmpp-webhook
|
xmpp-webhook
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
FROM golang:1.13-alpine3.10 as builder
|
FROM golang:1.15-alpine3.13 as builder
|
||||||
MAINTAINER Thomas Maier <contact@thomas-maier.net>
|
MAINTAINER Thomas Maier <contact@thomas-maier.net>
|
||||||
RUN apk add --no-cache git
|
RUN apk add --no-cache git
|
||||||
COPY . /build
|
COPY . /build
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
RUN GOOS=linux GOARCH=amd64 go build
|
RUN GOOS=linux GOARCH=amd64 go build
|
||||||
|
|
||||||
FROM alpine:3.10
|
FROM alpine:3.13
|
||||||
RUN apk add --no-cache ca-certificates
|
RUN apk add --no-cache ca-certificates
|
||||||
COPY --from=builder /build/xmpp-webhook /xmpp-webhook
|
COPY --from=builder /build/xmpp-webhook /xmpp-webhook
|
||||||
RUN adduser -D -g '' xmpp-webhook
|
RUN adduser -D -g '' xmpp-webhook
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
13
README.md
13
README.md
|
@ -6,6 +6,7 @@
|
||||||
`xmpp-webhook` currently support:
|
`xmpp-webhook` currently support:
|
||||||
|
|
||||||
- Grafana Webhook alerts
|
- Grafana Webhook alerts
|
||||||
|
- Alertmanager Webhooks
|
||||||
- Slack Incoming Webhooks (Feedback appreciated)
|
- Slack Incoming Webhooks (Feedback appreciated)
|
||||||
|
|
||||||
Check https://github.com/tmsmr/xmpp-webhook/blob/master/parser/ to learn how to support more source services.
|
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_SKIP_VERIFY` - Skip TLS verification (Optional)
|
||||||
- `XMPP_OVER_TLS` - Use dedicated TLS port (Optional)
|
- `XMPP_OVER_TLS` - Use dedicated TLS port (Optional)
|
||||||
- `XMPP_WEBHOOK_LISTEN_ADDRESS` - Bind address (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 @dev/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/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.
|
- 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`
|
- 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
|
## 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)
|
- 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 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`
|
- 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
|
- Clone the sources
|
||||||
- Change in the project folder:
|
- Change in the project folder:
|
||||||
- Build `xmpp-webhook`: `go build`
|
- 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?
|
## Need help?
|
||||||
Feel free to contact me!
|
Feel free to contact me!
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -9,4 +9,4 @@ require (
|
||||||
mellium.im/xmpp v0.18.0
|
mellium.im/xmpp v0.18.0
|
||||||
)
|
)
|
||||||
|
|
||||||
go 1.13
|
go 1.15
|
||||||
|
|
2
main.go
2
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("/grafana", newMessageHandler(messages, parser.GrafanaParserFunc))
|
||||||
http.Handle("/slack", newMessageHandler(messages, parser.SlackParserFunc))
|
http.Handle("/slack", newMessageHandler(messages, parser.SlackParserFunc))
|
||||||
http.Handle("/alertmanager", newMessageHandler(messages, parser.AlertmanagerParserFunc))
|
http.Handle("/alertmanager", newMessageHandler(messages, parser.AlertmanagerParserFunc))
|
||||||
|
|
|
@ -29,7 +29,7 @@ func AlertmanagerParserFunc(r *http.Request) (string, error) {
|
||||||
return "", errors.New(parseErr)
|
return "", errors.New(parseErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// contruct alert message
|
// construct alert message
|
||||||
var message string
|
var message string
|
||||||
for _, alert := range payload.Alerts {
|
for _, alert := range payload.Alerts {
|
||||||
if alert.Status == "resolved" {
|
if alert.Status == "resolved" {
|
||||||
|
|
|
@ -27,7 +27,7 @@ func GrafanaParserFunc(r *http.Request) (string, error) {
|
||||||
return "", errors.New(parseErr)
|
return "", errors.New(parseErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// contruct alert message
|
// construct alert message
|
||||||
var message string
|
var message string
|
||||||
switch alert.State {
|
switch alert.State {
|
||||||
case "ok":
|
case "ok":
|
||||||
|
|
|
@ -29,7 +29,7 @@ func SlackParserFunc(r *http.Request) (string, error) {
|
||||||
return "", errors.New(parseErr)
|
return "", errors.New(parseErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// contruct alert message
|
// construct alert message
|
||||||
message := alert.Text
|
message := alert.Text
|
||||||
for _, attachment := range alert.Attachments {
|
for _, attachment := range alert.Attachments {
|
||||||
if len(message) > 0 {
|
if len(message) > 0 {
|
||||||
|
|
Ładowanie…
Reference in New Issue