Просмотр исходного кода

Merge branch 'alerting' of github.com:grafana/grafana into alerting

Torkel Ödegaard 9 лет назад
Родитель
Сommit
da59d6547f

+ 6 - 4
pkg/models/alert.go

@@ -10,9 +10,11 @@ type AlertStateType string
 type AlertSeverityType string
 type AlertSeverityType string
 
 
 const (
 const (
-	AlertStatePending AlertStateType = "pending"
-	AlertStateFiring  AlertStateType = "firing"
-	AlertStateOK      AlertStateType = "ok"
+	AlertStatePending        AlertStateType = "pending"
+	AlertStateExeuctionError AlertStateType = "exeuction_error"
+	AlertStatePaused         AlertStateType = "paused"
+	AlertStateFiring         AlertStateType = "firing"
+	AlertStateOK             AlertStateType = "ok"
 )
 )
 
 
 func (s AlertStateType) IsValid() bool {
 func (s AlertStateType) IsValid() bool {
@@ -41,7 +43,6 @@ type Alert struct {
 	Severity       AlertSeverityType
 	Severity       AlertSeverityType
 	State          AlertStateType
 	State          AlertStateType
 	Handler        int64
 	Handler        int64
-	Paused         bool
 	Silenced       bool
 	Silenced       bool
 	ExecutionError string
 	ExecutionError string
 	Frequency      int64
 	Frequency      int64
@@ -115,6 +116,7 @@ type SetAlertStateCommand struct {
 	AlertId   int64
 	AlertId   int64
 	OrgId     int64
 	OrgId     int64
 	State     AlertStateType
 	State     AlertStateType
+	Error     string
 	Timestamp time.Time
 	Timestamp time.Time
 }
 }
 
 

+ 9 - 9
pkg/services/alerting/notifiers/slack.go

@@ -64,20 +64,20 @@ func (this *SlackNotifier) Notify(context *alerting.EvalContext) {
 	body := map[string]interface{}{
 	body := map[string]interface{}{
 		"attachments": []map[string]interface{}{
 		"attachments": []map[string]interface{}{
 			{
 			{
-				"color": context.GetColor(),
+				"color":       context.GetColor(),
+				"title":       context.GetNotificationTitle(),
+				"title_link":  ruleUrl,
+				"text":        context.Rule.Message,
+				"fields":      fields,
+				"image_url":   context.ImagePublicUrl,
+				"footer":      "Grafana v" + setting.BuildVersion,
+				"footer_icon": "http://grafana.org/assets/img/fav32.png",
+				"ts":          time.Now().Unix(),
 				//"pretext":     "Optional text that appears above the attachment block",
 				//"pretext":     "Optional text that appears above the attachment block",
 				// "author_name": "Bobby Tables",
 				// "author_name": "Bobby Tables",
 				// "author_link": "http://flickr.com/bobby/",
 				// "author_link": "http://flickr.com/bobby/",
 				// "author_icon": "http://flickr.com/icons/bobby.jpg",
 				// "author_icon": "http://flickr.com/icons/bobby.jpg",
-				"title":      context.GetNotificationTitle(),
-				"title_link": ruleUrl,
-				"text":       context.Rule.Message,
-				"fields":     fields,
-				"image_url":  context.ImagePublicUrl,
 				// "thumb_url":   "http://example.com/path/to/thumb.png",
 				// "thumb_url":   "http://example.com/path/to/thumb.png",
-				"footer":      "Grafana v" + setting.BuildVersion,
-				"footer_icon": "http://grafana.org/assets/img/fav32.png",
-				"ts":          time.Now().Unix(),
 			},
 			},
 		},
 		},
 	}
 	}

+ 4 - 1
pkg/services/alerting/result_handler.go

@@ -29,9 +29,11 @@ func NewResultHandler() *DefaultResultHandler {
 func (handler *DefaultResultHandler) Handle(ctx *EvalContext) {
 func (handler *DefaultResultHandler) Handle(ctx *EvalContext) {
 	oldState := ctx.Rule.State
 	oldState := ctx.Rule.State
 
 
+	exeuctionError := ""
 	if ctx.Error != nil {
 	if ctx.Error != nil {
 		handler.log.Error("Alert Rule Result Error", "ruleId", ctx.Rule.Id, "error", ctx.Error)
 		handler.log.Error("Alert Rule Result Error", "ruleId", ctx.Rule.Id, "error", ctx.Error)
-		ctx.Rule.State = m.AlertStatePending
+		ctx.Rule.State = m.AlertStateExeuctionError
+		exeuctionError = ctx.Error.Error()
 	} else if ctx.Firing {
 	} else if ctx.Firing {
 		ctx.Rule.State = m.AlertStateFiring
 		ctx.Rule.State = m.AlertStateFiring
 	} else {
 	} else {
@@ -47,6 +49,7 @@ func (handler *DefaultResultHandler) Handle(ctx *EvalContext) {
 			AlertId: ctx.Rule.Id,
 			AlertId: ctx.Rule.Id,
 			OrgId:   ctx.Rule.OrgId,
 			OrgId:   ctx.Rule.OrgId,
 			State:   ctx.Rule.State,
 			State:   ctx.Rule.State,
+			Error:   exeuctionError,
 		}
 		}
 
 
 		if err := bus.Dispatch(cmd); err != nil {
 		if err := bus.Dispatch(cmd); err != nil {

+ 1 - 0
pkg/services/sqlstore/alert.go

@@ -223,6 +223,7 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
 		alert.State = cmd.State
 		alert.State = cmd.State
 		alert.StateChanges += 1
 		alert.StateChanges += 1
 		alert.NewStateDate = time.Now()
 		alert.NewStateDate = time.Now()
+		alert.ExecutionError = cmd.Error
 
 
 		sess.Id(alert.Id).Update(&alert)
 		sess.Id(alert.Id).Update(&alert)
 		return nil
 		return nil

+ 0 - 1
pkg/services/sqlstore/migrations/alert_mig.go

@@ -21,7 +21,6 @@ func addAlertMigrations(mg *Migrator) {
 			{Name: "frequency", Type: DB_BigInt, Nullable: false},
 			{Name: "frequency", Type: DB_BigInt, Nullable: false},
 			{Name: "handler", Type: DB_BigInt, Nullable: false},
 			{Name: "handler", Type: DB_BigInt, Nullable: false},
 			{Name: "severity", Type: DB_Text, Nullable: false},
 			{Name: "severity", Type: DB_Text, Nullable: false},
-			{Name: "paused", Type: DB_Bool, Nullable: false},
 			{Name: "silenced", Type: DB_Bool, Nullable: false},
 			{Name: "silenced", Type: DB_Bool, Nullable: false},
 			{Name: "execution_error", Type: DB_Text, Nullable: false},
 			{Name: "execution_error", Type: DB_Text, Nullable: false},
 			{Name: "eval_data", Type: DB_Text, Nullable: true},
 			{Name: "eval_data", Type: DB_Text, Nullable: true},