feat: support batch edit notify groups of alert rule (#756)
This commit is contained in:
parent
72244b1983
commit
5064e5b0b1
|
@ -143,6 +143,7 @@ func configRoutes(r *gin.Engine) {
|
||||||
|
|
||||||
pages.POST("/alert-rules", login(), alertRuleAdd)
|
pages.POST("/alert-rules", login(), alertRuleAdd)
|
||||||
pages.PUT("/alert-rules/status", login(), alertRuleStatusPut)
|
pages.PUT("/alert-rules/status", login(), alertRuleStatusPut)
|
||||||
|
pages.PUT("/alert-rules/notify-groups", login(), alertRuleNotifyGroupsPut)
|
||||||
pages.GET("/alert-rule/:id", login(), alertRuleGet)
|
pages.GET("/alert-rule/:id", login(), alertRuleGet)
|
||||||
pages.PUT("/alert-rule/:id", login(), alertRulePut)
|
pages.PUT("/alert-rule/:id", login(), alertRulePut)
|
||||||
pages.DELETE("/alert-rule/:id", login(), alertRuleDel)
|
pages.DELETE("/alert-rule/:id", login(), alertRuleDel)
|
||||||
|
@ -268,6 +269,7 @@ func configRoutes(r *gin.Engine) {
|
||||||
|
|
||||||
v1.POST("/alert-rules", login(), alertRuleAdd)
|
v1.POST("/alert-rules", login(), alertRuleAdd)
|
||||||
v1.PUT("/alert-rules/status", login(), alertRuleStatusPut)
|
v1.PUT("/alert-rules/status", login(), alertRuleStatusPut)
|
||||||
|
v1.PUT("/alert-rules/notify-groups", login(), alertRuleNotifyGroupsPut)
|
||||||
v1.GET("/alert-rule/:id", login(), alertRuleGet)
|
v1.GET("/alert-rule/:id", login(), alertRuleGet)
|
||||||
v1.PUT("/alert-rule/:id", login(), alertRulePut)
|
v1.PUT("/alert-rule/:id", login(), alertRulePut)
|
||||||
v1.DELETE("/alert-rule/:id", login(), alertRuleDel)
|
v1.DELETE("/alert-rule/:id", login(), alertRuleDel)
|
||||||
|
|
|
@ -168,6 +168,30 @@ func alertRuleStatusPut(c *gin.Context) {
|
||||||
renderMessage(c, models.AlertRuleUpdateStatus(f.Ids, f.Status))
|
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) {
|
func alertRuleDel(c *gin.Context) {
|
||||||
me := loginUser(c).MustPerm("alert_rule_delete")
|
me := loginUser(c).MustPerm("alert_rule_delete")
|
||||||
alertRule := AlertRule(urlParamInt64(c, "id"))
|
alertRule := AlertRule(urlParamInt64(c, "id"))
|
||||||
|
|
|
@ -296,6 +296,11 @@ func AlertRuleUpdateStatus(ids []int64, status int) error {
|
||||||
return err
|
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) {
|
func AlertRuleTotal(query string) (num int64, err error) {
|
||||||
if query != "" {
|
if query != "" {
|
||||||
q := "%" + query + "%"
|
q := "%" + query + "%"
|
||||||
|
|
Loading…
Reference in New Issue