~fnux/matrix-alertmanager-receiver

8cf93a941b1d4969be10e7f7e4f8822c3de1d9b4 — Timothée Floure 7 months ago c29a683
Initial matrix client wiring
1 files changed, 28 insertions(+), 1 deletions(-)

M main.go
M main.go => main.go +28 -1
@@ 6,6 6,7 @@ import (
	"fmt"
	"log"
	"net/http"
	"github.com/matrix-org/gomatrix"
)

func main() {


@@ 13,11 14,37 @@ func main() {
	var logger *log.Logger = log.New(os.Stdout, "", log.Flags())

	// Handle command-line arguments.
	var homeserver = flag.String("homeserver", "https://matrix.org", "Address of Matrix homeserver")
	var user = flag.String("user", "", "Full MXID (e.g. @example.domain.tld) of Matrix user")
	var token = flag.String("token", "", "Access Token of Matrix user")
	var target = flag.String("target-room", "", "Matrix room to be notified of alerts.")
	var port = flag.Int("port", 9088, "HTTP port to listen on (incoming alertmanager webhooks)")
	flag.Parse()

	if *user == "" {
		logger.Fatal("Matrix user is required. See --help for usage.")
	}
	if *token == "" {
		logger.Fatal("Matrix access token is required. See --help for usage.")
	}
	if *target== "" {
		logger.Fatal("Matrix target room is required. See --help for usage.")
	}

	// Initialize Matrix client.
	// TODO
	matrixClient, err := gomatrix.NewClient(*homeserver, *user, *token)
	if err != nil {
		logger.Fatalf("Could not log in to Matrix (%v): %v", *homeserver, err)
	}

	/*
	logger.Printf("Syncing with Matrix homserver (%v)", *homeserver)
	err = matrixClient.Sync()
	if err != nil {
		logger.Fatalf("Could not sync with Matrix homeserver (%v): %v", *homeserver, err)
	}
	*/
	_ = matrixClient

	// Initialize HTTP serve (= listen for incoming requests).
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {