refresh email server pipeline when config change

This commit is contained in:
liugq 2023-07-26 15:16:16 +08:00
parent d08c430356
commit 4223bd052d
3 changed files with 19 additions and 44 deletions

View File

@ -5,6 +5,7 @@
package email
import (
"infini.sh/console/plugin/api/email/common"
"infini.sh/framework/core/api"
)
@ -21,31 +22,9 @@ func InitAPI() {
api.HandleAPIMethod(api.GET, "/email/server/_search", email.searchEmailServer)
}
//func InitEmailServer() error {
// q := orm.Query{
// Size: 10,
// }
// q.Conds = orm.And(orm.Eq("enabled", true))
// err, result := orm.Search(model.EmailServer{}, &q )
// if err != nil {
// return err
// }
// if len(result.Result) == 0 {
// return nil
// }
// for _, row := range result.Result {
// emailServer := model.EmailServer{}
// buf := util.MustToJSONBytes(row)
// util.MustFromJSONBytes(buf, &emailServer)
// err = emailServer.Validate(false)
// if err != nil {
// log.Error(err)
// continue
// }
// err = common.StartEmailServer(&emailServer)
// if err != nil {
// log.Error(err)
// }
// }
// return nil
//}
func InitEmailServer() error {
if !common.CheckEmailPipelineExists() {
return common.RefreshEmailServer()
}
return nil
}

View File

@ -148,11 +148,9 @@ func (h *EmailAPI) updateEmailServer(w http.ResponseWriter, req *http.Request, p
log.Error(err)
return
}
if obj.Enabled {
err = common.RefreshEmailServer()
if err != nil {
log.Error(err)
}
err = common.RefreshEmailServer()
if err != nil {
log.Error(err)
}
h.WriteJSON(w, util.MapStr{

View File

@ -682,18 +682,16 @@ func (engine *Engine) Do(rule *alerting.Rule) error {
// send recover message to channel
recoverCfg := rule.RecoveryNotificationConfig
if recoverCfg != nil && recoverCfg.Enabled {
if recoverCfg.AcceptTimeRange.Include(time.Now()) {
paramsCtx = newParameterCtx(rule, checkResults, util.MapStr{
alerting2.ParamEventID: alertItem.ID,
alerting2.ParamTimestamp: alertItem.Created.Unix(),
})
err = attachTitleMessageToCtx(recoverCfg.Title, recoverCfg.Message, paramsCtx)
if err != nil {
return err
}
actionResults, _ := performChannels(recoverCfg.Channels, paramsCtx)
alertItem.ActionExecutionResults = actionResults
paramsCtx = newParameterCtx(rule, checkResults, util.MapStr{
alerting2.ParamEventID: alertItem.ID,
alerting2.ParamTimestamp: alertItem.Created.Unix(),
})
err = attachTitleMessageToCtx(recoverCfg.Title, recoverCfg.Message, paramsCtx)
if err != nil {
return err
}
actionResults, _ := performChannels(recoverCfg.Channels, paramsCtx)
alertItem.ActionExecutionResults = actionResults
}
}
return nil