-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
50 lines (41 loc) · 1.2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"net/http"
"os"
"github.com/mobalyticshq/alertsforge/alertsource"
"github.com/mobalyticshq/alertsforge/config"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
loggerConfig := zap.NewDevelopmentConfig()
loggerConfig.Level.SetLevel(zapcore.InfoLevel)
logger, err := loggerConfig.Build()
defer logger.Sync()
zap.ReplaceGlobals(logger)
log := logger.Sugar()
if err != nil {
log.Fatal(err)
}
configLoader := config.Config{}
runbooks, err := configLoader.LoadRunbooksConfig("./config/runbooks.yaml")
if err != nil {
log.Fatalf("error during structure loading: %v", err)
}
am := alertsource.NewAlertManager(runbooks)
http.HandleFunc("/healthz", healthz)
http.HandleFunc("/alertWebhook/api/v2/alerts", am.AlertWebhook)
http.HandleFunc("/processAlertBuffer", am.ProcessAlertsBufferWebhook)
http.HandleFunc("/showAlertBuffer", am.ShowAlertsBufferWebhook)
go am.AlertsProcessor()
listenAddress := ":8080"
if os.Getenv("PORT") != "" {
listenAddress = ":" + os.Getenv("PORT")
}
log.Info("listening on: ", listenAddress)
log.Fatal(http.ListenAndServe(listenAddress, nil))
}
func healthz(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Ok!")
}