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 package email
import ( import (
"infini.sh/console/plugin/api/email/common"
"infini.sh/framework/core/api" "infini.sh/framework/core/api"
) )
@ -21,31 +22,9 @@ func InitAPI() {
api.HandleAPIMethod(api.GET, "/email/server/_search", email.searchEmailServer) api.HandleAPIMethod(api.GET, "/email/server/_search", email.searchEmailServer)
} }
//func InitEmailServer() error { func InitEmailServer() error {
// q := orm.Query{ if !common.CheckEmailPipelineExists() {
// Size: 10, return common.RefreshEmailServer()
// } }
// q.Conds = orm.And(orm.Eq("enabled", true)) return nil
// 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
//}

View File

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

View File

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