Alerting: Notification channel http api enhancements (#16219)
Now returns uid in response to get notification channel by id. Adds GET/PUT/DELETE support for notification channel by uid, /api/alert-notifications/uid/:uid. Break apart alerting and alert notification http api docs in two pages and update documentation to make it up to date with current implementation. Fixes #16012
This commit is contained in:
@@ -208,6 +208,31 @@ func GetAlertNotificationByID(c *m.ReqContext) Response {
|
||||
Id: c.ParamsInt64("notificationId"),
|
||||
}
|
||||
|
||||
if query.Id == 0 {
|
||||
return Error(404, "Alert notification not found", nil)
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(query); err != nil {
|
||||
return Error(500, "Failed to get alert notifications", err)
|
||||
}
|
||||
|
||||
if query.Result == nil {
|
||||
return Error(404, "Alert notification not found", nil)
|
||||
}
|
||||
|
||||
return JSON(200, dtos.NewAlertNotification(query.Result))
|
||||
}
|
||||
|
||||
func GetAlertNotificationByUID(c *m.ReqContext) Response {
|
||||
query := &m.GetAlertNotificationsWithUidQuery{
|
||||
OrgId: c.OrgId,
|
||||
Uid: c.Params("uid"),
|
||||
}
|
||||
|
||||
if query.Uid == "" {
|
||||
return Error(404, "Alert notification not found", nil)
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(query); err != nil {
|
||||
return Error(500, "Failed to get alert notifications", err)
|
||||
}
|
||||
@@ -239,6 +264,17 @@ func UpdateAlertNotification(c *m.ReqContext, cmd m.UpdateAlertNotificationComma
|
||||
return JSON(200, dtos.NewAlertNotification(cmd.Result))
|
||||
}
|
||||
|
||||
func UpdateAlertNotificationByUID(c *m.ReqContext, cmd m.UpdateAlertNotificationWithUidCommand) Response {
|
||||
cmd.OrgId = c.OrgId
|
||||
cmd.Uid = c.Params("uid")
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
return Error(500, "Failed to update alert notification", err)
|
||||
}
|
||||
|
||||
return JSON(200, dtos.NewAlertNotification(cmd.Result))
|
||||
}
|
||||
|
||||
func DeleteAlertNotification(c *m.ReqContext) Response {
|
||||
cmd := m.DeleteAlertNotificationCommand{
|
||||
OrgId: c.OrgId,
|
||||
@@ -252,6 +288,19 @@ func DeleteAlertNotification(c *m.ReqContext) Response {
|
||||
return Success("Notification deleted")
|
||||
}
|
||||
|
||||
func DeleteAlertNotificationByUID(c *m.ReqContext) Response {
|
||||
cmd := m.DeleteAlertNotificationWithUidCommand{
|
||||
OrgId: c.OrgId,
|
||||
Uid: c.Params("uid"),
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
return Error(500, "Failed to delete alert notification", err)
|
||||
}
|
||||
|
||||
return Success("Notification deleted")
|
||||
}
|
||||
|
||||
//POST /api/alert-notifications/test
|
||||
func NotificationTest(c *m.ReqContext, dto dtos.NotificationTestCommand) Response {
|
||||
cmd := &alerting.NotificationTestCommand{
|
||||
|
||||
@@ -350,6 +350,9 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
alertNotifications.Put("/:notificationId", bind(m.UpdateAlertNotificationCommand{}), Wrap(UpdateAlertNotification))
|
||||
alertNotifications.Get("/:notificationId", Wrap(GetAlertNotificationByID))
|
||||
alertNotifications.Delete("/:notificationId", Wrap(DeleteAlertNotification))
|
||||
alertNotifications.Get("/uid/:uid", Wrap(GetAlertNotificationByUID))
|
||||
alertNotifications.Put("/uid/:uid", bind(m.UpdateAlertNotificationWithUidCommand{}), Wrap(UpdateAlertNotificationByUID))
|
||||
alertNotifications.Delete("/uid/:uid", Wrap(DeleteAlertNotificationByUID))
|
||||
}, reqEditorRole)
|
||||
|
||||
apiRoute.Get("/annotations", Wrap(GetAnnotations))
|
||||
|
||||
@@ -67,14 +67,14 @@ type UpdateAlertNotificationCommand struct {
|
||||
}
|
||||
|
||||
type UpdateAlertNotificationWithUidCommand struct {
|
||||
Uid string
|
||||
Name string
|
||||
Type string
|
||||
SendReminder bool
|
||||
DisableResolveMessage bool
|
||||
Frequency string
|
||||
IsDefault bool
|
||||
Settings *simplejson.Json
|
||||
Uid string `json:"-"`
|
||||
Name string `json:"name" binding:"Required"`
|
||||
Type string `json:"type" binding:"Required"`
|
||||
SendReminder bool `json:"sendReminder"`
|
||||
DisableResolveMessage bool `json:"disableResolveMessage"`
|
||||
Frequency string `json:"frequency"`
|
||||
IsDefault bool `json:"isDefault"`
|
||||
Settings *simplejson.Json `json:"settings" binding:"Required"`
|
||||
|
||||
OrgId int64
|
||||
Result *AlertNotification
|
||||
|
||||
@@ -130,6 +130,7 @@ func getAlertNotificationInternal(query *m.GetAlertNotificationsQuery, sess *DBS
|
||||
|
||||
sql.WriteString(`SELECT
|
||||
alert_notification.id,
|
||||
alert_notification.uid,
|
||||
alert_notification.org_id,
|
||||
alert_notification.name,
|
||||
alert_notification.type,
|
||||
|
||||
Reference in New Issue
Block a user