2016-11-01 02:19:43 -05:00
|
|
|
package notifiers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2019-05-14 01:15:05 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2016-11-01 02:19:43 -05:00
|
|
|
. "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, _ := simplejson.NewJson([]byte(json))
|
2019-05-14 01:15:05 -05:00
|
|
|
model := &models.AlertNotification{
|
2016-11-01 02:19:43 -05:00
|
|
|
Name: "pageduty_testing",
|
|
|
|
Type: "pagerduty",
|
|
|
|
Settings: settingsJSON,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := NewPagerdutyNotifier(model)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2017-12-22 03:54:48 -06:00
|
|
|
Convey("auto resolve should default to false", func() {
|
|
|
|
json := `{ "integrationKey": "abcdefgh0123456789" }`
|
|
|
|
|
|
|
|
settingsJSON, _ := simplejson.NewJson([]byte(json))
|
2019-05-14 01:15:05 -05:00
|
|
|
model := &models.AlertNotification{
|
2017-12-22 03:54:48 -06:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2016-11-07 09:12:43 -06:00
|
|
|
Convey("settings should trigger incident", func() {
|
2016-11-01 02:19:43 -05:00
|
|
|
json := `
|
|
|
|
{
|
2017-12-22 02:58:18 -06:00
|
|
|
"integrationKey": "abcdefgh0123456789",
|
|
|
|
"autoResolve": false
|
2016-11-01 02:19:43 -05:00
|
|
|
}`
|
|
|
|
|
|
|
|
settingsJSON, _ := simplejson.NewJson([]byte(json))
|
2019-05-14 01:15:05 -05:00
|
|
|
model := &models.AlertNotification{
|
2016-11-01 02:19:43 -05:00
|
|
|
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")
|
2017-12-22 02:58:18 -06:00
|
|
|
So(pagerdutyNotifier.AutoResolve, ShouldBeFalse)
|
2016-11-01 02:19:43 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|