feat: support batch edit notify groups of alert rule (#756)

This commit is contained in:
201806060205 2021-08-02 20:16:43 +08:00 committed by GitHub
parent 72244b1983
commit 5064e5b0b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 0 deletions

View File

@ -143,6 +143,7 @@ func configRoutes(r *gin.Engine) {
pages.POST("/alert-rules", login(), alertRuleAdd)
pages.PUT("/alert-rules/status", login(), alertRuleStatusPut)
pages.PUT("/alert-rules/notify-groups", login(), alertRuleNotifyGroupsPut)
pages.GET("/alert-rule/:id", login(), alertRuleGet)
pages.PUT("/alert-rule/:id", login(), alertRulePut)
pages.DELETE("/alert-rule/:id", login(), alertRuleDel)
@ -268,6 +269,7 @@ func configRoutes(r *gin.Engine) {
v1.POST("/alert-rules", login(), alertRuleAdd)
v1.PUT("/alert-rules/status", login(), alertRuleStatusPut)
v1.PUT("/alert-rules/notify-groups", login(), alertRuleNotifyGroupsPut)
v1.GET("/alert-rule/:id", login(), alertRuleGet)
v1.PUT("/alert-rule/:id", login(), alertRulePut)
v1.DELETE("/alert-rule/:id", login(), alertRuleDel)

View File

@ -168,6 +168,30 @@ func alertRuleStatusPut(c *gin.Context) {
renderMessage(c, models.AlertRuleUpdateStatus(f.Ids, f.Status))
}
type alertRuleNotifyGroupsForm struct {
Ids []int64 `json:"ids"`
NotifyGroups string `json:"notify_groups"`
}
func alertRuleNotifyGroupsPut(c *gin.Context) {
var f alertRuleNotifyGroupsForm
bind(c, &f)
//用户有修改告警策略的权限
me := loginUser(c).MustPerm("alert_rule_modify")
//id不存在
if len(f.Ids) == 0 {
bomb(http.StatusBadRequest, "ids is empty")
}
for _, id := range f.Ids {
alertRule := AlertRule(id)
arg := AlertRuleGroup(alertRule.GroupId)
alertRuleWritePermCheck(arg, me)
}
renderMessage(c, models.AlertRuleUpdateNotifyGroup(f.Ids, f.NotifyGroups))
}
func alertRuleDel(c *gin.Context) {
me := loginUser(c).MustPerm("alert_rule_delete")
alertRule := AlertRule(urlParamInt64(c, "id"))

View File

@ -296,6 +296,11 @@ func AlertRuleUpdateStatus(ids []int64, status int) error {
return err
}
func AlertRuleUpdateNotifyGroup(ids []int64, notifyGroups string) error {
_, err := DB.Exec("UPDATE alert_rule SET notify_groups = ? where id in ("+str.IdsString(ids)+")", notifyGroups)
return err
}
func AlertRuleTotal(query string) (num int64, err error) {
if query != "" {
q := "%" + query + "%"