alaram_msg.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_robot/cache"
  5. "hongze/hongze_robot/models"
  6. "hongze/hongze_robot/services"
  7. "hongze/hongze_robot/utils"
  8. )
  9. //监控信息管理
  10. type AlarmMsgController struct {
  11. BaseCommonController
  12. }
  13. // @Title 监控信息发送接口
  14. // @Description 监控信息发送接口
  15. // @Param request body company.CompanyApplyApproveReq true "type json string"
  16. // @Success Ret=200 转发成功
  17. // @router /send [post]
  18. func (this *AlarmMsgController) SmsSend() {
  19. br := new(models.BaseResponse).Init()
  20. var err error
  21. defer func() {
  22. if err != nil {
  23. utils.FileLog.Info("send msg err: %s", err.Error())
  24. }
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. reqBody := this.Ctx.Input.RequestBody
  29. utils.FileLog.Info("%s", string(reqBody))
  30. var req *models.AlarmMsgReq
  31. err = json.Unmarshal(reqBody, &req)
  32. if err != nil {
  33. br.Msg = "参数解析异常!"
  34. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  35. return
  36. }
  37. if req.MsgBody == "" {
  38. br.Ret = 200
  39. br.Success = true
  40. br.Msg = "发送失败,消息内容为空"
  41. return
  42. }
  43. //钉钉
  44. {
  45. go services.SendAlarmMsgByDingTalk(req.ProjectName, req.RunMode, req.MsgBody, req.Level)
  46. }
  47. //邮箱
  48. {
  49. configItem, _ := cache.GetSmsConfigByCache("email")
  50. if configItem != nil {
  51. go services.SendAlarmMsgByEmail(req.ProjectName, req.RunMode, req.MsgBody, configItem.ConfigValue, req.Level)
  52. }
  53. }
  54. br.Ret = 200
  55. br.Success = true
  56. br.Msg = "发送成功"
  57. }