|
@@ -1,6 +1,7 @@
|
|
package main
|
|
package main
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "log"
|
|
"strconv"
|
|
"strconv"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
@@ -17,7 +18,6 @@ func notificationInit() {
|
|
//Register the notification agents
|
|
//Register the notification agents
|
|
|
|
|
|
//SMTP Mail Sender
|
|
//SMTP Mail Sender
|
|
- //Load configuration from database
|
|
|
|
|
|
|
|
//Load username and their email from authAgent
|
|
//Load username and their email from authAgent
|
|
userEmailmap := map[string]string{}
|
|
userEmailmap := map[string]string{}
|
|
@@ -28,27 +28,31 @@ func notificationInit() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //log.Println(userEmailmap)
|
|
|
|
-
|
|
|
|
- smtpAgent := smtpn.Agent{
|
|
|
|
- Hostname: *host_name,
|
|
|
|
- SMTPSender: "[email protected]",
|
|
|
|
- SMTPPassword: "",
|
|
|
|
- SMTPDomain: "mail.gandi.net",
|
|
|
|
- SMTPPort: 587,
|
|
|
|
- UsernameToEmailMap: userEmailmap,
|
|
|
|
|
|
+ smtpnConfigPath := "./system/smtp_conf.json"
|
|
|
|
+ if !fileExists(smtpnConfigPath) {
|
|
|
|
+ //Create an empty one
|
|
|
|
+ smtpn.GenerateEmptyConfigFile(smtpnConfigPath)
|
|
}
|
|
}
|
|
|
|
|
|
- notificationQueue.RegisterNotificationAgent(smtpAgent)
|
|
|
|
|
|
+ smtpAgent, err := smtpn.NewSMTPNotificationAgent(*host_name, smtpnConfigPath,
|
|
|
|
+ func(username string) (string, error) {
|
|
|
|
+ //Translate username to email
|
|
|
|
+ return registerHandler.GetUserEmail(username)
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("[Notification/SMTPN] Unable to start smtpn agent: " + err.Error())
|
|
|
|
+ } else {
|
|
|
|
+ notificationQueue.RegisterNotificationAgent(smtpAgent)
|
|
|
|
+ }
|
|
|
|
|
|
//Create and register other notification agents
|
|
//Create and register other notification agents
|
|
|
|
|
|
go func() {
|
|
go func() {
|
|
time.Sleep(10 * time.Second)
|
|
time.Sleep(10 * time.Second)
|
|
- return
|
|
|
|
notificationQueue.BroadcastNotification(¬ification.NotificationPayload{
|
|
notificationQueue.BroadcastNotification(¬ification.NotificationPayload{
|
|
ID: strconv.Itoa(int(time.Now().Unix())),
|
|
ID: strconv.Itoa(int(time.Now().Unix())),
|
|
- Title: "Disk SMART Error",
|
|
|
|
|
|
+ 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.",
|
|
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"},
|
|
Receiver: []string{"TC"},
|
|
Sender: "SMART Nightly Scanner",
|
|
Sender: "SMART Nightly Scanner",
|