From c29a6832be5d3f345e66ed75a9a0f913eab4842d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Mon, 6 Apr 2020 18:12:43 +0200 Subject: [PATCH] Initial project structure, HTTP server --- .gitignore | 1 + Makefile | 12 ++++++++++++ README.md | 5 +++++ main.go | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a3c303 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +matrix-alertmanager-receiver diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..03b7e9f --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +NAME=matrix-alertmanager-receiver + +all: build + +getDeps: + go get -v + +build: + go build + +clean: + rm $(NAME) diff --git a/README.md b/README.md new file mode 100644 index 0000000..ef0579d --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# matrix-alertmanager-receiver + +TODO: synopsis, existing matrix-alermanager + +See `matrix-alermanager-receiver.scd` for usage. diff --git a/main.go b/main.go new file mode 100644 index 0000000..12aade8 --- /dev/null +++ b/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "os" + "flag" + "fmt" + "log" + "net/http" +) + +func main() { + // Initialize logger. + var logger *log.Logger = log.New(os.Stdout, "", log.Flags()) + + // Handle command-line arguments. + var port = flag.Int("port", 9088, "HTTP port to listen on (incoming alertmanager webhooks)") + flag.Parse() + + // Initialize Matrix client. + // TODO + + // Initialize HTTP serve (= listen for incoming requests). + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, `Hi! I receive prometheus-alertmanager webhooks on /alert and forward them to Matrix. + +You will find more details on: http://git.sr.ht/~fnux/matrix-prometheus-alertmanager`) + }) + + http.HandleFunc("/alert", func(w http.ResponseWriter, r *http.Request) { + }) + + var listenAddr = fmt.Sprintf(":%v", *port) + logger.Printf("Listening for HTTP requests (webhooks) on %v", listenAddr) + log.Fatal(http.ListenAndServe(listenAddr, nil)) +}