feat(alerting): skeleton for alert notification configuration page
This commit is contained in:
@@ -156,3 +156,35 @@ func PutAlertState(c *middleware.Context, cmd models.UpdateAlertStateCommand) Re
|
||||
|
||||
return Json(200, cmd.Result)
|
||||
}
|
||||
|
||||
func GetAlertNotifications(c *middleware.Context) Response {
|
||||
query := &models.GetAlertNotificationQuery{
|
||||
OrgID: c.OrgId,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(query); err != nil {
|
||||
return ApiError(500, "Failed to get alert notifications", err)
|
||||
}
|
||||
|
||||
return Json(200, query.Result)
|
||||
}
|
||||
|
||||
func CreateAlertNotification(c *middleware.Context, cmd *models.CreateAlertNotificationCommand) Response {
|
||||
cmd.OrgID = c.OrgId
|
||||
|
||||
if err := bus.Dispatch(cmd); err != nil {
|
||||
return ApiError(500, "Failed to create alert notification", err)
|
||||
}
|
||||
|
||||
return Json(200, cmd.Result)
|
||||
}
|
||||
|
||||
func UpdateAlertNotification(c *middleware.Context, cmd *models.UpdateAlertNotificationCommand) Response {
|
||||
cmd.OrgID = c.OrgId
|
||||
|
||||
if err := bus.Dispatch(cmd); err != nil {
|
||||
return ApiError(500, "Failed to update alert notification", err)
|
||||
}
|
||||
|
||||
return Json(200, cmd.Result)
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ func Register(r *macaron.Macaron) {
|
||||
r.Get("/playlists/", reqSignedIn, Index)
|
||||
r.Get("/playlists/*", reqSignedIn, Index)
|
||||
r.Get("/alerting/", reqSignedIn, Index)
|
||||
r.Get("/alerting/*", reqSignedIn, Index)
|
||||
|
||||
// sign up
|
||||
r.Get("/signup", Index)
|
||||
@@ -250,6 +251,12 @@ func Register(r *macaron.Macaron) {
|
||||
r.Get("/", wrap(GetAlerts))
|
||||
})
|
||||
|
||||
r.Get("/notifications", wrap(GetAlertNotifications))
|
||||
r.Group("/notification", func() {
|
||||
r.Post("/", bind(m.CreateAlertNotificationCommand{}), wrap(CreateAlertNotification))
|
||||
r.Put("/", bind(m.UpdateAlertNotificationCommand{}), wrap(UpdateAlertNotification))
|
||||
})
|
||||
|
||||
r.Get("/changes", wrap(GetAlertChanges))
|
||||
})
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ func (n *NotifierImpl) Notify(alertResult *AlertResult) {
|
||||
n.log.Warn("looopie", "warn", warn, "crit", crit)
|
||||
if warn || crit {
|
||||
n.log.Info("Sending notification", "state", alertResult.State, "type", notifier.Type)
|
||||
go notifier.Notifierr.Notify(alertResult)
|
||||
go notifier.Notifierr.Dispatch(alertResult)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ type Notification struct {
|
||||
SendWarning bool
|
||||
SendCritical bool
|
||||
|
||||
Notifierr Notifierr
|
||||
Notifierr NotificationDispatcher
|
||||
}
|
||||
|
||||
type EmailNotifier struct {
|
||||
@@ -50,7 +50,7 @@ type EmailNotifier struct {
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func (this *EmailNotifier) Notify(alertResult *AlertResult) {
|
||||
func (this *EmailNotifier) Dispatch(alertResult *AlertResult) {
|
||||
//bus.dispath to notification package in grafana
|
||||
this.log.Info("Sending email")
|
||||
}
|
||||
@@ -62,13 +62,13 @@ type WebhookNotifier struct {
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
func (this *WebhookNotifier) Notify(alertResult *AlertResult) {
|
||||
func (this *WebhookNotifier) Dispatch(alertResult *AlertResult) {
|
||||
//bus.dispath to notification package in grafana
|
||||
this.log.Info("Sending webhook")
|
||||
}
|
||||
|
||||
type Notifierr interface {
|
||||
Notify(alertResult *AlertResult)
|
||||
type NotificationDispatcher interface {
|
||||
Dispatch(alertResult *AlertResult)
|
||||
}
|
||||
|
||||
func (n *NotifierImpl) getNotifiers(orgId int64, notificationGroups []int64) []*Notification {
|
||||
@@ -104,7 +104,7 @@ func NewNotificationFromDBModel(model *m.AlertNotification) (*Notification, erro
|
||||
}, nil
|
||||
}
|
||||
|
||||
var createNotifier = func(notificationType string, settings *simplejson.Json) Notifierr {
|
||||
var createNotifier = func(notificationType string, settings *simplejson.Json) NotificationDispatcher {
|
||||
if notificationType == "email" {
|
||||
return &EmailNotifier{
|
||||
To: settings.Get("to").MustString(),
|
||||
|
||||
Reference in New Issue
Block a user