|
|
@@ -6,7 +6,6 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
- "github.com/go-xorm/xorm"
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
)
|
|
|
@@ -48,7 +47,7 @@ func GetAllAlertQueryHandler(query *m.GetAllAlertsQuery) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func deleteAlertByIdInternal(alertId int64, reason string, sess *xorm.Session) error {
|
|
|
+func deleteAlertByIdInternal(alertId int64, reason string, sess *DBSession) error {
|
|
|
sqlog.Debug("Deleting alert", "id", alertId, "reason", reason)
|
|
|
|
|
|
if _, err := sess.Exec("DELETE FROM alert WHERE id = ?", alertId); err != nil {
|
|
|
@@ -63,7 +62,7 @@ func deleteAlertByIdInternal(alertId int64, reason string, sess *xorm.Session) e
|
|
|
}
|
|
|
|
|
|
func DeleteAlertById(cmd *m.DeleteAlertCommand) error {
|
|
|
- return inTransaction(func(sess *xorm.Session) error {
|
|
|
+ return inTransaction(func(sess *DBSession) error {
|
|
|
return deleteAlertByIdInternal(cmd.AlertId, "DeleteAlertCommand", sess)
|
|
|
})
|
|
|
}
|
|
|
@@ -123,7 +122,7 @@ func HandleAlertsQuery(query *m.GetAlertsQuery) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func DeleteAlertDefinition(dashboardId int64, sess *xorm.Session) error {
|
|
|
+func DeleteAlertDefinition(dashboardId int64, sess *DBSession) error {
|
|
|
alerts := make([]*m.Alert, 0)
|
|
|
sess.Where("dashboard_id = ?", dashboardId).Find(&alerts)
|
|
|
|
|
|
@@ -135,7 +134,7 @@ func DeleteAlertDefinition(dashboardId int64, sess *xorm.Session) error {
|
|
|
}
|
|
|
|
|
|
func SaveAlerts(cmd *m.SaveAlertsCommand) error {
|
|
|
- return inTransaction(func(sess *xorm.Session) error {
|
|
|
+ return inTransaction(func(sess *DBSession) error {
|
|
|
existingAlerts, err := GetAlertsByDashboardId2(cmd.DashboardId, sess)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
@@ -153,7 +152,7 @@ func SaveAlerts(cmd *m.SaveAlertsCommand) error {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-func upsertAlerts(existingAlerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm.Session) error {
|
|
|
+func upsertAlerts(existingAlerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *DBSession) error {
|
|
|
for _, alert := range cmd.Alerts {
|
|
|
update := false
|
|
|
var alertToUpdate *m.Alert
|
|
|
@@ -197,7 +196,7 @@ func upsertAlerts(existingAlerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xor
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func deleteMissingAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm.Session) error {
|
|
|
+func deleteMissingAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *DBSession) error {
|
|
|
for _, missingAlert := range alerts {
|
|
|
missing := true
|
|
|
|
|
|
@@ -216,7 +215,7 @@ func deleteMissingAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func GetAlertsByDashboardId2(dashboardId int64, sess *xorm.Session) ([]*m.Alert, error) {
|
|
|
+func GetAlertsByDashboardId2(dashboardId int64, sess *DBSession) ([]*m.Alert, error) {
|
|
|
alerts := make([]*m.Alert, 0)
|
|
|
err := sess.Where("dashboard_id = ?", dashboardId).Find(&alerts)
|
|
|
|
|
|
@@ -228,7 +227,7 @@ func GetAlertsByDashboardId2(dashboardId int64, sess *xorm.Session) ([]*m.Alert,
|
|
|
}
|
|
|
|
|
|
func SetAlertState(cmd *m.SetAlertStateCommand) error {
|
|
|
- return inTransaction(func(sess *xorm.Session) error {
|
|
|
+ return inTransaction(func(sess *DBSession) error {
|
|
|
alert := m.Alert{}
|
|
|
|
|
|
if has, err := sess.Id(cmd.AlertId).Get(&alert); err != nil {
|
|
|
@@ -262,7 +261,7 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
|
|
|
}
|
|
|
|
|
|
func PauseAlert(cmd *m.PauseAlertCommand) error {
|
|
|
- return inTransaction(func(sess *xorm.Session) error {
|
|
|
+ return inTransaction(func(sess *DBSession) error {
|
|
|
if len(cmd.AlertIds) == 0 {
|
|
|
return fmt.Errorf("command contains no alertids")
|
|
|
}
|
|
|
@@ -292,7 +291,7 @@ func PauseAlert(cmd *m.PauseAlertCommand) error {
|
|
|
}
|
|
|
|
|
|
func PauseAllAlerts(cmd *m.PauseAllAlertCommand) error {
|
|
|
- return inTransaction(func(sess *xorm.Session) error {
|
|
|
+ return inTransaction(func(sess *DBSession) error {
|
|
|
var newState string
|
|
|
if cmd.Paused {
|
|
|
newState = string(m.AlertStatePaused)
|