notification.go 1.6 KB

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