Skip to content

Commit

Permalink
feat:add my alert rule callbacks api
Browse files Browse the repository at this point in the history
  • Loading branch information
710leo committed Dec 27, 2023
1 parent a8c0b3b commit ab38f22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions center/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func (rt *Router) Config(r *gin.Engine) {

pages.GET("/alert-rules/builtin/alerts-cates", rt.auth(), rt.user(), rt.builtinAlertCateGets)
pages.GET("/alert-rules/builtin/list", rt.auth(), rt.user(), rt.builtinAlertRules)
pages.GET("/alert-rules/callbacks", rt.auth(), rt.user(), rt.alertRuleCallbacks)

pages.GET("/busi-groups/alert-rules", rt.auth(), rt.user(), rt.perm("/alert-rules"), rt.alertRuleGetsByGids)
pages.GET("/busi-group/:id/alert-rules", rt.auth(), rt.user(), rt.perm("/alert-rules"), rt.alertRuleGets)
Expand Down
25 changes: 25 additions & 0 deletions center/router/router_alert_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,28 @@ func (rt *Router) alertRuleValidation(c *gin.Context) {

ginx.NewRender(c).Message("")
}

func (rt *Router) alertRuleCallbacks(c *gin.Context) {
user := c.MustGet("user").(*models.User)
gids, err := models.MyGroupIds(rt.Ctx, user.Id)
ginx.Dangerous(err)

bussGroupIds, err := models.BusiGroupIds(rt.Ctx, gids)
ginx.Dangerous(err)

ars, err := models.AlertRuleGetsByBGIds(rt.Ctx, bussGroupIds)
ginx.Dangerous(err)

var callbacks []string
callbackFilter := make(map[string]struct{})
for i := range ars {
for _, callback := range ars[i].CallbacksJSON {
if _, ok := callbackFilter[callback]; !ok {
callbackFilter[callback] = struct{}{}
callbacks = append(callbacks, callback)
}
}
}

ginx.NewRender(c).Data(callbacks, nil)
}

0 comments on commit ab38f22

Please sign in to comment.