From b0c7e61ef869537093b03da9b57399dd3d10dc03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 13 Sep 2016 15:09:55 +0200 Subject: [PATCH] feat(alerting): removed severity --- pkg/api/alerting.go | 2 - pkg/api/dtos/alerting.go | 22 +++-- pkg/metrics/metrics.go | 80 +++++++++---------- pkg/models/alert.go | 26 ++---- pkg/services/alerting/eval_context.go | 17 ++-- pkg/services/alerting/extractor.go | 5 -- pkg/services/alerting/interfaces.go | 4 +- pkg/services/alerting/notifier.go | 4 +- pkg/services/alerting/notifier_test.go | 15 ++-- pkg/services/alerting/notifiers/base.go | 22 ++--- pkg/services/alerting/notifiers/base_test.go | 50 ++++++------ pkg/services/alerting/notifiers/email.go | 19 +++-- pkg/services/alerting/notifiers/webhook.go | 1 - pkg/services/alerting/result_handler.go | 18 ++--- pkg/services/alerting/rule.go | 4 +- pkg/services/alerting/test_notification.go | 30 +++---- pkg/services/sqlstore/alert.go | 2 +- pkg/services/sqlstore/alert_test.go | 4 +- public/app/features/alerting/alert_def.ts | 25 ++---- .../app/features/alerting/alert_list_ctrl.ts | 5 +- .../app/features/alerting/alert_tab_ctrl.ts | 10 +-- .../features/alerting/partials/alert_tab.html | 14 +--- .../app/features/alerting/threshold_mapper.ts | 2 +- 23 files changed, 143 insertions(+), 238 deletions(-) diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index bd40d8d63e9..d9a543b2425 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -49,7 +49,6 @@ func GetAlerts(c *middleware.Context) Response { Name: alert.Name, Message: alert.Message, State: alert.State, - Severity: alert.Severity, EvalDate: alert.EvalDate, NewStateDate: alert.NewStateDate, ExecutionError: alert.ExecutionError, @@ -219,7 +218,6 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R cmd := &alerting.NotificationTestCommand{ Name: dto.Name, Type: dto.Type, - Severity: dto.Severity, Settings: dto.Settings, } diff --git a/pkg/api/dtos/alerting.go b/pkg/api/dtos/alerting.go index 2b91cf0cb5b..e024768cd5e 100644 --- a/pkg/api/dtos/alerting.go +++ b/pkg/api/dtos/alerting.go @@ -8,17 +8,16 @@ 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"` - NewStateDate time.Time `json:"newStateDate"` - EvalDate time.Time `json:"evalDate"` - ExecutionError string `json:"executionError"` - 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"` + NewStateDate time.Time `json:"newStateDate"` + EvalDate time.Time `json:"evalDate"` + ExecutionError string `json:"executionError"` + DashbboardUri string `json:"dashboardUri"` } type AlertNotification struct { @@ -58,5 +57,4 @@ type NotificationTestCommand struct { Name string `json:"name"` Type string `json:"type"` Settings *simplejson.Json `json:"settings"` - Severity string `json:"severity"` } diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index 80d316c022f..bbe580de218 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -9,43 +9,42 @@ func init() { } var ( - M_Instance_Start Counter - M_Page_Status_200 Counter - M_Page_Status_500 Counter - M_Page_Status_404 Counter - M_Page_Status_Unknown Counter - M_Api_Status_200 Counter - M_Api_Status_404 Counter - M_Api_Status_500 Counter - M_Api_Status_Unknown Counter - M_Proxy_Status_200 Counter - M_Proxy_Status_404 Counter - M_Proxy_Status_500 Counter - M_Proxy_Status_Unknown Counter - M_Api_User_SignUpStarted Counter - M_Api_User_SignUpCompleted Counter - M_Api_User_SignUpInvite Counter - M_Api_Dashboard_Save Timer - M_Api_Dashboard_Get Timer - M_Api_Dashboard_Search Timer - M_Api_Admin_User_Create Counter - M_Api_Login_Post Counter - M_Api_Login_OAuth Counter - M_Api_Org_Create Counter - M_Api_Dashboard_Snapshot_Create Counter - M_Api_Dashboard_Snapshot_External Counter - M_Api_Dashboard_Snapshot_Get Counter - M_Models_Dashboard_Insert Counter - M_Alerting_Result_State_Critical Counter - M_Alerting_Result_State_Warning Counter - M_Alerting_Result_State_Ok Counter - M_Alerting_Result_State_Paused Counter - M_Alerting_Result_State_Unknown Counter - M_Alerting_Result_State_ExecutionError Counter - M_Alerting_Active_Alerts Counter - M_Alerting_Notification_Sent_Slack Counter - M_Alerting_Notification_Sent_Email Counter - M_Alerting_Notification_Sent_Webhook Counter + M_Instance_Start Counter + M_Page_Status_200 Counter + M_Page_Status_500 Counter + M_Page_Status_404 Counter + M_Page_Status_Unknown Counter + M_Api_Status_200 Counter + M_Api_Status_404 Counter + M_Api_Status_500 Counter + M_Api_Status_Unknown Counter + M_Proxy_Status_200 Counter + M_Proxy_Status_404 Counter + M_Proxy_Status_500 Counter + M_Proxy_Status_Unknown Counter + M_Api_User_SignUpStarted Counter + M_Api_User_SignUpCompleted Counter + M_Api_User_SignUpInvite Counter + M_Api_Dashboard_Save Timer + M_Api_Dashboard_Get Timer + M_Api_Dashboard_Search Timer + M_Api_Admin_User_Create Counter + M_Api_Login_Post Counter + M_Api_Login_OAuth Counter + M_Api_Org_Create Counter + M_Api_Dashboard_Snapshot_Create Counter + M_Api_Dashboard_Snapshot_External Counter + M_Api_Dashboard_Snapshot_Get Counter + M_Models_Dashboard_Insert Counter + M_Alerting_Result_State_Alerting Counter + M_Alerting_Result_State_Ok Counter + M_Alerting_Result_State_Paused Counter + M_Alerting_Result_State_NoData Counter + M_Alerting_Result_State_ExecError Counter + M_Alerting_Active_Alerts Counter + M_Alerting_Notification_Sent_Slack Counter + M_Alerting_Notification_Sent_Email Counter + M_Alerting_Notification_Sent_Webhook Counter // Timers M_DataSource_ProxyReq_Timer Timer @@ -92,12 +91,11 @@ func initMetricVars(settings *MetricSettings) { M_Models_Dashboard_Insert = RegCounter("models.dashboard.insert") - M_Alerting_Result_State_Critical = RegCounter("alerting.result", "state", "critical") - M_Alerting_Result_State_Warning = RegCounter("alerting.result", "state", "warning") + M_Alerting_Result_State_Alerting = RegCounter("alerting.result", "state", "alerting") M_Alerting_Result_State_Ok = RegCounter("alerting.result", "state", "ok") M_Alerting_Result_State_Paused = RegCounter("alerting.result", "state", "paused") - M_Alerting_Result_State_Unknown = RegCounter("alerting.result", "state", "unknown") - M_Alerting_Result_State_ExecutionError = RegCounter("alerting.result", "state", "execution_error") + M_Alerting_Result_State_NoData = RegCounter("alerting.result", "state", "no_data") + M_Alerting_Result_State_ExecError = RegCounter("alerting.result", "state", "exec_error") M_Alerting_Active_Alerts = RegCounter("alerting.active_alerts") M_Alerting_Notification_Sent_Slack = RegCounter("alerting.notifications_sent", "type", "slack") diff --git a/pkg/models/alert.go b/pkg/models/alert.go index d7dcd5b39a8..23c2c747a0f 100644 --- a/pkg/models/alert.go +++ b/pkg/models/alert.go @@ -10,27 +10,15 @@ type AlertStateType string type AlertSeverityType string const ( - AlertStateUnknown AlertStateType = "unknown" - AlertStateExeuctionError AlertStateType = "execution_error" - AlertStatePaused AlertStateType = "paused" - AlertStateCritical AlertStateType = "critical" - AlertStateWarning AlertStateType = "warning" - AlertStateOK AlertStateType = "ok" + AlertStateNoData AlertStateType = "no_data" + AlertStateExecError AlertStateType = "execution_error" + AlertStatePaused AlertStateType = "paused" + AlertStateAlerting AlertStateType = "alerting" + AlertStateOK AlertStateType = "ok" ) func (s AlertStateType) IsValid() bool { - return s == AlertStateOK || s == AlertStateUnknown || s == AlertStateExeuctionError || s == AlertStatePaused || s == AlertStateCritical || s == AlertStateWarning -} - -const ( - AlertSeverityCritical AlertSeverityType = "critical" - AlertSeverityWarning AlertSeverityType = "warning" - AlertSeverityInfo AlertSeverityType = "info" - AlertSeverityOK AlertSeverityType = "ok" -) - -func (s AlertSeverityType) IsValid() bool { - return s == AlertSeverityCritical || s == AlertSeverityInfo || s == AlertSeverityWarning + return s == AlertStateOK || s == AlertStateNoData || s == AlertStateExecError || s == AlertStatePaused } type Alert struct { @@ -41,7 +29,7 @@ type Alert struct { PanelId int64 Name string Message string - Severity AlertSeverityType + Severity string State AlertStateType Handler int64 Silenced bool diff --git a/pkg/services/alerting/eval_context.go b/pkg/services/alerting/eval_context.go index f54a4e212be..13067c25f08 100644 --- a/pkg/services/alerting/eval_context.go +++ b/pkg/services/alerting/eval_context.go @@ -43,25 +43,20 @@ func (c *EvalContext) GetStateModel() *StateDescription { Color: "#36a64f", Text: "OK", } - case m.AlertStateUnknown: + case m.AlertStateNoData: return &StateDescription{ Color: "#888888", - Text: "UNKNOWN", + Text: "No Data", } - case m.AlertStateExeuctionError: + case m.AlertStateExecError: return &StateDescription{ Color: "#000", - Text: "EXECUTION_ERROR", + Text: "Execution Error", } - case m.AlertStateWarning: - return &StateDescription{ - Color: "#fd821b", - Text: "WARNING", - } - case m.AlertStateCritical: + case m.AlertStateAlerting: return &StateDescription{ Color: "#D63232", - Text: "CRITICAL", + Text: "Alerting", } default: panic("Unknown rule state " + c.Rule.State) diff --git a/pkg/services/alerting/extractor.go b/pkg/services/alerting/extractor.go index 7d3b800fb31..cf516786412 100644 --- a/pkg/services/alerting/extractor.go +++ b/pkg/services/alerting/extractor.go @@ -88,14 +88,9 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) { Name: jsonAlert.Get("name").MustString(), Handler: jsonAlert.Get("handler").MustInt64(), Message: jsonAlert.Get("message").MustString(), - Severity: m.AlertSeverityType(jsonAlert.Get("severity").MustString()), Frequency: getTimeDurationStringToSeconds(jsonAlert.Get("frequency").MustString()), } - if !alert.Severity.IsValid() { - return nil, ValidationError{Reason: "Invalid alert Severity"} - } - for _, condition := range jsonAlert.Get("conditions").MustArray() { jsonCondition := simplejson.NewFromAny(condition) diff --git a/pkg/services/alerting/interfaces.go b/pkg/services/alerting/interfaces.go index e2549da2365..78ffc280375 100644 --- a/pkg/services/alerting/interfaces.go +++ b/pkg/services/alerting/interfaces.go @@ -2,8 +2,6 @@ package alerting import ( "time" - - "github.com/grafana/grafana/pkg/models" ) type EvalHandler interface { @@ -19,7 +17,7 @@ type Notifier interface { Notify(alertResult *EvalContext) GetType() string NeedsImage() bool - MatchSeverity(result models.AlertSeverityType) bool + PassesFilter(rule *Rule) bool } type Condition interface { diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go index 9a81501833d..bb48f71cdcd 100644 --- a/pkg/services/alerting/notifier.go +++ b/pkg/services/alerting/notifier.go @@ -28,7 +28,7 @@ func (n *RootNotifier) NeedsImage() bool { return false } -func (n *RootNotifier) MatchSeverity(result m.AlertSeverityType) bool { +func (n *RootNotifier) PassesFilter(rule *Rule) bool { return false } @@ -130,7 +130,7 @@ func shouldUseNotification(notifier Notifier, context *EvalContext) bool { return true } - return notifier.MatchSeverity(context.Rule.Severity) + return notifier.PassesFilter(context.Rule) } type NotifierFactory func(notification *m.AlertNotification) (Notifier, error) diff --git a/pkg/services/alerting/notifier_test.go b/pkg/services/alerting/notifier_test.go index 1354177f9b3..c854d8475b5 100644 --- a/pkg/services/alerting/notifier_test.go +++ b/pkg/services/alerting/notifier_test.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/grafana/grafana/pkg/models" + m "github.com/grafana/grafana/pkg/models" . "github.com/smartystreets/goconvey/convey" ) @@ -23,7 +24,7 @@ func (fn *FakeNotifier) NeedsImage() bool { func (fn *FakeNotifier) Notify(alertResult *EvalContext) {} -func (fn *FakeNotifier) MatchSeverity(result models.AlertSeverityType) bool { +func (fn *FakeNotifier) PassesFilter(rule *Rule) bool { return fn.FakeMatchResult } @@ -34,7 +35,7 @@ func TestAlertNotificationExtraction(t *testing.T) { ctx := &EvalContext{ Firing: false, Rule: &Rule{ - Severity: models.AlertSeverityCritical, + State: m.AlertStateAlerting, }, } notifier := &FakeNotifier{FakeMatchResult: false} @@ -42,12 +43,12 @@ func TestAlertNotificationExtraction(t *testing.T) { So(shouldUseNotification(notifier, ctx), ShouldBeTrue) }) - Convey("exeuction error cannot be ignored", func() { + Convey("execution error cannot be ignored", func() { ctx := &EvalContext{ Firing: true, Error: fmt.Errorf("I used to be a programmer just like you"), Rule: &Rule{ - Severity: models.AlertSeverityCritical, + State: m.AlertStateOK, }, } notifier := &FakeNotifier{FakeMatchResult: false} @@ -59,7 +60,7 @@ func TestAlertNotificationExtraction(t *testing.T) { ctx := &EvalContext{ Firing: true, Rule: &Rule{ - Severity: models.AlertSeverityCritical, + State: models.AlertStateAlerting, }, } notifier := &FakeNotifier{FakeMatchResult: true} @@ -70,9 +71,7 @@ func TestAlertNotificationExtraction(t *testing.T) { Convey("firing alert that dont match", func() { ctx := &EvalContext{ Firing: true, - Rule: &Rule{ - Severity: models.AlertSeverityCritical, - }, + Rule: &Rule{State: m.AlertStateOK}, } notifier := &FakeNotifier{FakeMatchResult: false} diff --git a/pkg/services/alerting/notifiers/base.go b/pkg/services/alerting/notifiers/base.go index acfafd59ac4..27c2a625d17 100644 --- a/pkg/services/alerting/notifiers/base.go +++ b/pkg/services/alerting/notifiers/base.go @@ -2,33 +2,21 @@ package notifiers import ( "github.com/grafana/grafana/pkg/components/simplejson" - "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/services/alerting" ) type NotifierBase struct { - Name string - Type string - SeverityFilter models.AlertSeverityType + Name string + Type string } func NewNotifierBase(name, notifierType string, model *simplejson.Json) NotifierBase { base := NotifierBase{Name: name, Type: notifierType} - - severityFilter := models.AlertSeverityType(model.Get("severityFilter").MustString("")) - - if severityFilter == models.AlertSeverityCritical || severityFilter == models.AlertSeverityWarning { - base.SeverityFilter = severityFilter - } - return base } -func (n *NotifierBase) MatchSeverity(result models.AlertSeverityType) bool { - if !n.SeverityFilter.IsValid() { - return true - } - - return n.SeverityFilter == result +func (n *NotifierBase) PassesFilter(rule *alerting.Rule) bool { + return true } func (n *NotifierBase) GetType() string { diff --git a/pkg/services/alerting/notifiers/base_test.go b/pkg/services/alerting/notifiers/base_test.go index af5dd902c87..775594fea44 100644 --- a/pkg/services/alerting/notifiers/base_test.go +++ b/pkg/services/alerting/notifiers/base_test.go @@ -3,34 +3,32 @@ package notifiers import ( "testing" - "github.com/grafana/grafana/pkg/components/simplejson" - m "github.com/grafana/grafana/pkg/models" . "github.com/smartystreets/goconvey/convey" ) func TestBaseNotifier(t *testing.T) { - Convey("Parsing base notification severity", t, func() { - - Convey("matches", func() { - json := ` - { - "severityFilter": "critical" - }` - - settingsJSON, _ := simplejson.NewJson([]byte(json)) - not := NewNotifierBase("ops", "email", settingsJSON) - So(not.MatchSeverity(m.AlertSeverityCritical), ShouldBeTrue) - }) - - Convey("does not match", func() { - json := ` - { - "severityFilter": "critical" - }` - - settingsJSON, _ := simplejson.NewJson([]byte(json)) - not := NewNotifierBase("ops", "email", settingsJSON) - So(not.MatchSeverity(m.AlertSeverityWarning), ShouldBeFalse) - }) - }) + // Convey("Parsing base notification state", t, func() { + // + // Convey("matches", func() { + // json := ` + // { + // "states": "critical" + // }` + // + // settingsJSON, _ := simplejson.NewJson([]byte(json)) + // not := NewNotifierBase("ops", "email", settingsJSON) + // So(not.MatchSeverity(m.AlertSeverityCritical), ShouldBeTrue) + // }) + // + // Convey("does not match", func() { + // json := ` + // { + // "severityFilter": "critical" + // }` + // + // settingsJSON, _ := simplejson.NewJson([]byte(json)) + // not := NewNotifierBase("ops", "email", settingsJSON) + // So(not.MatchSeverity(m.AlertSeverityWarning), ShouldBeFalse) + // }) + // }) } diff --git a/pkg/services/alerting/notifiers/email.go b/pkg/services/alerting/notifiers/email.go index c754dd7985e..eccd3ce9dfb 100644 --- a/pkg/services/alerting/notifiers/email.go +++ b/pkg/services/alerting/notifiers/email.go @@ -47,16 +47,15 @@ func (this *EmailNotifier) Notify(context *alerting.EvalContext) { cmd := &m.SendEmailCommand{ Data: map[string]interface{}{ - "Title": context.GetNotificationTitle(), - "State": context.Rule.State, - "Name": context.Rule.Name, - "Severity": context.Rule.Severity, - "SeverityColor": context.GetStateModel().Color, - "Message": context.Rule.Message, - "RuleUrl": ruleUrl, - "ImageLink": context.ImagePublicUrl, - "AlertPageUrl": setting.AppUrl + "alerting", - "EvalMatches": context.EvalMatches, + "Title": context.GetNotificationTitle(), + "State": context.Rule.State, + "Name": context.Rule.Name, + "StateModel": context.GetStateModel(), + "Message": context.Rule.Message, + "RuleUrl": ruleUrl, + "ImageLink": context.ImagePublicUrl, + "AlertPageUrl": setting.AppUrl + "alerting", + "EvalMatches": context.EvalMatches, }, To: this.Addresses, Template: "alert_notification.html", diff --git a/pkg/services/alerting/notifiers/webhook.go b/pkg/services/alerting/notifiers/webhook.go index 9a66d18c73c..7e28b35cd0a 100644 --- a/pkg/services/alerting/notifiers/webhook.go +++ b/pkg/services/alerting/notifiers/webhook.go @@ -45,7 +45,6 @@ func (this *WebhookNotifier) Notify(context *alerting.EvalContext) { bodyJSON.Set("ruleId", context.Rule.Id) bodyJSON.Set("ruleName", context.Rule.Name) bodyJSON.Set("state", context.Rule.State) - bodyJSON.Set("severity", context.Rule.Severity) bodyJSON.Set("evalMatches", context.EvalMatches) ruleUrl, err := context.GetRuleUrl() diff --git a/pkg/services/alerting/result_handler.go b/pkg/services/alerting/result_handler.go index 822d2bf8513..2f9572dcf80 100644 --- a/pkg/services/alerting/result_handler.go +++ b/pkg/services/alerting/result_handler.go @@ -34,11 +34,11 @@ func (handler *DefaultResultHandler) Handle(ctx *EvalContext) { annotationData := simplejson.New() if ctx.Error != nil { handler.log.Error("Alert Rule Result Error", "ruleId", ctx.Rule.Id, "error", ctx.Error) - ctx.Rule.State = m.AlertStateExeuctionError + ctx.Rule.State = m.AlertStateExecError exeuctionError = ctx.Error.Error() annotationData.Set("errorMessage", exeuctionError) } else if ctx.Firing { - ctx.Rule.State = m.AlertStateType(ctx.Rule.Severity) + ctx.Rule.State = m.AlertStateAlerting annotationData = simplejson.NewFromAny(ctx.EvalMatches) } else { // handle no data case @@ -90,17 +90,15 @@ func (handler *DefaultResultHandler) Handle(ctx *EvalContext) { func countStateResult(state m.AlertStateType) { switch state { - case m.AlertStateCritical: - metrics.M_Alerting_Result_State_Critical.Inc(1) - case m.AlertStateWarning: - metrics.M_Alerting_Result_State_Warning.Inc(1) + case m.AlertStateAlerting: + metrics.M_Alerting_Result_State_Alerting.Inc(1) case m.AlertStateOK: metrics.M_Alerting_Result_State_Ok.Inc(1) case m.AlertStatePaused: metrics.M_Alerting_Result_State_Paused.Inc(1) - case m.AlertStateUnknown: - metrics.M_Alerting_Result_State_Unknown.Inc(1) - case m.AlertStateExeuctionError: - metrics.M_Alerting_Result_State_ExecutionError.Inc(1) + case m.AlertStateNoData: + metrics.M_Alerting_Result_State_NoData.Inc(1) + case m.AlertStateExecError: + metrics.M_Alerting_Result_State_ExecError.Inc(1) } } diff --git a/pkg/services/alerting/rule.go b/pkg/services/alerting/rule.go index a967e2c40fb..5f59b60b64f 100644 --- a/pkg/services/alerting/rule.go +++ b/pkg/services/alerting/rule.go @@ -20,7 +20,6 @@ type Rule struct { Message string NoDataState m.AlertStateType State m.AlertStateType - Severity m.AlertSeverityType Conditions []Condition Notifications []int64 } @@ -66,9 +65,8 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) { model.Name = ruleDef.Name model.Message = ruleDef.Message model.Frequency = ruleDef.Frequency - model.Severity = ruleDef.Severity model.State = ruleDef.State - model.NoDataState = m.AlertStateType(ruleDef.Settings.Get("noDataState").MustString("unknown")) + model.NoDataState = m.AlertStateType(ruleDef.Settings.Get("noDataState").MustString("no_data")) for _, v := range ruleDef.Settings.Get("notifications").MustArray() { jsonModel := simplejson.NewFromAny(v) diff --git a/pkg/services/alerting/test_notification.go b/pkg/services/alerting/test_notification.go index c3fbaeb4f1c..c483835b8e1 100644 --- a/pkg/services/alerting/test_notification.go +++ b/pkg/services/alerting/test_notification.go @@ -4,11 +4,11 @@ import ( "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/simplejson" "github.com/grafana/grafana/pkg/log" - "github.com/grafana/grafana/pkg/models" + m "github.com/grafana/grafana/pkg/models" ) type NotificationTestCommand struct { - Severity string + State m.AlertStateType Name string Type string Settings *simplejson.Json @@ -22,7 +22,7 @@ func init() { func handleNotificationTestCommand(cmd *NotificationTestCommand) error { notifier := NewRootNotifier() - model := &models.AlertNotification{ + model := &m.AlertNotification{ Name: cmd.Name, Type: cmd.Type, Settings: cmd.Settings, @@ -35,23 +35,12 @@ func handleNotificationTestCommand(cmd *NotificationTestCommand) error { return err } - severity := models.AlertSeverityType(cmd.Severity) - notifier.sendNotifications([]Notifier{notifiers}, createTestEvalContext(severity)) + notifier.sendNotifications([]Notifier{notifiers}, createTestEvalContext(cmd.State)) return nil } -func createTestEvalContext(severity models.AlertSeverityType) *EvalContext { - state := models.AlertStateOK - firing := false - if severity == models.AlertSeverityCritical { - state = models.AlertStateCritical - firing = true - } - if severity == models.AlertSeverityWarning { - state = models.AlertStateWarning - firing = true - } +func createTestEvalContext(state m.AlertStateType) *EvalContext { testRule := &Rule{ DashboardId: 1, @@ -59,23 +48,22 @@ func createTestEvalContext(severity models.AlertSeverityType) *EvalContext { Name: "Test notification", Message: "Someone is testing the alert notification within grafana.", State: state, - Severity: severity, } ctx := NewEvalContext(testRule) ctx.ImagePublicUrl = "http://grafana.org/assets/img/blog/mixed_styles.png" ctx.IsTestRun = true - ctx.Firing = firing + ctx.Firing = state == m.AlertStateAlerting ctx.Error = nil - ctx.EvalMatches = evalMatchesBasedOnSeverity(severity) + ctx.EvalMatches = evalMatchesBasedOnState(state) return ctx } -func evalMatchesBasedOnSeverity(severity models.AlertSeverityType) []*EvalMatch { +func evalMatchesBasedOnState(state m.AlertStateType) []*EvalMatch { matches := make([]*EvalMatch, 0) - if severity == models.AlertSeverityOK { + if state == m.AlertStateOK { return matches } diff --git a/pkg/services/sqlstore/alert.go b/pkg/services/sqlstore/alert.go index cfabe7c12d2..8e22fc7dd43 100644 --- a/pkg/services/sqlstore/alert.go +++ b/pkg/services/sqlstore/alert.go @@ -159,7 +159,7 @@ func upsertAlerts(existingAlerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xor } else { alert.Updated = time.Now() alert.Created = time.Now() - alert.State = m.AlertStateUnknown + alert.State = m.AlertStateNoData alert.NewStateDate = time.Now() _, err := sess.Insert(alert) diff --git a/pkg/services/sqlstore/alert_test.go b/pkg/services/sqlstore/alert_test.go index 2bdfdd28efa..02126c2984a 100644 --- a/pkg/services/sqlstore/alert_test.go +++ b/pkg/services/sqlstore/alert_test.go @@ -47,7 +47,7 @@ func TestAlertingDataAccess(t *testing.T) { So(err2, ShouldBeNil) So(alert.Name, ShouldEqual, "Alerting title") So(alert.Message, ShouldEqual, "Alerting message") - So(alert.State, ShouldEqual, "unknown") + So(alert.State, ShouldEqual, "no_data") So(alert.Frequency, ShouldEqual, 1) }) @@ -77,7 +77,7 @@ func TestAlertingDataAccess(t *testing.T) { So(query.Result[0].Name, ShouldEqual, "Name") Convey("Alert state should not be updated", func() { - So(query.Result[0].State, ShouldEqual, "unknown") + So(query.Result[0].State, ShouldEqual, "no_data") }) }) diff --git a/public/app/features/alerting/alert_def.ts b/public/app/features/alerting/alert_def.ts index 1c0312c3028..15f1f373bd5 100644 --- a/public/app/features/alerting/alert_def.ts +++ b/public/app/features/alerting/alert_def.ts @@ -38,9 +38,8 @@ var reducerTypes = [ var noDataModes = [ {text: 'OK', value: 'ok'}, - {text: 'Critical', value: 'critical'}, - {text: 'Warning', value: 'warning'}, - {text: 'Unknown', value: 'unknown'}, + {text: 'Alerting', value: 'alerting'}, + {text: 'No Data', value: 'no_data'}, ]; function createReducerPart(model) { @@ -48,10 +47,6 @@ function createReducerPart(model) { return new QueryPart(model, def); } -var severityLevels = { - 'critical': {text: 'Critical', iconClass: 'icon-gf icon-gf-critical', stateClass: 'alert-state-critical'}, - 'warning': {text: 'Warning', iconClass: 'icon-gf icon-gf-warning', stateClass: 'alert-state-warning'}, -}; function getStateDisplayModel(state) { switch (state) { @@ -62,23 +57,16 @@ function getStateDisplayModel(state) { stateClass: 'alert-state-ok' }; } - case 'critical': { + case 'alerting': { return { - text: 'CRITICAL', + text: 'ALERTING', iconClass: 'icon-gf icon-gf-critical', stateClass: 'alert-state-critical' }; } - case 'warning': { + case 'no_data': { return { - text: 'WARNING', - iconClass: 'icon-gf icon-gf-warning', - stateClass: 'alert-state-warning' - }; - } - case 'unknown': { - return { - text: 'UNKNOWN', + text: 'NO DATA', iconClass: "fa fa-question", stateClass: 'alert-state-warning' }; @@ -106,7 +94,6 @@ export default { getStateDisplayModel: getStateDisplayModel, conditionTypes: conditionTypes, evalFunctions: evalFunctions, - severityLevels: severityLevels, noDataModes: noDataModes, reducerTypes: reducerTypes, createReducerPart: createReducerPart, diff --git a/public/app/features/alerting/alert_list_ctrl.ts b/public/app/features/alerting/alert_list_ctrl.ts index 0a8e9addcd7..4b429e961a7 100644 --- a/public/app/features/alerting/alert_list_ctrl.ts +++ b/public/app/features/alerting/alert_list_ctrl.ts @@ -13,9 +13,8 @@ export class AlertListCtrl { stateFilters = [ {text: 'All', value: null}, {text: 'OK', value: 'ok'}, - {text: 'Unknown', value: 'unknown'}, - {text: 'Warning', value: 'warning'}, - {text: 'Critical', value: 'critical'}, + {text: 'Alerting', value: 'alerting'}, + {text: 'No Data', value: 'no_data'}, {text: 'Execution Error', value: 'execution_error'}, ]; diff --git a/public/app/features/alerting/alert_tab_ctrl.ts b/public/app/features/alerting/alert_tab_ctrl.ts index ee8892f6bba..e71b7686d5c 100644 --- a/public/app/features/alerting/alert_tab_ctrl.ts +++ b/public/app/features/alerting/alert_tab_ctrl.ts @@ -17,7 +17,6 @@ export class AlertTabCtrl { alert: any; conditionModels: any; evalFunctions: any; - severityLevels: any; noDataModes: any; addNotificationSegment; notifications; @@ -41,7 +40,6 @@ export class AlertTabCtrl { this.subTabIndex = 0; this.evalFunctions = alertDef.evalFunctions; this.conditionTypes = alertDef.conditionTypes; - this.severityLevels = alertDef.severityLevels; this.noDataModes = alertDef.noDataModes; this.appSubUrl = config.appSubUrl; } @@ -155,8 +153,7 @@ export class AlertTabCtrl { alert.conditions.push(this.buildDefaultCondition()); } - alert.noDataState = alert.noDataState || 'unknown'; - alert.severity = alert.severity || 'critical'; + alert.noDataState = alert.noDataState || 'no_data'; alert.frequency = alert.frequency || '60s'; alert.handler = alert.handler || 1; alert.notifications = alert.notifications || []; @@ -321,11 +318,6 @@ export class AlertTabCtrl { this.panelCtrl.render(); } - severityChanged() { - ThresholdMapper.alertToGraphThresholds(this.panel); - this.panelCtrl.render(); - } - evaluatorTypeChanged(evaluator) { // ensure params array is correct length switch (evaluator.type) { diff --git a/public/app/features/alerting/partials/alert_tab.html b/public/app/features/alerting/partials/alert_tab.html index a8ec861a5eb..434605ffe5e 100644 --- a/public/app/features/alerting/partials/alert_tab.html +++ b/public/app/features/alerting/partials/alert_tab.html @@ -29,18 +29,8 @@
Name -
-
-
- Evaluate every - -
-
- Severity -
- -
+ Evaluate every +
diff --git a/public/app/features/alerting/threshold_mapper.ts b/public/app/features/alerting/threshold_mapper.ts index 16801b9a9fa..b14f9a4d933 100644 --- a/public/app/features/alerting/threshold_mapper.ts +++ b/public/app/features/alerting/threshold_mapper.ts @@ -62,7 +62,7 @@ export class ThresholdMapper { for (var t of panel.thresholds) { t.fill = true; t.line = true; - t.colorMode = panel.alert.severity; + t.colorMode = 'critical'; } var updated = true;