MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / CreateBarkAlertLog

Function CreateBarkAlertLog

agent/utils/alert/alert.go:103–129  ·  view source on GitHub ↗
(create dto.AlertLogCreate, alert dto.AlertDTO, params []dto.Param, transport *http.Transport, agentInfo *dto.AgentInfo, barkConfig model.AlertConfig)

Source from the content-addressed store, hash-verified

101}
102
103func 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
131func SaveAlertLog(create dto.AlertLogCreate, alertLog *model.AlertLog) error {
132 alertRepo := repo.NewIAlertRepo()

Callers

nothing calls this directly

Calls 3

SaveAlertLogFunction · 0.85
GetSendContentFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected