notification.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. smtpAgent := smtpn.Agent{
  15. Hostname: *host_name,
  16. SMTPSender: "[email protected]",
  17. SMTPPassword: "",
  18. SMTPDomain: "mail.gandi.net",
  19. SMTPPort: 587,
  20. UsernameToEmailMap: map[string]string{},
  21. }
  22. notificationQueue.RegisterNotificationAgent(smtpAgent)
  23. go func() {
  24. time.Sleep(10 * time.Second)
  25. notificationQueue.BroadcastNotification(&notification.NotificationPayload{
  26. ID: strconv.Itoa(int(time.Now().Unix())),
  27. Title: "Disk SMART Error",
  28. 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.",
  29. Receiver: []string{"TC", "jk", "ay"},
  30. Sender: "SMART Nightly Scanner",
  31. ReciverAgents: []string{"smtpn"},
  32. })
  33. }()
  34. }