alertbot: cleanup old files
This commit is contained in:
parent
cb823d84d7
commit
de70014435
3 changed files with 1 additions and 126 deletions
|
@ -91,7 +91,7 @@ services:
|
|||
build: kanbot
|
||||
restart: always
|
||||
volumes:
|
||||
- ./kanbot_config/config.yaml:/var/www/kanbot/config.yaml:ro
|
||||
- ./kanbot_data/config.yaml:/var/www/kanbot/config.yaml:ro
|
||||
|
||||
miniflux:
|
||||
image: miniflux/miniflux
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
# Built following https://medium.com/@chemidy/create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324
|
||||
|
||||
# STEP 1 build executable binary
|
||||
FROM golang:alpine as builder
|
||||
|
||||
# BUILD_DATE and VCS_REF are immaterial, since this is a 2-stage build, but our build
|
||||
# hook won't work unless we specify the args
|
||||
ARG BUILD_DATE
|
||||
ARG VCS_REF
|
||||
|
||||
# Install SSL ca certificates
|
||||
RUN apk update && apk add git && apk add ca-certificates
|
||||
# Create appuser
|
||||
RUN adduser -D -g '' appuser
|
||||
COPY . $GOPATH/src/mypackage/myapp/
|
||||
WORKDIR $GOPATH/src/mypackage/myapp/
|
||||
#get dependancies
|
||||
RUN go get -d -v
|
||||
#build the binary
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-w -s" -o /go/bin/alertmanager-discord
|
||||
|
||||
|
||||
# STEP 2 build a small image
|
||||
# start from scratch
|
||||
FROM scratch
|
||||
# Now we DO need these, for the auto-labeling of the image
|
||||
ARG BUILD_DATE
|
||||
ARG VCS_REF
|
||||
|
||||
# Good docker practice, plus we get microbadger badges
|
||||
LABEL org.label-schema.build-date=$BUILD_DATE \
|
||||
org.label-schema.vcs-url="https://github.com/funkypenguin/alertmanager-discord.git" \
|
||||
org.label-schema.vcs-ref=$VCS_REF \
|
||||
org.label-schema.schema-version="2.2-r1"
|
||||
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=builder /etc/passwd /etc/passwd
|
||||
# Copy our static executable
|
||||
COPY --from=builder /go/bin/alertmanager-discord /go/bin/alertmanager-discord
|
||||
|
||||
EXPOSE 9094
|
||||
USER appuser
|
||||
ENTRYPOINT ["/go/bin/alertmanager-discord"]
|
|
@ -1,82 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type alertManOut struct {
|
||||
Alerts []struct {
|
||||
Annotations struct {
|
||||
Description string `json:"description"`
|
||||
Summary string `json:"summary"`
|
||||
} `json:"annotations"`
|
||||
EndsAt string `json:"endsAt"`
|
||||
GeneratorURL string `json:"generatorURL"`
|
||||
Labels map[string]string `json:"labels"`
|
||||
StartsAt string `json:"startsAt"`
|
||||
Status string `json:"status"`
|
||||
} `json:"alerts"`
|
||||
CommonAnnotations struct {
|
||||
Summary string `json:"summary"`
|
||||
} `json:"commonAnnotations"`
|
||||
CommonLabels struct {
|
||||
Alertname string `json:"alertname"`
|
||||
} `json:"commonLabels"`
|
||||
ExternalURL string `json:"externalURL"`
|
||||
GroupKey string `json:"groupKey"`
|
||||
GroupLabels struct {
|
||||
Alertname string `json:"alertname"`
|
||||
} `json:"groupLabels"`
|
||||
Receiver string `json:"receiver"`
|
||||
Status string `json:"status"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type discordOut struct {
|
||||
Content string `json:"content"`
|
||||
Name string `json:"username"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
webhookUrl := os.Getenv("DISCORD_WEBHOOK")
|
||||
if webhookUrl == "" {
|
||||
fmt.Fprintf(os.Stderr, "error: environment variable DISCORD_WEBHOOK not found\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
whURL := flag.String("webhook.url", webhookUrl, "")
|
||||
flag.Parse()
|
||||
fmt.Fprintf(os.Stdout, "info: Listening on 0.0.0.0:9094\n")
|
||||
http.ListenAndServe(":9094", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
b, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
amo := alertManOut{}
|
||||
err = json.Unmarshal(b, &amo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Format alerts
|
||||
Content := "\n"
|
||||
for _, alert := range amo.Alerts {
|
||||
Content += fmt.Sprintf("*%s* **%s** %s\n", alert.Labels["alertname"], alert.Labels["severity"], alert.Annotations.Summary)
|
||||
}
|
||||
|
||||
// Send to Discord
|
||||
DO := discordOut{
|
||||
Name: "Prometheus 🦋️",
|
||||
Content: Content,
|
||||
}
|
||||
DOD, _ := json.Marshal(DO)
|
||||
http.Post(*whURL, "application/json", bytes.NewReader(DOD))
|
||||
}))
|
||||
}
|
||||
|
Loading…
Reference in a new issue