mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
@@ -34,6 +34,10 @@ type AlertQuery struct {
|
||||
To string
|
||||
}
|
||||
|
||||
func (c *QueryCondition) GetDatsourceId() (datasourceId *int64, exist bool) {
|
||||
return &c.Query.DatasourceId, true
|
||||
}
|
||||
|
||||
func (c *QueryCondition) Eval(context *alerting.EvalContext) (*alerting.ConditionResult, error) {
|
||||
timeRange := tsdb.NewTimeRange(c.Query.From, c.Query.To)
|
||||
|
||||
|
||||
@@ -30,4 +30,5 @@ type ConditionResult struct {
|
||||
|
||||
type Condition interface {
|
||||
Eval(result *EvalContext) (*ConditionResult, error)
|
||||
GetDatsourceId() (datasourceId *int64, exist bool)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
@@ -246,25 +248,32 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
|
||||
|
||||
func PauseAlertRule(cmd *m.PauseAlertCommand) error {
|
||||
return inTransaction(func(sess *xorm.Session) error {
|
||||
alert := m.Alert{}
|
||||
var buffer bytes.Buffer
|
||||
params := make([]interface{}, 0)
|
||||
buffer.WriteString(`UPDATE alert SET state = ?`)
|
||||
|
||||
has, err := x.Where("id = ? AND org_id=?", cmd.AlertId, cmd.OrgId).Get(&alert)
|
||||
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 {
|
||||
params = append(params, string(m.AlertStatePaused))
|
||||
} else {
|
||||
params = append(params, string(m.AlertStatePending))
|
||||
}
|
||||
|
||||
for _, v := range cmd.AlertIds {
|
||||
params = append(params, v)
|
||||
}
|
||||
|
||||
res, err := sess.Exec(buffer.String(), params...)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
return fmt.Errorf("Could not find alert")
|
||||
}
|
||||
|
||||
var newState m.AlertStateType
|
||||
if cmd.Paused {
|
||||
newState = m.AlertStatePaused
|
||||
} else {
|
||||
newState = m.AlertStatePending
|
||||
}
|
||||
alert.State = newState
|
||||
|
||||
sess.Id(alert.Id).Update(&alert)
|
||||
cmd.ResultCount, _ = res.RowsAffected()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
// m "github.com/grafana/grafana/pkg/models"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestAlertingHeartbeatDataAccess(t *testing.T) {
|
||||
|
||||
Convey("Testing Alerting data access", t, func() {
|
||||
InitTestDB(t)
|
||||
//send heartbeat from server 1
|
||||
//send heartbeat from server 2
|
||||
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user