alarm_msg.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package alarm_msg
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/http"
  5. "hongze/hongze_task/utils"
  6. )
  7. var (
  8. AlarmMsgUrl = "http://127.0.0.1:8606/api/alarm/send"
  9. )
  10. // projectName-项目名称
  11. // runMode-运行模式
  12. // msgBody-消息内容
  13. // level:消息基本,1:提示消息,2:警告消息,3:严重错误信息,默认为1 提示消息
  14. func SendAlarmMsg(msgBody string, level int) {
  15. params := make(map[string]interface{})
  16. params["ProjectName"] = utils.APPNAME
  17. params["RunMode"] = utils.RunMode
  18. params["MsgBody"] = msgBody
  19. params["Level"] = level
  20. param, err := json.Marshal(params)
  21. if err != nil {
  22. utils.FileLog.Info("SendAlarmMsg json.Marshal Err:" + err.Error())
  23. return
  24. }
  25. http.Post(AlarmMsgUrl, string(param), "application/json")
  26. }
  27. // SendAlarmMsgWithEmail 指定邮箱通知
  28. // projectName-项目名称
  29. // runMode-运行模式
  30. // msgBody-消息内容
  31. // email-需要发送的邮箱
  32. // level:消息基本,1:提示消息,2:警告消息,3:严重错误信息,默认为1 提示消息
  33. func SendAlarmMsgWithEmail(msgBody, email string, level int) {
  34. params := make(map[string]interface{})
  35. params["ProjectName"] = utils.APPNAME
  36. params["RunMode"] = utils.RunMode
  37. params["MsgBody"] = msgBody
  38. params["Email"] = email
  39. params["Level"] = level
  40. param, err := json.Marshal(params)
  41. if err != nil {
  42. utils.FileLog.Info("SendAlarmMsg json.Marshal Err:" + err.Error())
  43. return
  44. }
  45. http.Post(AlarmMsgUrl, string(param), "application/json")
  46. }