feat(alerting): add alert message to slack integration

This commit is contained in:
bergquist
2016-08-12 10:12:04 +02:00
parent e7613b8bc0
commit 16e75a3036
12 changed files with 30 additions and 30 deletions
+1 -1
View File
@@ -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()),
}
+5 -5
View File
@@ -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() {
+5 -4
View File
@@ -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(),
},
+2 -2
View File
@@ -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
+3 -3
View File
@@ -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",
},
}
@@ -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},