-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotification.go
67 lines (54 loc) · 1.88 KB
/
notification.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
package main
import (
"strconv"
"time"
fs "imuslab.com/arozos/mod/filesystem"
notification "imuslab.com/arozos/mod/notification"
"imuslab.com/arozos/mod/notification/agents/smtpn"
)
var notificationQueue *notification.NotificationQueue
func notificationInit() {
//Create a new notification agent
notificationQueue = notification.NewNotificationQueue()
//Register the notification agents
/*
SMTP Notification Agent
For handling notification sending via Mail
*/
//Load username and their email from authAgent
userEmailmap := map[string]string{}
allRecords := registerHandler.ListAllUserEmails()
for _, userRercord := range allRecords {
if userRercord[2].(bool) {
userEmailmap[userRercord[0].(string)] = userRercord[1].(string)
}
}
smtpnConfigPath := "./system/smtp_conf.json"
if !fs.FileExists(smtpnConfigPath) {
//Create an empty one
smtpn.GenerateEmptyConfigFile(smtpnConfigPath)
}
smtpAgent, err := smtpn.NewSMTPNotificationAgent(*host_name, smtpnConfigPath,
func(username string) (string, error) {
//Translate username to email
return registerHandler.GetUserEmail(username)
})
if err != nil {
systemWideLogger.PrintAndLog("Notification", "Unable to start smtpn agent: "+err.Error(), nil)
} else {
notificationQueue.RegisterNotificationAgent(smtpAgent)
}
//Create and register other notification agents
go func() {
time.Sleep(10 * time.Second)
return
notificationQueue.BroadcastNotification(¬ification.NotificationPayload{
ID: strconv.Itoa(int(time.Now().Unix())),
Title: "Email Test",
Message: "This is a testing notification for showcasing a sample email when DISK SMART error was scanned and discovered.<br> Please visit <a href='https://blog.teacat.io'>here</a> for more information.",
Receiver: []string{"TC"},
Sender: "SMART Nightly Scanner",
ReciverAgents: []string{"smtpn"},
})
}()
}