Commit 6b9db0c0 by bergquist

style(alerting): simplify support for pausing multiple alerts

parent 4ef95cfd
...@@ -250,23 +250,19 @@ func PauseAlertRule(cmd *m.PauseAlertCommand) error { ...@@ -250,23 +250,19 @@ func PauseAlertRule(cmd *m.PauseAlertCommand) error {
return inTransaction(func(sess *xorm.Session) error { return inTransaction(func(sess *xorm.Session) error {
var buffer bytes.Buffer var buffer bytes.Buffer
params := make([]interface{}, 0) params := make([]interface{}, 0)
buffer.WriteString(`UPDATE alert SET state = ?`)
alertIdCount := len(cmd.AlertIds)
if alertIdCount == 1 {
buffer.WriteString(` WHERE id = ?`)
} else if alertIdCount > 1 {
buffer.WriteString(` WHERE id IN (?` + strings.Repeat(",?", len(cmd.AlertIds)-1) + `)`)
}
buffer.WriteString(`UPDATE alert SET state = ?`)
if cmd.Paused { if cmd.Paused {
params = append(params, string(m.AlertStatePaused)) params = append(params, string(m.AlertStatePaused))
} else { } else {
params = append(params, string(m.AlertStatePending)) params = append(params, string(m.AlertStatePending))
} }
for _, v := range cmd.AlertIds { if len(cmd.AlertIds) > 0 {
params = append(params, v) buffer.WriteString(` WHERE id IN (?` + strings.Repeat(",?", len(cmd.AlertIds)-1) + `)`)
for _, v := range cmd.AlertIds {
params = append(params, v)
}
} }
res, err := sess.Exec(buffer.String(), params...) res, err := sess.Exec(buffer.String(), params...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment