diff --git a/http/router_alert_rule.go b/http/router_alert_rule.go index 3953922a4ebebee52234eaf3d0a84f6248ffffe3..83d5fba04267d54af3a46428fb1c6fe1509a6f3b 100644 --- a/http/router_alert_rule.go +++ b/http/router_alert_rule.go @@ -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) { diff --git a/models/alert_rule.go b/models/alert_rule.go index fd49224bc62df2cf41a546e1e10765033f2c5ce1..8d08f082dda1d926cc2459f3aa5add78f1bc5bc9 100644 --- a/models/alert_rule.go +++ b/models/alert_rule.go @@ -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 }