// Copyright 2019 getensh.com. All rights reserved. // Use of this source code is governed by getensh.com. package warning import ( "gd_crontab/apis" "fmt" ) // Warning 邮件预警预处理 func Warning(req *apis.Warning) { for _,v := range req.WarningText{ content := fmt.Sprintf("%s\n%s",req.Subject,v) err := RobotMsg(content) //collection := mongo.Session.DB(accessDB).C("mail_log") //errmsg := "发送钉钉消息成功" if err != nil{ //errmsg = err.Error() } /*host := config.Conf.Warning.MailHost to := config.Conf.ThirdPart.DingTalkWebhook user := config.Conf.Warning.MailUser now := time.Now() 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()})*/ } /*for _, v := range req.To { host := config.Conf.Warning.MailHost password := config.Conf.Warning.MailPassword to := v user := config.Conf.Warning.MailUser subject := req.Subject body := `

content

` body = strings.Replace(body, "content", req.WarningText, -1) err := SendToMail(user, password, host, to, subject, body, "html") errmsg = err.Error() if err != nil { errmsg = err.Error() } collection := mongo.Session.DB(accessDB).C("mail_log") now := time.Now() 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()}) }*/ }