-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (45 loc) · 1.03 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
package main
import (
"github.com/itsTurnip/albion-status-checker/checker"
"os"
"os/signal"
"syscall"
log "github.com/sirupsen/logrus"
)
func main() {
config := parseEnv()
if len(config.Webhooks) == 0 {
log.Fatal("Webhook url environment variable is not set")
}
log.SetLevel(config.LogLevel)
check := checker.NewChecker()
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
log.Info("Getting current status...")
err := check.CheckStatus()
if err != nil {
log.Fatal(err)
}
status := <-check.Changes
log.Info("Current server status: ", status.Status)
err = check.Start()
if err != nil {
log.Fatal(err)
}
go func() {
<-sc
err := check.Stop()
if err != nil {
log.Errorf("Error stopping checker %s", err)
}
}()
log.Info("Started checking")
for message := range check.Changes {
for _, webhook := range config.Webhooks {
err := SendStatusChangeWebhook(webhook, message)
if err != nil {
log.Errorf("Error occurred sending status change: %s", err)
}
}
}
}