diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go
index 8546a4e439f..c829c1ff71c 100644
--- a/pkg/api/alerting.go
+++ b/pkg/api/alerting.go
@@ -43,13 +43,16 @@ func GetAlerts(c *middleware.Context) Response {
for _, alert := range query.Result {
dashboardIds = append(dashboardIds, alert.DashboardId)
alertDTOs = append(alertDTOs, &dtos.AlertRule{
- Id: alert.Id,
- DashboardId: alert.DashboardId,
- PanelId: alert.PanelId,
- Name: alert.Name,
- Message: alert.Message,
- State: alert.State,
- Severity: alert.Severity,
+ Id: alert.Id,
+ DashboardId: alert.DashboardId,
+ PanelId: alert.PanelId,
+ Name: alert.Name,
+ Message: alert.Message,
+ State: alert.State,
+ Severity: alert.Severity,
+ EvalDate: alert.EvalDate,
+ NewStateDate: alert.NewStateDate,
+ ExecutionError: alert.ExecutionError,
})
}
diff --git a/pkg/api/dtos/alerting.go b/pkg/api/dtos/alerting.go
index ce8995eb2f6..bab4eb196ba 100644
--- a/pkg/api/dtos/alerting.go
+++ b/pkg/api/dtos/alerting.go
@@ -8,15 +8,17 @@ import (
)
type AlertRule struct {
- Id int64 `json:"id"`
- DashboardId int64 `json:"dashboardId"`
- PanelId int64 `json:"panelId"`
- Name string `json:"name"`
- Message string `json:"message"`
- State m.AlertStateType `json:"state"`
- Severity m.AlertSeverityType `json:"severity"`
-
- DashbboardUri string `json:"dashboardUri"`
+ Id int64 `json:"id"`
+ DashboardId int64 `json:"dashboardId"`
+ PanelId int64 `json:"panelId"`
+ Name string `json:"name"`
+ Message string `json:"message"`
+ State m.AlertStateType `json:"state"`
+ Severity m.AlertSeverityType `json:"severity"`
+ NewStateDate time.Time `json:"newStateDate"`
+ EvalDate time.Time `json:"evalDate"`
+ ExecutionError string `json:"executionError"`
+ DashbboardUri string `json:"dashboardUri"`
}
type AlertNotification struct {
diff --git a/pkg/api/index.go b/pkg/api/index.go
index 056bf1f11e1..46dfc813259 100644
--- a/pkg/api/index.go
+++ b/pkg/api/index.go
@@ -93,14 +93,14 @@ func setIndexViewData(c *middleware.Context) (*dtos.IndexViewData, error) {
if setting.AlertingEnabled && (c.OrgRole == m.ROLE_ADMIN || c.OrgRole == m.ROLE_EDITOR) {
alertChildNavs := []*dtos.NavLink{
- {Text: "Home", Url: setting.AppSubUrl + "/alerting"},
+ {Text: "Alert List", Url: setting.AppSubUrl + "/alerting/list"},
{Text: "Notifications", Url: setting.AppSubUrl + "/alerting/notifications"},
}
data.MainNavLinks = append(data.MainNavLinks, &dtos.NavLink{
Text: "Alerting",
Icon: "icon-gf icon-gf-monitoring",
- Url: setting.AppSubUrl + "/alerting",
+ Url: setting.AppSubUrl + "/alerting/list",
Children: alertChildNavs,
})
}
diff --git a/pkg/models/alert.go b/pkg/models/alert.go
index 8d7d338ca06..240f8509179 100644
--- a/pkg/models/alert.go
+++ b/pkg/models/alert.go
@@ -32,6 +32,7 @@ func (s AlertSeverityType) IsValid() bool {
type Alert struct {
Id int64
+ Version int64
OrgId int64
DashboardId int64
PanelId int64
@@ -45,11 +46,10 @@ type Alert struct {
ExecutionError string
Frequency int64
- LastEvalData *simplejson.Json
- LastEvalTime time.Time
-
- CreatedBy int64
- UpdatedBy int64
+ EvalData *simplejson.Json
+ EvalDate time.Time
+ NewStateDate time.Time
+ StateChanges int
Created time.Time
Updated time.Time
diff --git a/pkg/services/sqlstore/alert.go b/pkg/services/sqlstore/alert.go
index 1a19b17aafa..d47e742c82d 100644
--- a/pkg/services/sqlstore/alert.go
+++ b/pkg/services/sqlstore/alert.go
@@ -161,8 +161,6 @@ func upsertAlerts(existingAlerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xor
alert.Updated = time.Now()
alert.Created = time.Now()
alert.State = m.AlertStatePending
- alert.CreatedBy = cmd.UserId
- alert.UpdatedBy = cmd.UserId
_, err := sess.Insert(alert)
if err != nil {
@@ -222,8 +220,10 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
}
alert.State = cmd.State
- sess.Id(alert.Id).Update(&alert)
+ alert.StateChanges += 1
+ alert.NewStateDate = time.Now()
+ sess.Id(alert.Id).Update(&alert)
return nil
})
}
diff --git a/pkg/services/sqlstore/migrations/alert_mig.go b/pkg/services/sqlstore/migrations/alert_mig.go
index 342c2282933..62817e3f543 100644
--- a/pkg/services/sqlstore/migrations/alert_mig.go
+++ b/pkg/services/sqlstore/migrations/alert_mig.go
@@ -10,6 +10,7 @@ func addAlertMigrations(mg *Migrator) {
Name: "alert",
Columns: []*Column{
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
+ {Name: "version", Type: DB_BigInt, Nullable: false},
{Name: "dashboard_id", Type: DB_BigInt, Nullable: false},
{Name: "panel_id", Type: DB_BigInt, Nullable: false},
{Name: "org_id", Type: DB_BigInt, Nullable: false},
@@ -23,12 +24,12 @@ func addAlertMigrations(mg *Migrator) {
{Name: "paused", Type: DB_Bool, Nullable: false},
{Name: "silenced", Type: DB_Bool, Nullable: false},
{Name: "execution_error", Type: DB_Text, Nullable: false},
- {Name: "last_eval_data", Type: DB_Text, Nullable: false},
- {Name: "last_eval_time", Type: DB_DateTime, Nullable: false},
+ {Name: "eval_data", Type: DB_Text, Nullable: true},
+ {Name: "eval_date", Type: DB_DateTime, Nullable: true},
+ {Name: "new_state_date", Type: DB_DateTime, Nullable: false},
+ {Name: "state_changes", Type: DB_Int, Nullable: false},
{Name: "created", Type: DB_DateTime, Nullable: false},
{Name: "updated", Type: DB_DateTime, Nullable: false},
- {Name: "updated_by", Type: DB_BigInt, Nullable: false},
- {Name: "created_by", Type: DB_BigInt, Nullable: false},
},
Indices: []*Index{
{Cols: []string{"org_id", "id"}, Type: IndexType},
diff --git a/pkg/services/sqlstore/migrations/annotation_mig.go b/pkg/services/sqlstore/migrations/annotation_mig.go
index af8d1cf0a03..11b4eeed629 100644
--- a/pkg/services/sqlstore/migrations/annotation_mig.go
+++ b/pkg/services/sqlstore/migrations/annotation_mig.go
@@ -32,6 +32,7 @@ func addAnnotationMig(mg *Migrator) {
// create indices
mg.AddMigration("add index annotation org_id & alert_id ", NewAddIndexMigration(table, table.Indices[0]))
+
mg.AddMigration("add index annotation org_id & type", NewAddIndexMigration(table, table.Indices[1]))
mg.AddMigration("add index annotation timestamp", NewAddIndexMigration(table, table.Indices[2]))
}
diff --git a/public/app/core/routes/routes.ts b/public/app/core/routes/routes.ts
index 547a22dfd7a..afe8dca2534 100644
--- a/public/app/core/routes/routes.ts
+++ b/public/app/core/routes/routes.ts
@@ -194,7 +194,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
controllerAs: 'ctrl',
templateUrl: 'public/app/features/styleguide/styleguide.html',
})
- .when('/alerting', {
+ .when('/alerting/list', {
templateUrl: 'public/app/features/alerting/partials/alert_list.html',
controller: 'AlertListCtrl',
controllerAs: 'ctrl',
diff --git a/public/app/features/alerting/alert_def.ts b/public/app/features/alerting/alert_def.ts
index 69f639d04c4..bcac982f5ea 100644
--- a/public/app/features/alerting/alert_def.ts
+++ b/public/app/features/alerting/alert_def.ts
@@ -1,14 +1,5 @@
///
| Name | -State | -Severity | -- - |
|---|---|---|---|
| - - {{alert.name}} - - | -- {{alert.state}} - | -- {{alert.severity}} - | -- - - edit - - | -