diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index 46a3e008f11..d84151e5f45 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -288,15 +288,17 @@ func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response { //POST /api/alerts/pause func PauseAlerts(c *middleware.Context, dto dtos.PauseAlertsCommand) Response { - alertIdsToUpdate, err := getAlertIdsToUpdate(dto) - if err != nil { - return ApiError(500, "Failed to pause alerts", err) + updateCmd := models.PauseAlertCommand{ + OrgId: c.OrgId, + Paused: dto.Paused, } - updateCmd := models.PauseAlertCommand{ - OrgId: c.OrgId, - AlertIds: alertIdsToUpdate, - Paused: dto.Paused, + if len(dto.DataSourceIds) > 0 { + alertIdsToUpdate, err := getAlertIdsToUpdate(dto) + if err != nil { + return ApiError(500, "Failed to pause alerts", err) + } + updateCmd.AlertIds = alertIdsToUpdate } if err := bus.Dispatch(&updateCmd); err != nil { @@ -326,20 +328,14 @@ func getAlertIdsToUpdate(pauseAlertCmd dtos.PauseAlertsCommand) ([]int64, error) } var alertIdsToUpdate []int64 - updateAllAlerts := len(pauseAlertCmd.DataSourceIds) == 0 for _, alert := range cmd.Result { - if updateAllAlerts { - alertIdsToUpdate = append(alertIdsToUpdate, alert.Id) - continue - } - alert, err := alerting.NewRuleFromDBAlert(alert) if err != nil { return nil, err } for _, condition := range alert.Conditions { - id, exist := condition.GetDatsourceId() + id, exist := condition.GetDatasourceId() if exist && existInSlice(pauseAlertCmd.DataSourceIds, *id) { alertIdsToUpdate = append(alertIdsToUpdate, alert.Id) } diff --git a/pkg/api/alerting_test.go b/pkg/api/alerting_test.go deleted file mode 100644 index 395f4bbb671..00000000000 --- a/pkg/api/alerting_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package api - -import ( - "testing" - - . "github.com/smartystreets/goconvey/convey" -) - -func TestAlertingApi(t *testing.T) { - Convey("", func() {}) -} diff --git a/pkg/services/alerting/conditions/query.go b/pkg/services/alerting/conditions/query.go index db3a615f924..ca6c5f8b5d5 100644 --- a/pkg/services/alerting/conditions/query.go +++ b/pkg/services/alerting/conditions/query.go @@ -34,7 +34,7 @@ type AlertQuery struct { To string } -func (c *QueryCondition) GetDatsourceId() (datasourceId *int64, exist bool) { +func (c *QueryCondition) GetDatasourceId() (datasourceId *int64, exist bool) { return &c.Query.DatasourceId, true } diff --git a/pkg/services/alerting/eval_handler_test.go b/pkg/services/alerting/eval_handler_test.go index 73d675e3fa7..fd0d73f58b9 100644 --- a/pkg/services/alerting/eval_handler_test.go +++ b/pkg/services/alerting/eval_handler_test.go @@ -18,6 +18,10 @@ func (c *conditionStub) Eval(context *EvalContext) (*ConditionResult, error) { return &ConditionResult{Firing: c.firing, EvalMatches: c.matches, Operator: c.operator, NoDataFound: c.noData}, nil } +func (c *conditionStub) GetDatasourceId() (datasourceId *int64, exist bool) { + return nil, false +} + func TestAlertingExecutor(t *testing.T) { Convey("Test alert execution", t, func() { handler := NewEvalHandler() diff --git a/pkg/services/alerting/interfaces.go b/pkg/services/alerting/interfaces.go index bcc44fcf52b..32c78b1dd62 100644 --- a/pkg/services/alerting/interfaces.go +++ b/pkg/services/alerting/interfaces.go @@ -30,5 +30,5 @@ type ConditionResult struct { type Condition interface { Eval(result *EvalContext) (*ConditionResult, error) - GetDatsourceId() (datasourceId *int64, exist bool) + GetDatasourceId() (datasourceId *int64, exist bool) } diff --git a/pkg/services/alerting/rule_test.go b/pkg/services/alerting/rule_test.go index f8761efcd90..426712fa9f2 100644 --- a/pkg/services/alerting/rule_test.go +++ b/pkg/services/alerting/rule_test.go @@ -14,6 +14,10 @@ func (f *FakeCondition) Eval(context *EvalContext) (*ConditionResult, error) { return &ConditionResult{}, nil } +func (c *FakeCondition) GetDatasourceId() (datasourceId *int64, exist bool) { + return nil, false +} + func TestAlertRuleModel(t *testing.T) { Convey("Testing alert rule", t, func() {