notification.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "log"
  4. "strconv"
  5. "time"
  6. notification "imuslab.com/arozos/mod/notification"
  7. "imuslab.com/arozos/mod/notification/agents/smtpn"
  8. )
  9. var notificationQueue *notification.NotificationQueue
  10. func notificationInit() {
  11. //Create a new notification agent
  12. notificationQueue = notification.NewNotificationQueue()
  13. //Register the notification agents
  14. //SMTP Mail Sender
  15. //Load configuration from database
  16. //Load username and their email from authAgent
  17. userEmailmap := map[string]string{}
  18. allRecords := registerHandler.ListAllUserEmails()
  19. for _, userRercord := range allRecords {
  20. if userRercord[2].(bool) {
  21. userEmailmap[userRercord[0].(string)] = userRercord[1].(string)
  22. }
  23. }
  24. log.Println(userEmailmap)
  25. smtpAgent := smtpn.Agent{
  26. Hostname: *host_name,
  27. SMTPSender: "[email protected]",
  28. SMTPPassword: "noreplypassword",
  29. SMTPDomain: "mail.gandi.net",
  30. SMTPPort: 587,
  31. UsernameToEmailMap: userEmailmap,
  32. }
  33. notificationQueue.RegisterNotificationAgent(smtpAgent)
  34. //Create and register other notification agents
  35. go func() {
  36. time.Sleep(10 * time.Second)
  37. return
  38. notificationQueue.BroadcastNotification(&notification.NotificationPayload{
  39. ID: strconv.Itoa(int(time.Now().Unix())),
  40. Title: "Disk SMART Error",
  41. 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.",
  42. Receiver: []string{"TC"},
  43. Sender: "SMART Nightly Scanner",
  44. ReciverAgents: []string{"smtpn"},
  45. })
  46. }()
  47. }