diff --git a/pkg/services/sqlstore/alert_state.go b/pkg/services/sqlstore/alert_state.go deleted file mode 100644 index 38c14b077b5..00000000000 --- a/pkg/services/sqlstore/alert_state.go +++ /dev/null @@ -1,77 +0,0 @@ -package sqlstore - -// import ( -// "fmt" -// "time" -// -// "github.com/go-xorm/xorm" -// "github.com/grafana/grafana/pkg/bus" -// m "github.com/grafana/grafana/pkg/models" -// ) -// -// func init() { -// bus.AddHandler("sql", SetNewAlertState) -// bus.AddHandler("sql", GetAlertStateLogByAlertId) -// bus.AddHandler("sql", GetLastAlertStateQuery) -// } -// -// func GetLastAlertStateQuery(cmd *m.GetLastAlertStateQuery) error { -// states := make([]m.AlertState, 0) -// -// if err := x.Where("alert_id = ? and org_id = ? ", cmd.AlertId, cmd.OrgId).Desc("created").Find(&states); err != nil { -// return err -// } -// -// if len(states) == 0 { -// cmd.Result = nil -// return nil -// } -// -// cmd.Result = &states[0] -// return nil -// } -// -// func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error { -// return inTransaction(func(sess *xorm.Session) error { -// if !cmd.IsValidState() { -// return fmt.Errorf("new state is invalid") -// } -// -// alert := m.Alert{} -// has, err := sess.Id(cmd.AlertId).Get(&alert) -// if err != nil { -// return err -// } -// -// if !has { -// return fmt.Errorf("Could not find alert") -// } -// -// alert.State = cmd.State -// sess.Id(alert.Id).Update(&alert) -// -// alertState := m.AlertState{ -// AlertId: cmd.AlertId, -// OrgId: cmd.OrgId, -// State: cmd.State, -// Info: cmd.Info, -// Created: time.Now(), -// } -// -// sess.Insert(&alertState) -// -// cmd.Result = &alert -// return nil -// }) -// } -// -// func GetAlertStateLogByAlertId(cmd *m.GetAlertsStateQuery) error { -// states := make([]m.AlertState, 0) -// -// if err := x.Where("alert_id = ?", cmd.AlertId).Desc("created").Find(&states); err != nil { -// return err -// } -// -// cmd.Result = &states -// return nil -// } diff --git a/pkg/services/sqlstore/alert_state_test.go b/pkg/services/sqlstore/alert_state_test.go deleted file mode 100644 index 1db1fca2b78..00000000000 --- a/pkg/services/sqlstore/alert_state_test.go +++ /dev/null @@ -1,100 +0,0 @@ -package sqlstore - -// import ( -// "testing" -// -// m "github.com/grafana/grafana/pkg/models" -// . "github.com/smartystreets/goconvey/convey" -// ) -// -// func TestAlertingStateAccess(t *testing.T) { -// Convey("Test alerting state changes", t, func() { -// InitTestDB(t) -// -// testDash := insertTestDashboard("dashboard with alerts", 1, "alert") -// -// items := []*m.Alert{ -// { -// PanelId: 1, -// DashboardId: testDash.Id, -// OrgId: testDash.OrgId, -// Name: "Alerting title", -// Description: "Alerting description", -// }, -// } -// -// cmd := m.SaveAlertsCommand{ -// Alerts: items, -// DashboardId: testDash.Id, -// OrgId: 1, -// UserId: 1, -// } -// -// err := SaveAlerts(&cmd) -// So(err, ShouldBeNil) -// -// Convey("Cannot insert invalid states", func() { -// err = SetNewAlertState(&m.UpdateAlertStateCommand{ -// AlertId: 1, -// NewState: "maybe ok", -// Info: "Shit just hit the fan", -// }) -// -// So(err, ShouldNotBeNil) -// }) -// -// Convey("Changes state to alert", func() { -// -// err = SetNewAlertState(&m.UpdateAlertStateCommand{ -// AlertId: 1, -// NewState: "CRITICAL", -// Info: "Shit just hit the fan", -// }) -// -// Convey("can get new state for alert", func() { -// query := &m.GetAlertByIdQuery{Id: 1} -// err := GetAlertById(query) -// So(err, ShouldBeNil) -// So(query.Result.State, ShouldEqual, "CRITICAL") -// }) -// -// Convey("Changes state to ok", func() { -// err = SetNewAlertState(&m.UpdateAlertStateCommand{ -// AlertId: 1, -// NewState: "OK", -// Info: "Shit just hit the fan", -// }) -// -// Convey("get ok state for alert", func() { -// query := &m.GetAlertByIdQuery{Id: 1} -// err := GetAlertById(query) -// So(err, ShouldBeNil) -// So(query.Result.State, ShouldEqual, "OK") -// }) -// -// Convey("should have two event state logs", func() { -// query := &m.GetAlertsStateQuery{ -// AlertId: 1, -// OrgId: 1, -// } -// -// err := GetAlertStateLogByAlertId(query) -// So(err, ShouldBeNil) -// -// So(len(*query.Result), ShouldEqual, 2) -// }) -// -// Convey("should not get any alerts with critical state", func() { -// query := &m.GetAlertsQuery{ -// OrgId: 1, -// State: []string{"Critical", "Warn"}, -// } -// -// err := HandleAlertsQuery(query) -// So(err, ShouldBeNil) -// So(len(query.Result), ShouldEqual, 0) -// }) -// }) -// }) -// }) -// }