warning.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package warning
  4. import (
  5. "gd_crontab/apis"
  6. "fmt"
  7. )
  8. // Warning 邮件预警预处理
  9. func Warning(req *apis.Warning) {
  10. for _,v := range req.WarningText{
  11. content := fmt.Sprintf("%s\n%s",req.Subject,v)
  12. err := RobotMsg(content)
  13. //collection := mongo.Session.DB(accessDB).C("mail_log")
  14. //errmsg := "发送钉钉消息成功"
  15. if err != nil{
  16. //errmsg = err.Error()
  17. }
  18. /*host := config.Conf.Warning.MailHost
  19. to := config.Conf.ThirdPart.DingTalkWebhook
  20. user := config.Conf.Warning.MailUser
  21. now := time.Now()
  22. collection.Insert(bson.M{"user": user, "host": host, "to": to, "body": content, "err": errmsg, "sendtime": now.Format("2006-01-02 15:04:05"), "timestamp": now.Unix()})*/
  23. }
  24. /*for _, v := range req.To {
  25. host := config.Conf.Warning.MailHost
  26. password := config.Conf.Warning.MailPassword
  27. to := v
  28. user := config.Conf.Warning.MailUser
  29. subject := req.Subject
  30. body := `
  31. <html>
  32. <body>
  33. <h3>
  34. content
  35. </h3>
  36. </body>
  37. </html>
  38. `
  39. body = strings.Replace(body, "content", req.WarningText, -1)
  40. err := SendToMail(user, password, host, to, subject, body, "html")
  41. errmsg = err.Error()
  42. if err != nil {
  43. errmsg = err.Error()
  44. }
  45. collection := mongo.Session.DB(accessDB).C("mail_log")
  46. now := time.Now()
  47. collection.Insert(bson.M{"user": user, "host": host, "to": to, "body": body, "err": errmsg, "sendtime": now.Format("2006-01-02 15:04:05"), "timestamp": now.Unix()})
  48. }*/
  49. }