fix: batch update alert rule

This commit is contained in:
710leo 2021-08-26 11:03:32 +08:00
parent d92ca5f2a9
commit afb01b0258
2 changed files with 12 additions and 12 deletions

View File

@ -164,7 +164,7 @@ func alertRuleStatusPut(c *gin.Context) {
alertRuleWritePermCheck(arg, me)
}
renderMessage(c, models.AlertRuleUpdateStatus(f.Ids, f.Status))
renderMessage(c, models.AlertRuleUpdateStatus(f.Ids, f.Status, me.Username))
}
type alertRuleNotifyGroupsForm struct {
@ -189,7 +189,7 @@ func alertRuleNotifyGroupsPut(c *gin.Context) {
alertRuleWritePermCheck(arg, me)
}
renderMessage(c, models.AlertRuleUpdateNotifyGroups(f.Ids, f.NotifyGroups, f.NotifyUsers))
renderMessage(c, models.AlertRuleUpdateNotifyGroups(f.Ids, f.NotifyGroups, f.NotifyUsers, me.Username))
}
type alertRuleNotifyChannelsForm struct {
@ -211,7 +211,7 @@ func alertRuleNotifyChannelsPut(c *gin.Context) {
alertRuleWritePermCheck(arg, me)
}
renderMessage(c, models.AlertRuleUpdateNotifyChannels(f.Ids, f.NotifyChannels))
renderMessage(c, models.AlertRuleUpdateNotifyChannels(f.Ids, f.NotifyChannels, me.Username))
}
type alertRuleAppendTagsForm struct {
@ -233,7 +233,7 @@ func alertRuleAppendTagsPut(c *gin.Context) {
alertRuleWritePermCheck(arg, me)
}
renderMessage(c, models.AlertRuleUpdateAppendTags(f.Ids, f.AppendTags))
renderMessage(c, models.AlertRuleUpdateAppendTags(f.Ids, f.AppendTags, me.Username))
}
func alertRuleDel(c *gin.Context) {

View File

@ -291,23 +291,23 @@ func (ar *AlertRule) Update(cols ...string) error {
return nil
}
func AlertRuleUpdateStatus(ids []int64, status int) error {
_, err := DB.Exec("UPDATE alert_rule SET status=? WHERE id in ("+str.IdsString(ids)+")", status)
func AlertRuleUpdateStatus(ids []int64, status int, username string) error {
_, err := DB.Exec("UPDATE alert_rule SET status=?, update_at=?, update_by=? WHERE id in ("+str.IdsString(ids)+")", status, time.Now().Unix(), username)
return err
}
func AlertRuleUpdateNotifyGroups(ids []int64, notifyGroups string, notifyUsers string) error {
_, err := DB.Exec("UPDATE alert_rule SET notify_groups = ? , notify_users = ? where id in ("+str.IdsString(ids)+")", notifyGroups, notifyUsers)
func AlertRuleUpdateNotifyGroups(ids []int64, notifyGroups, notifyUsers, username string) error {
_, err := DB.Exec("UPDATE alert_rule SET notify_groups = ? , notify_users = ?, update_at = ?, update_by = ? where id in ("+str.IdsString(ids)+")", notifyGroups, notifyUsers, time.Now().Unix(), username)
return err
}
func AlertRuleUpdateNotifyChannels(ids []int64, notifyChannels string) error {
_, err := DB.Exec("UPDATE alert_rule SET notify_channels = ? where id in ("+str.IdsString(ids)+")", notifyChannels)
func AlertRuleUpdateNotifyChannels(ids []int64, notifyChannels, username string) error {
_, err := DB.Exec("UPDATE alert_rule SET notify_channels = ?, update_at = ?, update_by = ? where id in ("+str.IdsString(ids)+")", notifyChannels, time.Now().Unix(), username)
return err
}
func AlertRuleUpdateAppendTags(ids []int64, appendTags string) error {
_, err := DB.Exec("UPDATE alert_rule SET append_tags = ? where id in ("+str.IdsString(ids)+")", appendTags)
func AlertRuleUpdateAppendTags(ids []int64, appendTags, username string) error {
_, err := DB.Exec("UPDATE alert_rule SET append_tags = ?, update_at = ?, update_by = ? where id in ("+str.IdsString(ids)+")", appendTags, time.Now().Unix(), username)
return err
}