mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
style(alerting): simplify support for pausing multiple alerts
This commit is contained in:
@@ -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 = ?`)
|
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) + `)`)
|
|
||||||
}
|
|
||||||
|
|
||||||
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...)
|
||||||
|
|||||||
Reference in New Issue
Block a user