mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Pagerduty notifier: configurable severity Instead of hardcoding `critical` make it configurable per notification channel instance. * fix html * Add a test to ensure default severity is correct * Notifications doc * Add a non-default test * Add err check on NewJson (all tests) * Add default severity (critical) to AlertNotificationEditCtrl class
104 lines
3.0 KiB
Go
104 lines
3.0 KiB
Go
package notifiers
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
"github.com/grafana/grafana/pkg/models"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
func TestPagerdutyNotifier(t *testing.T) {
|
|
Convey("Pagerduty notifier tests", t, func() {
|
|
Convey("Parsing alert notification from settings", func() {
|
|
Convey("empty settings should return error", func() {
|
|
json := `{ }`
|
|
|
|
settingsJSON, jerr := simplejson.NewJson([]byte(json))
|
|
So(jerr, ShouldBeNil)
|
|
|
|
model := &models.AlertNotification{
|
|
Name: "pageduty_testing",
|
|
Type: "pagerduty",
|
|
Settings: settingsJSON,
|
|
}
|
|
|
|
_, err := NewPagerdutyNotifier(model)
|
|
So(err, ShouldNotBeNil)
|
|
})
|
|
|
|
Convey("severity should override default", func() {
|
|
json := `{ "integrationKey": "abcdefgh0123456789", "severity": "info" }`
|
|
|
|
settingsJSON, jerr := simplejson.NewJson([]byte(json))
|
|
So(jerr, ShouldBeNil)
|
|
|
|
model := &models.AlertNotification{
|
|
Name: "pagerduty_testing",
|
|
Type: "pagerduty",
|
|
Settings: settingsJSON,
|
|
}
|
|
|
|
not, err := NewPagerdutyNotifier(model)
|
|
pagerdutyNotifier := not.(*PagerdutyNotifier)
|
|
|
|
So(err, ShouldBeNil)
|
|
So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
|
|
So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
|
|
So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
|
|
So(pagerdutyNotifier.Severity, ShouldEqual, "info")
|
|
So(pagerdutyNotifier.AutoResolve, ShouldBeFalse)
|
|
})
|
|
|
|
Convey("auto resolve and severity should have expected defaults", func() {
|
|
json := `{ "integrationKey": "abcdefgh0123456789" }`
|
|
|
|
settingsJSON, jerr := simplejson.NewJson([]byte(json))
|
|
So(jerr, ShouldBeNil)
|
|
|
|
model := &models.AlertNotification{
|
|
Name: "pagerduty_testing",
|
|
Type: "pagerduty",
|
|
Settings: settingsJSON,
|
|
}
|
|
|
|
not, err := NewPagerdutyNotifier(model)
|
|
pagerdutyNotifier := not.(*PagerdutyNotifier)
|
|
|
|
So(err, ShouldBeNil)
|
|
So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
|
|
So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
|
|
So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
|
|
So(pagerdutyNotifier.Severity, ShouldEqual, "critical")
|
|
So(pagerdutyNotifier.AutoResolve, ShouldBeFalse)
|
|
})
|
|
|
|
Convey("settings should trigger incident", func() {
|
|
json := `
|
|
{
|
|
"integrationKey": "abcdefgh0123456789",
|
|
"autoResolve": false
|
|
}`
|
|
|
|
settingsJSON, jerr := simplejson.NewJson([]byte(json))
|
|
So(jerr, ShouldBeNil)
|
|
|
|
model := &models.AlertNotification{
|
|
Name: "pagerduty_testing",
|
|
Type: "pagerduty",
|
|
Settings: settingsJSON,
|
|
}
|
|
|
|
not, err := NewPagerdutyNotifier(model)
|
|
pagerdutyNotifier := not.(*PagerdutyNotifier)
|
|
|
|
So(err, ShouldBeNil)
|
|
So(pagerdutyNotifier.Name, ShouldEqual, "pagerduty_testing")
|
|
So(pagerdutyNotifier.Type, ShouldEqual, "pagerduty")
|
|
So(pagerdutyNotifier.Key, ShouldEqual, "abcdefgh0123456789")
|
|
So(pagerdutyNotifier.AutoResolve, ShouldBeFalse)
|
|
})
|
|
})
|
|
})
|
|
}
|