From de700144351dfb862d7d3d152bb61517c7991c61 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Mon, 20 Dec 2021 11:53:31 +0100 Subject: [PATCH] alertbot: cleanup old files --- docker-compose.yml | 2 +- prometheus-alertmanager-discord/Dockerfile | 43 ------------ prometheus-alertmanager-discord/main.go | 82 ---------------------- 3 files changed, 1 insertion(+), 126 deletions(-) delete mode 100644 prometheus-alertmanager-discord/Dockerfile delete mode 100644 prometheus-alertmanager-discord/main.go diff --git a/docker-compose.yml b/docker-compose.yml index a146739..7996ee8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/prometheus-alertmanager-discord/Dockerfile b/prometheus-alertmanager-discord/Dockerfile deleted file mode 100644 index 5489508..0000000 --- a/prometheus-alertmanager-discord/Dockerfile +++ /dev/null @@ -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"] diff --git a/prometheus-alertmanager-discord/main.go b/prometheus-alertmanager-discord/main.go deleted file mode 100644 index 944dc73..0000000 --- a/prometheus-alertmanager-discord/main.go +++ /dev/null @@ -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)) - })) -} -