update rule test message api
This commit is contained in:
parent
d7f04395fd
commit
ad440995e9
|
@ -665,6 +665,7 @@ func (alertAPI *AlertAPI) enableRule(w http.ResponseWriter, req *http.Request, p
|
|||
}
|
||||
|
||||
func (alertAPI *AlertAPI) sendTestMessage(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||
typ := alertAPI.GetParameterOrDefault(req, "type", "notification")
|
||||
rule := alerting.Rule{}
|
||||
err := alertAPI.DecodeJSON(req, &rule)
|
||||
if err != nil {
|
||||
|
@ -678,7 +679,7 @@ func (alertAPI *AlertAPI) sendTestMessage(w http.ResponseWriter, req *http.Reque
|
|||
rule.ID = util.GetUUID()
|
||||
}
|
||||
eng := alerting2.GetEngine(rule.Resource.Type)
|
||||
actionResults, err := eng.Test(&rule)
|
||||
actionResults, err := eng.Test(&rule, typ)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
alertAPI.WriteJSON(w, util.MapStr{
|
||||
|
|
|
@ -930,7 +930,7 @@ func newParameterCtx(rule *alerting.Rule, checkResults *alerting.ConditionResult
|
|||
return paramsCtx
|
||||
}
|
||||
|
||||
func (engine *Engine) Test(rule *alerting.Rule) ([]alerting.ActionExecutionResult, error) {
|
||||
func (engine *Engine) Test(rule *alerting.Rule, msgType string) ([]alerting.ActionExecutionResult, error) {
|
||||
checkResults, err := engine.CheckCondition(rule)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("check condition error:%w", err)
|
||||
|
@ -946,10 +946,27 @@ func (engine *Engine) Test(rule *alerting.Rule) ([]alerting.ActionExecutionResul
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(rule.Channels.Normal) > 0 {
|
||||
actionResults, _ = performChannels(rule.Channels.Normal, paramsCtx)
|
||||
}else if len(rule.Channels.Escalation) > 0{
|
||||
actionResults, _ = performChannels(rule.Channels.Escalation, paramsCtx)
|
||||
var channels []alerting.Channel
|
||||
switch msgType {
|
||||
case "escalation":
|
||||
notifyCfg := rule.GetNotificationConfig()
|
||||
if notifyCfg == nil {
|
||||
return nil, nil
|
||||
}
|
||||
channels = notifyCfg.Escalation
|
||||
case "recover_notification":
|
||||
if rule.RecoveryNotificationConfig != nil {
|
||||
channels = rule.RecoveryNotificationConfig.Normal
|
||||
}
|
||||
case "notification":
|
||||
notifyCfg := rule.GetNotificationConfig()
|
||||
if notifyCfg == nil {
|
||||
return nil, nil
|
||||
}
|
||||
channels = notifyCfg.Normal
|
||||
}
|
||||
if len(channels) > 0 {
|
||||
actionResults, _ = performChannels(channels, paramsCtx)
|
||||
}else{
|
||||
return nil, fmt.Errorf("no useable channel")
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ type Engine interface {
|
|||
ExecuteQuery(rule *alerting.Rule, filterParam *alerting.FilterParam)(*alerting.QueryResult, error)
|
||||
CheckCondition(rule *alerting.Rule)(*alerting.ConditionResult, error)
|
||||
GenerateTask(rule alerting.Rule) func(ctx context.Context)
|
||||
Test(rule *alerting.Rule) ([]alerting.ActionExecutionResult, error)
|
||||
Test(rule *alerting.Rule, msgType string) ([]alerting.ActionExecutionResult, error)
|
||||
GetTargetMetricData(rule *alerting.Rule, isFilterNaN bool, filterParam *alerting.FilterParam)([]alerting.MetricData, *alerting.QueryResult, error)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue