mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Revert "fix(alerting): pause dto can only pause one"
This reverts commit b2c5a6a037
.
This commit is contained in:
parent
b2c5a6a037
commit
6c2c3c7e24
@ -259,9 +259,10 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R
|
||||
|
||||
//POST /api/alerts/:alertId/pause
|
||||
func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
|
||||
alertId := c.ParamsInt64("alertId")
|
||||
cmd := models.PauseAlertCommand{
|
||||
OrgId: c.OrgId,
|
||||
AlertId: c.ParamsInt64("alertId"),
|
||||
AlertIds: []int64{alertId},
|
||||
Paused: dto.Paused,
|
||||
}
|
||||
|
||||
@ -277,7 +278,7 @@ func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
|
||||
}
|
||||
|
||||
result := map[string]interface{}{
|
||||
"alertId": c.ParamsInt64("alertId"),
|
||||
"alertId": alertId,
|
||||
"state": response,
|
||||
"message": "alert " + pausedState,
|
||||
}
|
||||
|
@ -139,7 +139,8 @@ type SaveAlertsCommand struct {
|
||||
|
||||
type PauseAlertCommand struct {
|
||||
OrgId int64
|
||||
AlertId int64
|
||||
AlertIds []int64
|
||||
ResultCount int64
|
||||
Paused bool
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package sqlstore
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
@ -251,18 +252,31 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
|
||||
|
||||
func PauseAlert(cmd *m.PauseAlertCommand) error {
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
if len(cmd.AlertIds) == 0 {
|
||||
return fmt.Errorf("command contains no alertids")
|
||||
}
|
||||
|
||||
var buffer bytes.Buffer
|
||||
params := make([]interface{}, 0)
|
||||
|
||||
sql := `UPDATE alert SET state = ? WHERE id = ?`
|
||||
buffer.WriteString(`UPDATE alert SET state = ?`)
|
||||
if cmd.Paused {
|
||||
params = append(params, string(m.AlertStatePaused))
|
||||
} else {
|
||||
params = append(params, string(m.AlertStatePending))
|
||||
}
|
||||
params = append(params, cmd.AlertId)
|
||||
|
||||
_, err := sess.Exec(sql, params...)
|
||||
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...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd.ResultCount, _ = res.RowsAffected()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user