-
Notifications
You must be signed in to change notification settings - Fork 8
/
notifications.go
101 lines (88 loc) · 2.8 KB
/
notifications.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package notifications
import (
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
type Notification interface {
Notify(string, string, string, string) bool
}
type Notifications struct {
EnabledServices []Notification
config viper.Viper
Log log.Logger
}
func (n Notifications) Notify(title string, description string, notifType string, path string) {
for _, service := range n.EnabledServices {
service.Notify(title, description, notifType, path)
}
}
func (n *Notifications) Connect() {
if n.config.Sub("discord") != nil {
discord := DiscordWebhook{}
discord.FromConfig(*n.config.Sub("discord"))
discordConnected, discordMessage := discord.Connect()
n.Log.WithFields(log.Fields{"Startup": true, "Discord Connected": discordConnected}).Info(discordMessage)
if discordConnected {
n.EnabledServices = append(n.EnabledServices, discord)
}
}
if n.config.Sub("healthchecks") != nil {
healthcheck := Healthchecks{}
healthcheck.FromConfig(*n.config.Sub("healthchecks"))
healthcheckConnected := healthcheck.Connect()
if healthcheckConnected {
n.EnabledServices = append(n.EnabledServices, healthcheck)
}
}
if n.config.Sub("telegram") != nil {
telegram := Telegram{Log: *log.StandardLogger()}
telegram.FromConfig(*n.config.Sub("telegram"))
telegramConnected := telegram.Connect()
if telegramConnected {
n.EnabledServices = append(n.EnabledServices, telegram)
}
}
if n.config.Sub("webhook") != nil {
webhook := Notifywebhook{Log: *log.StandardLogger()}
webhook.FromConfig(*n.config.Sub("webhook"))
webhookConnected := webhook.Connect()
if webhookConnected {
n.EnabledServices = append(n.EnabledServices, webhook)
}
}
if n.config.Sub("pushbullet") != nil {
pushbullet := Pushbullet{Log: *log.StandardLogger()}
pushbullet.FromConfig(*n.config.Sub("pushbullet"))
pushbulletConnected := pushbullet.Connect()
if pushbulletConnected {
n.EnabledServices = append(n.EnabledServices, pushbullet)
}
}
if n.config.Sub("pushover") != nil {
pushover := Pushover{Log: *log.StandardLogger()}
pushover.FromConfig(*n.config.Sub("pushover"))
pushoverConnected := pushover.Connect()
if pushoverConnected {
n.EnabledServices = append(n.EnabledServices, pushover)
}
}
if n.config.Sub("gotify") != nil {
gotify := GotifyNotifs{Log: *log.StandardLogger()}
gotify.FromConfig(*n.config.Sub("gotify"))
gotifyConnected := gotify.Connect()
if gotifyConnected {
n.EnabledServices = append(n.EnabledServices, gotify)
}
}
if n.config.Sub("splunk") != nil {
splunk := SplunkHEC{Log: *log.StandardLogger()}
splunk.FromConfig(*n.config.Sub("splunk"))
splunkConnected := splunk.Connect()
if splunkConnected {
n.EnabledServices = append(n.EnabledServices, splunk)
}
}
}
func (n *Notifications) FromConfig(c viper.Viper) {
n.config = c
}