~fnux/matrix-alertmanager-receiver

fd35273ed4d59c0f8556b722565546e72883e58b — Timothée Floure 6 months ago 560f0db
Refactor config loading, message formatting
1 files changed, 5 insertions(+), 11 deletions(-)

M main.go
M main.go => main.go +5 -11
@@ 2,18 2,18 @@ package main

import (
	"os"
	"flag"
	"fmt"
	"log"
	"io/ioutil"
	"flag"
	"net/http"
	"encoding/json"
	"github.com/prometheus/alertmanager/template"
	"github.com/BurntSushi/toml"
	"github.com/matrix-org/gomatrix"
	"github.com/prometheus/alertmanager/template"
)

var logger *log.Logger
var config Configuration

type Configuration struct {
	Homeserver string


@@ 27,7 27,7 @@ type Configuration struct {
}

func generateMatrixMessageBody(alert template.Alert) string {
	return alert.Status + " // " + alert.Annotations["summary"]
	return fmt.Sprintf("**%v** %v.", alert.Status, alert.Annotations["summary"])
}

func getMatrixClient(homeserver string, user string, token string, targetRoomID string) *gomatrix.Client {


@@ 99,13 99,7 @@ func main() {
	flag.Parse()

	logger.Printf("Reading configuration from %v.", *configPath)
	raw, err := ioutil.ReadFile(*configPath)
	if err != nil {
		logger.Fatalf("Could not read configuration file (%v): %v", *configPath, err)
	}

	var config Configuration
	md, err := toml.Decode(string(raw), &config)
	md, err := toml.DecodeFile(*configPath, &config)
	if err != nil {
		logger.Fatalf("Could not parse configuration file (%v): %v", *configPath, err)
	}