mirror of https://github.com/grafana/grafana
parent
779ea55ee0
commit
8b91e57ef6
@ -0,0 +1,44 @@ |
|||||||
|
package models |
||||||
|
|
||||||
|
import ( |
||||||
|
"time" |
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/components/simplejson" |
||||||
|
) |
||||||
|
|
||||||
|
type AlertNotification struct { |
||||||
|
Id int64 |
||||||
|
OrgId int64 |
||||||
|
Name string |
||||||
|
Type string |
||||||
|
Settings *simplejson.Json |
||||||
|
|
||||||
|
Created time.Time |
||||||
|
Updated time.Time |
||||||
|
} |
||||||
|
|
||||||
|
type CreateAlertNotificationCommand struct { |
||||||
|
Name string |
||||||
|
Type string |
||||||
|
OrgID int64 |
||||||
|
Settings *simplejson.Json |
||||||
|
|
||||||
|
Result *AlertNotification |
||||||
|
} |
||||||
|
|
||||||
|
type UpdateAlertNotificationCommand struct { |
||||||
|
Name string |
||||||
|
Type string |
||||||
|
OrgID int64 |
||||||
|
Settings *simplejson.Json |
||||||
|
|
||||||
|
Result *AlertNotification |
||||||
|
} |
||||||
|
|
||||||
|
type GetAlertNotificationQuery struct { |
||||||
|
Name string |
||||||
|
ID int64 |
||||||
|
OrgID int64 |
||||||
|
|
||||||
|
Result []*AlertNotification |
||||||
|
} |
@ -0,0 +1,56 @@ |
|||||||
|
package sqlstore |
||||||
|
|
||||||
|
import ( |
||||||
|
"bytes" |
||||||
|
|
||||||
|
"github.com/grafana/grafana/pkg/bus" |
||||||
|
m "github.com/grafana/grafana/pkg/models" |
||||||
|
) |
||||||
|
|
||||||
|
func init() { |
||||||
|
bus.AddHandler("sql", GetAlertNotifications) |
||||||
|
} |
||||||
|
|
||||||
|
func GetAlertNotifications(query *m.GetAlertNotificationQuery) error { |
||||||
|
var sql bytes.Buffer |
||||||
|
params := make([]interface{}, 0) |
||||||
|
|
||||||
|
sql.WriteString(`SELECT |
||||||
|
alert_notification.id, |
||||||
|
alert_notification.org_id, |
||||||
|
alert_notification.name, |
||||||
|
alert_notification.type, |
||||||
|
alert_notification.created, |
||||||
|
alert_notification.updated, |
||||||
|
alert_notification.settings |
||||||
|
FROM alert_notification |
||||||
|
`) |
||||||
|
|
||||||
|
sql.WriteString(` WHERE alert_notification.org_id = ?`) |
||||||
|
params = append(params, query.OrgID) |
||||||
|
|
||||||
|
if query.Name != "" { |
||||||
|
sql.WriteString(` AND alert_notification.name = ?`) |
||||||
|
params = append(params, query.Name) |
||||||
|
} |
||||||
|
|
||||||
|
var result []*m.AlertNotification |
||||||
|
if err := x.Sql(sql.String(), params...).Find(&result); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
query.Result = result |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
/* |
||||||
|
func CreateAlertNotification(cmd *m.CreateAlertNotificationCommand) error { |
||||||
|
return inTransaction(func(sess *xorm.Session) error { |
||||||
|
|
||||||
|
|
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
func UpdateAlertNotification(cmd *m.UpdateAlertNotificationCommand) error { |
||||||
|
|
||||||
|
}*/ |
@ -0,0 +1,36 @@ |
|||||||
|
package sqlstore |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"testing" |
||||||
|
|
||||||
|
m "github.com/grafana/grafana/pkg/models" |
||||||
|
. "github.com/smartystreets/goconvey/convey" |
||||||
|
) |
||||||
|
|
||||||
|
func TestAlertNotificationSQLAccess(t *testing.T) { |
||||||
|
Convey("Testing Alert notification sql access", t, func() { |
||||||
|
InitTestDB(t) |
||||||
|
|
||||||
|
Convey("Alert notifications should be empty", func() { |
||||||
|
cmd := &m.GetAlertNotificationQuery{ |
||||||
|
OrgID: FakeOrgId, |
||||||
|
Name: "email", |
||||||
|
} |
||||||
|
|
||||||
|
err := GetAlertNotifications(cmd) |
||||||
|
fmt.Printf("errror %v", err) |
||||||
|
So(err, ShouldBeNil) |
||||||
|
So(len(cmd.Result), ShouldEqual, 0) |
||||||
|
}) |
||||||
|
/* |
||||||
|
Convey("Can save Alert Notification", func() { |
||||||
|
cmd := &m.CreateAlertNotificationCommand{} |
||||||
|
|
||||||
|
var err error |
||||||
|
err = CreateAlertNotification(cmd) |
||||||
|
|
||||||
|
So(err, ShouldBeNil) |
||||||
|
}) */ |
||||||
|
}) |
||||||
|
} |
Loading…
Reference in new issue