diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go
index 1443f395ea2..29ca7a6758f 100644
--- a/pkg/api/alerting.go
+++ b/pkg/api/alerting.go
@@ -1,6 +1,7 @@
package api
import (
+ "github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/models"
@@ -21,7 +22,7 @@ func ValidateOrgAlert(c *middleware.Context) {
}
}
-// GET /api/alert_rule
+// GET /api/alert_rule/changes
func GetAlertChanges(c *middleware.Context) Response {
query := models.GetAlertChangesQuery{
OrgId: c.OrgId,
@@ -44,7 +45,44 @@ func GetAlerts(c *middleware.Context) Response {
return ApiError(500, "List alerts failed", err)
}
- return Json(200, query.Result)
+ dashboardIds := make([]int64, 0)
+ alertDTOs := make([]*dtos.AlertRuleDTO, 0)
+ for _, alert := range query.Result {
+ dashboardIds = append(dashboardIds, alert.DashboardId)
+ alertDTOs = append(alertDTOs, &dtos.AlertRuleDTO{
+ Id: alert.Id,
+ DashboardId: alert.DashboardId,
+ PanelId: alert.PanelId,
+ Query: alert.Query,
+ QueryRefId: alert.QueryRefId,
+ WarnLevel: alert.WarnLevel,
+ CritLevel: alert.CritLevel,
+ Interval: alert.Interval,
+ Title: alert.Title,
+ Description: alert.Description,
+ QueryRange: alert.QueryRange,
+ Aggregator: alert.Aggregator,
+ })
+ }
+
+ dashboardsQuery := models.GetDashboardsQuery{
+ DashboardIds: dashboardIds,
+ }
+
+ if err := bus.Dispatch(&dashboardsQuery); err != nil {
+ return ApiError(500, "List alerts failed", err)
+ }
+
+ //TODO: should be possible to speed this up with lookup table
+ for _, alert := range alertDTOs {
+ for _, dash := range *dashboardsQuery.Result {
+ if alert.DashboardId == dash.Id {
+ alert.DashbboardUri = "db/" + dash.Slug
+ }
+ }
+ }
+
+ return Json(200, alertDTOs)
}
// GET /api/alert_rule/:id
diff --git a/pkg/api/api.go b/pkg/api/api.go
index 4ad6c1665a1..081a85adba0 100644
--- a/pkg/api/api.go
+++ b/pkg/api/api.go
@@ -58,6 +58,8 @@ func Register(r *macaron.Macaron) {
r.Get("/playlists/", reqSignedIn, Index)
r.Get("/playlists/*", reqSignedIn, Index)
+ r.Get("/alerts/", reqSignedIn, Index)
+ r.Get("/alerts/*", reqSignedIn, Index)
// sign up
r.Get("/signup", Index)
diff --git a/pkg/api/dtos/alerting.go b/pkg/api/dtos/alerting.go
new file mode 100644
index 00000000000..695d11c0b66
--- /dev/null
+++ b/pkg/api/dtos/alerting.go
@@ -0,0 +1,18 @@
+package dtos
+
+type AlertRuleDTO struct {
+ Id int64 `json:"id"`
+ DashboardId int64 `json:"dashboardId"`
+ PanelId int64 `json:"panelId"`
+ Query string `json:"query"`
+ QueryRefId string `json:"queryRefId"`
+ WarnLevel string `json:"warnLevel"`
+ CritLevel string `json:"critLevel"`
+ Interval string `json:"interval"`
+ Title string `json:"title"`
+ Description string `json:"description"`
+ QueryRange string `json:"queryRange"`
+ Aggregator string `json:"aggregator"`
+
+ DashbboardUri string `json:"dashboardUri"`
+}
diff --git a/public/app/core/routes/routes.ts b/public/app/core/routes/routes.ts
index 1608a772e87..899310c9c2b 100644
--- a/public/app/core/routes/routes.ts
+++ b/public/app/core/routes/routes.ts
@@ -13,6 +13,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
var loadOrgBundle = new BundleLoader('app/features/org/all');
var loadPluginsBundle = new BundleLoader('app/features/plugins/all');
var loadAdminBundle = new BundleLoader('app/features/admin/admin');
+ var loadAlertsBundle = new BundleLoader('app/features/alerts/all');
$routeProvider
.when('/', {
@@ -197,6 +198,12 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
controllerAs: 'ctrl',
templateUrl: 'public/app/features/styleguide/styleguide.html',
})
+ .when('/alerts', {
+ templateUrl: 'public/app/features/alerts/partials/alerts_page.html',
+ controller: 'AlertPageCtrl',
+ controllerAs: 'ctrl',
+ resolve: loadAlertsBundle,
+ })
.otherwise({
templateUrl: 'public/app/partials/error.html',
controller: 'ErrorCtrl'
diff --git a/public/app/features/alerts/alerts_ctrl.ts b/public/app/features/alerts/alerts_ctrl.ts
new file mode 100644
index 00000000000..7a3fc032281
--- /dev/null
+++ b/public/app/features/alerts/alerts_ctrl.ts
@@ -0,0 +1,26 @@
+///
| Name | ++ | + + + |
|---|---|---|
| + {{alert.title}} + | ++ + Go to dashboard + + | ++ + + + | +