diff --git a/src/webapi/router/router_alert_rule.go b/src/webapi/router/router_alert_rule.go index ce330083..7bd2fe30 100644 --- a/src/webapi/router/router_alert_rule.go +++ b/src/webapi/router/router_alert_rule.go @@ -65,10 +65,35 @@ func alertRuleAddByService(c *gin.Context) { if count == 0 { ginx.Bomb(http.StatusBadRequest, "input json is empty") } - reterr := alertRuleAdd(lst, "", 0, c.GetHeader("X-Language")) + reterr := alertRuleAddForService(lst, "") ginx.NewRender(c).Data(reterr, nil) } +func alertRuleAddForService(lst []models.AlertRule, username string) map[string]string { + count := len(lst) + // alert rule name -> error string + reterr := make(map[string]string) + for i := 0; i < count; i++ { + lst[i].Id = 0 + if username != "" { + lst[i].CreateBy = username + lst[i].UpdateBy = username + } + + if err := lst[i].FE2DB(); err != nil { + reterr[lst[i].Name] = err.Error() + continue + } + + if err := lst[i].Add(); err != nil { + reterr[lst[i].Name] = err.Error() + } else { + reterr[lst[i].Name] = "" + } + } + return reterr +} + func alertRuleAdd(lst []models.AlertRule, username string, bgid int64, lang string) map[string]string { count := len(lst) // alert rule name -> error string