(create dto.AlertLogCreate, alert dto.AlertDTO, params []dto.Param, transport *http.Transport, agentInfo *dto.AgentInfo, barkConfig model.AlertConfig)
| 101 | } |
| 102 | |
| 103 | func CreateBarkAlertLog(create dto.AlertLogCreate, alert dto.AlertDTO, params []dto.Param, transport *http.Transport, agentInfo *dto.AgentInfo, barkConfig model.AlertConfig) error { |
| 104 | var alertLog model.AlertLog |
| 105 | |
| 106 | var barkInfo dto.AlertWebhookConfig |
| 107 | err := json.Unmarshal([]byte(barkConfig.Config), &barkInfo) |
| 108 | if err != nil { |
| 109 | return err |
| 110 | } |
| 111 | if barkInfo.Url == "" { |
| 112 | create.Message = "bark config url is required" |
| 113 | create.Status = constant.AlertError |
| 114 | return SaveAlertLog(create, &alertLog) |
| 115 | } |
| 116 | |
| 117 | content := GetSendContent(alert.Type, params, agentInfo) |
| 118 | if content == "" { |
| 119 | content = i18n.GetMsgWithMap("CommonAlert", map[string]interface{}{"msg": alert.Title}) |
| 120 | } |
| 121 | |
| 122 | if err = bark.SendMessage(barkInfo.Url, i18n.GetMsgByKey("PanelAlertTitle"), content, transport); err != nil { |
| 123 | create.Message = err.Error() |
| 124 | create.Status = constant.AlertError |
| 125 | return SaveAlertLog(create, &alertLog) |
| 126 | } |
| 127 | create.Status = constant.AlertSuccess |
| 128 | return SaveAlertLog(create, &alertLog) |
| 129 | } |
| 130 | |
| 131 | func SaveAlertLog(create dto.AlertLogCreate, alertLog *model.AlertLog) error { |
| 132 | alertRepo := repo.NewIAlertRepo() |
nothing calls this directly
no test coverage detected