~fnux/matrix-alertmanager-receiver

c29a6832be5d3f345e66ed75a9a0f913eab4842d — Timothée Floure 7 months ago f2aeec4
Initial project structure, HTTP server
4 files changed, 53 insertions(+), 0 deletions(-)

A .gitignore
A Makefile
A README.md
A main.go
A .gitignore => .gitignore +1 -0
@@ 0,0 1,1 @@
matrix-alertmanager-receiver

A Makefile => Makefile +12 -0
@@ 0,0 1,12 @@
NAME=matrix-alertmanager-receiver

all: build

getDeps:
	go get -v

build:
	go build

clean:
	rm $(NAME)

A README.md => README.md +5 -0
@@ 0,0 1,5 @@
# matrix-alertmanager-receiver

TODO: synopsis, existing matrix-alermanager

See `matrix-alermanager-receiver.scd` for usage.

A main.go => main.go +35 -0
@@ 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))
}