diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index e7a8609f637..8546a4e439f 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -47,7 +47,7 @@ func GetAlerts(c *middleware.Context) Response { DashboardId: alert.DashboardId, PanelId: alert.PanelId, Name: alert.Name, - Description: alert.Description, + Message: alert.Message, State: alert.State, Severity: alert.Severity, }) diff --git a/pkg/api/dtos/alerting.go b/pkg/api/dtos/alerting.go index 244d2bede66..ce8995eb2f6 100644 --- a/pkg/api/dtos/alerting.go +++ b/pkg/api/dtos/alerting.go @@ -12,7 +12,7 @@ type AlertRule struct { DashboardId int64 `json:"dashboardId"` PanelId int64 `json:"panelId"` Name string `json:"name"` - Description string `json:"description"` + Message string `json:"message"` State m.AlertStateType `json:"state"` Severity m.AlertSeverityType `json:"severity"` diff --git a/pkg/metrics/graphite_test.go b/pkg/metrics/graphite_test.go index 31620bdd161..03b9917258a 100644 --- a/pkg/metrics/graphite_test.go +++ b/pkg/metrics/graphite_test.go @@ -19,7 +19,7 @@ func TestGraphitePublisher(t *testing.T) { So(err, ShouldBeNil) sec, err := setting.Cfg.NewSection("metrics.graphite") - sec.NewKey("prefix", "service.grafana.%(instance_name)s") + sec.NewKey("prefix", "service.grafana.%(instance_name)s.") sec.NewKey("address", "localhost:2003") So(err, ShouldBeNil) @@ -30,7 +30,7 @@ func TestGraphitePublisher(t *testing.T) { So(err, ShouldBeNil) So(publisher, ShouldNotBeNil) - So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com") + So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.") }) Convey("Test graphite publisher default values", t, func() { @@ -49,7 +49,7 @@ func TestGraphitePublisher(t *testing.T) { So(err, ShouldBeNil) So(publisher, ShouldNotBeNil) - So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com") + So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.") So(publisher.address, ShouldEqual, "localhost:2003") }) } diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index f084a955d57..9477f2738b5 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -80,9 +80,9 @@ func initMetricVars(settings *MetricSettings) { M_Alerting_Result_Info = RegCounter("alerting.result", "severity", "info") M_Alerting_Result_Ok = RegCounter("alerting.result", "severity", "ok") M_Alerting_Active_Alerts = RegCounter("alerting.active_alerts") - M_Alerting_Notification_Sent_Slack = RegCounter("alerting.notifcations_sent", "type", "slack") - M_Alerting_Notification_Sent_Email = RegCounter("alerting.notifcations_sent", "type", "email") - M_Alerting_Notification_Sent_Webhook = RegCounter("alerting.notifcations_sent", "type", "webhook") + M_Alerting_Notification_Sent_Slack = RegCounter("alerting.notifications_sent", "type", "slack") + M_Alerting_Notification_Sent_Email = RegCounter("alerting.notifications_sent", "type", "email") + M_Alerting_Notification_Sent_Webhook = RegCounter("alerting.notifications_sent", "type", "webhook") // Timers M_DataSource_ProxyReq_Timer = RegTimer("api.dataproxy.request.all") diff --git a/pkg/models/alert.go b/pkg/models/alert.go index 722c69a9ef7..d8e6c5fc899 100644 --- a/pkg/models/alert.go +++ b/pkg/models/alert.go @@ -36,7 +36,7 @@ type Alert struct { DashboardId int64 PanelId int64 Name string - Description string + Message string Severity AlertSeverityType State AlertStateType Handler int64 @@ -63,7 +63,7 @@ func (alert *Alert) ShouldUpdateState(newState AlertStateType) bool { func (this *Alert) ContainsUpdates(other *Alert) bool { result := false result = result || this.Name != other.Name - result = result || this.Description != other.Description + result = result || this.Message != other.Message if this.Settings != nil && other.Settings != nil { json1, err1 := this.Settings.Encode() diff --git a/pkg/models/alert_test.go b/pkg/models/alert_test.go index 2e07d9f0ce4..421b90f1b21 100644 --- a/pkg/models/alert_test.go +++ b/pkg/models/alert_test.go @@ -14,15 +14,15 @@ func TestAlertingModelTest(t *testing.T) { json2, _ := simplejson.NewJson([]byte(`{ "field": "value" }`)) rule1 := &Alert{ - Settings: json1, - Name: "Namn", - Description: "Description", + Settings: json1, + Name: "Namn", + Message: "Message", } rule2 := &Alert{ - Settings: json2, - Name: "Namn", - Description: "Description", + Settings: json2, + Name: "Namn", + Message: "Message", } Convey("Testing AlertRule equals", func() { diff --git a/pkg/services/alerting/extractor.go b/pkg/services/alerting/extractor.go index 7713f221c28..a5704fd15bb 100644 --- a/pkg/services/alerting/extractor.go +++ b/pkg/services/alerting/extractor.go @@ -88,7 +88,7 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) { Name: jsonAlert.Get("name").MustString(), Handler: jsonAlert.Get("handler").MustInt64(), Enabled: jsonAlert.Get("enabled").MustBool(), - Description: jsonAlert.Get("description").MustString(), + Message: jsonAlert.Get("message").MustString(), Severity: m.AlertSeverityType(jsonAlert.Get("severity").MustString()), Frequency: getTimeDurationStringToSeconds(jsonAlert.Get("frequency").MustString()), } diff --git a/pkg/services/alerting/extractor_test.go b/pkg/services/alerting/extractor_test.go index 810c993a0b5..e3df5e571d1 100644 --- a/pkg/services/alerting/extractor_test.go +++ b/pkg/services/alerting/extractor_test.go @@ -40,7 +40,7 @@ func TestAlertRuleExtraction(t *testing.T) { "datasource": null, "alert": { "name": "name1", - "description": "desc1", + "message": "desc1", "handler": 1, "enabled": true, "frequency": "60s", @@ -65,7 +65,7 @@ func TestAlertRuleExtraction(t *testing.T) { "datasource": "graphite2", "alert": { "name": "name2", - "description": "desc2", + "message": "desc2", "handler": 0, "enabled": true, "frequency": "60s", @@ -121,7 +121,7 @@ func TestAlertRuleExtraction(t *testing.T) { for _, v := range alerts { So(v.DashboardId, ShouldEqual, 57) So(v.Name, ShouldNotBeEmpty) - So(v.Description, ShouldNotBeEmpty) + So(v.Message, ShouldNotBeEmpty) } Convey("should extract handler property", func() { @@ -146,9 +146,9 @@ func TestAlertRuleExtraction(t *testing.T) { Convey("should extract name and desc", func() { So(alerts[0].Name, ShouldEqual, "name1") - So(alerts[0].Description, ShouldEqual, "desc1") + So(alerts[0].Message, ShouldEqual, "desc1") So(alerts[1].Name, ShouldEqual, "name2") - So(alerts[1].Description, ShouldEqual, "desc2") + So(alerts[1].Message, ShouldEqual, "desc2") }) Convey("should set datasourceId", func() { diff --git a/pkg/services/alerting/notifiers/slack.go b/pkg/services/alerting/notifiers/slack.go index e2c479b4425..c311840f488 100644 --- a/pkg/services/alerting/notifiers/slack.go +++ b/pkg/services/alerting/notifiers/slack.go @@ -9,6 +9,7 @@ import ( "github.com/grafana/grafana/pkg/metrics" m "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/services/alerting" + "github.com/grafana/grafana/pkg/setting" ) func init() { @@ -70,11 +71,11 @@ func (this *SlackNotifier) Notify(context *alerting.EvalContext) { // "author_icon": "http://flickr.com/icons/bobby.jpg", "title": context.GetNotificationTitle(), "title_link": ruleUrl, - // "text": "Optional text that appears within the attachment", - "fields": fields, - "image_url": context.ImagePublicUrl, + "text": context.Rule.Message, + "fields": fields, + "image_url": context.ImagePublicUrl, // "thumb_url": "http://example.com/path/to/thumb.png", - "footer": "Grafana v4.0.0", + "footer": "Grafana v" + setting.BuildVersion, "footer_icon": "http://grafana.org/assets/img/fav32.png", "ts": time.Now().Unix(), }, diff --git a/pkg/services/alerting/rule.go b/pkg/services/alerting/rule.go index f11156957e8..8292041e04c 100644 --- a/pkg/services/alerting/rule.go +++ b/pkg/services/alerting/rule.go @@ -17,7 +17,7 @@ type Rule struct { PanelId int64 Frequency int64 Name string - Description string + Message string State m.AlertStateType Severity m.AlertSeverityType Conditions []Condition @@ -63,7 +63,7 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) { model.DashboardId = ruleDef.DashboardId model.PanelId = ruleDef.PanelId model.Name = ruleDef.Name - model.Description = ruleDef.Description + model.Message = ruleDef.Message model.Frequency = ruleDef.Frequency model.Severity = ruleDef.Severity model.State = ruleDef.State diff --git a/pkg/services/notifications/notifications_test.go b/pkg/services/notifications/notifications_test.go index 09bfbd459e1..d4f4ee0a5fb 100644 --- a/pkg/services/notifications/notifications_test.go +++ b/pkg/services/notifications/notifications_test.go @@ -40,84 +40,5 @@ func TestNotifications(t *testing.T) { So(sentMsg.Subject, ShouldEqual, "Reset your Grafana password - asd@asd.com") So(sentMsg.Body, ShouldNotContainSubstring, "Subject") }) - - Convey("Alert notifications", func() { - // Convey("When sending reset email password", func() { - // cmd := &m.SendEmailCommand{ - // Data: map[string]interface{}{ - // "Name": "Name", - // "State": "Critical", - // "Description": "Description", - // "DashboardLink": "http://localhost:3000/dashboard/db/alerting", - // "AlertPageUrl": "http://localhost:3000/alerting", - // "DashboardImage": "http://localhost:3000/render/dashboard-solo/db/alerting?from=1466169458375&to=1466171258375&panelId=1&width=1000&height=500", - // "TriggeredAlerts": []testTriggeredAlert{ - // {Name: "desktop", State: "Critical", ActualValue: 13}, - // {Name: "mobile", State: "Warn", ActualValue: 5}, - // }, - // }, - // To: []string{"asd@asd.com "}, - // Template: "alert_notification.html", - // } - // - // err := sendEmailCommandHandler(cmd) - // So(err, ShouldBeNil) - // - // So(sentMsg.Body, ShouldContainSubstring, "Alertstate: Critical") - // So(sentMsg.Body, ShouldContainSubstring, "http://localhost:3000/dashboard/db/alerting") - // So(sentMsg.Body, ShouldContainSubstring, "Critical") - // So(sentMsg.Body, ShouldContainSubstring, "Warn") - // So(sentMsg.Body, ShouldContainSubstring, "mobile") - // So(sentMsg.Body, ShouldContainSubstring, "desktop") - // So(sentMsg.Subject, ShouldContainSubstring, "Grafana Alert: [ Critical ] ") - // }) - // - // Convey("given critical", func() { - // cmd := &m.SendEmailCommand{ - // Data: map[string]interface{}{ - // "Name": "Name", - // "State": "Warn", - // "Description": "Description", - // "DashboardLink": "http://localhost:3000/dashboard/db/alerting", - // "DashboardImage": "http://localhost:3000/render/dashboard-solo/db/alerting?from=1466169458375&to=1466171258375&panelId=1&width=1000&height=500", - // "AlertPageUrl": "http://localhost:3000/alerting", - // "TriggeredAlerts": []testTriggeredAlert{ - // {Name: "desktop", State: "Critical", ActualValue: 13}, - // {Name: "mobile", State: "Warn", ActualValue: 5}, - // }, - // }, - // To: []string{"asd@asd.com "}, - // Template: "alert_notification.html", - // } - // - // err := sendEmailCommandHandler(cmd) - // So(err, ShouldBeNil) - // So(sentMsg.Body, ShouldContainSubstring, "Alertstate: Warn") - // So(sentMsg.Body, ShouldContainSubstring, "http://localhost:3000/dashboard/db/alerting") - // So(sentMsg.Body, ShouldContainSubstring, "Critical") - // So(sentMsg.Body, ShouldContainSubstring, "Warn") - // So(sentMsg.Body, ShouldContainSubstring, "mobile") - // So(sentMsg.Body, ShouldContainSubstring, "desktop") - // So(sentMsg.Subject, ShouldContainSubstring, "Grafana Alert: [ Warn ]") - // }) - // - // Convey("given ok", func() { - // cmd := &m.SendEmailCommand{ - // Data: map[string]interface{}{ - // "Name": "Name", - // "State": "Ok", - // "Description": "Description", - // "DashboardLink": "http://localhost:3000/dashboard/db/alerting", - // "AlertPageUrl": "http://localhost:3000/alerting", - // }, - // To: []string{"asd@asd.com "}, - // Template: "alert_notification.html", - // } - // - // err := sendEmailCommandHandler(cmd) - // So(err, ShouldBeNil) - // So(sentMsg.Subject, ShouldContainSubstring, "Grafana Alert: [ Ok ]") - // }) - }) }) } diff --git a/pkg/services/sqlstore/alert_test.go b/pkg/services/sqlstore/alert_test.go index 8e06ded2cd3..e22b1c48c47 100644 --- a/pkg/services/sqlstore/alert_test.go +++ b/pkg/services/sqlstore/alert_test.go @@ -20,7 +20,7 @@ func TestAlertingDataAccess(t *testing.T) { DashboardId: testDash.Id, OrgId: testDash.OrgId, Name: "Alerting title", - Description: "Alerting description", + Message: "Alerting message", Settings: simplejson.New(), Frequency: 1, }, @@ -46,7 +46,7 @@ func TestAlertingDataAccess(t *testing.T) { alert := alertQuery.Result[0] So(err2, ShouldBeNil) So(alert.Name, ShouldEqual, "Alerting title") - So(alert.Description, ShouldEqual, "Alerting description") + So(alert.Message, ShouldEqual, "Alerting message") So(alert.State, ShouldEqual, "pending") So(alert.Frequency, ShouldEqual, 1) }) @@ -146,7 +146,7 @@ func TestAlertingDataAccess(t *testing.T) { PanelId: 1, DashboardId: testDash.Id, Name: "Alerting title", - Description: "Alerting description", + Message: "Alerting message", }, } diff --git a/pkg/services/sqlstore/migrations/alert_mig.go b/pkg/services/sqlstore/migrations/alert_mig.go index f51087e7f78..fa54fe9ece0 100644 --- a/pkg/services/sqlstore/migrations/alert_mig.go +++ b/pkg/services/sqlstore/migrations/alert_mig.go @@ -14,7 +14,7 @@ func addAlertMigrations(mg *Migrator) { {Name: "panel_id", Type: DB_BigInt, Nullable: false}, {Name: "org_id", Type: DB_BigInt, Nullable: false}, {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false}, - {Name: "description", Type: DB_Text, Nullable: false}, + {Name: "message", Type: DB_Text, Nullable: false}, {Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false}, {Name: "settings", Type: DB_Text, Nullable: false}, {Name: "frequency", Type: DB_BigInt, Nullable: false}, diff --git a/public/app/features/alerting/alert_tab_ctrl.ts b/public/app/features/alerting/alert_tab_ctrl.ts index c02b4597ae6..328c8d0f874 100644 --- a/public/app/features/alerting/alert_tab_ctrl.ts +++ b/public/app/features/alerting/alert_tab_ctrl.ts @@ -111,7 +111,6 @@ export class AlertTabCtrl { var defaultName = this.panel.title + ' alert'; alert.name = alert.name || defaultName; - alert.description = alert.description || defaultName; this.conditionModels = _.reduce(alert.conditions, (memo, value) => { memo.push(this.buildConditionModel(value));