Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add escalation schedule in responder type in alert policy #135

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ func TestCreateAlertPolicy_Validate(t *testing.T) {

req.Responders = &[]alert.Responder{
{
Type: alert.ScheduleResponder,
Type: "",
Name: "",
Id: "",
Username: "",
},
}
err = req.Validate()
assert.Equal(t, err.Error(), errors.New("responder type for alert policy should be one of team or user").Error())
assert.Equal(t, err.Error(), errors.New("responder type for alert policy should be one of team, user, escalation or schedule").Error())

req.Responders = &[]alert.Responder{
{
Expand Down Expand Up @@ -179,6 +179,50 @@ func TestCreateAlertPolicy_Validate(t *testing.T) {
err = req.Validate()
assert.Nil(t, err)

req.Responders = &[]alert.Responder{
{
Type: alert.EscalationResponder,
Name: "",
Id: "",
Username: "user1",
},
}
err = req.Validate()
assert.Equal(t, err.Error(), errors.New("responder id should be provided").Error())

req.Responders = &[]alert.Responder{
{
Type: alert.EscalationResponder,
Name: "",
Id: "teamId",
Username: "",
},
}
err = req.Validate()
assert.Nil(t, err)

req.Responders = &[]alert.Responder{
{
Type: alert.ScheduleResponder,
Name: "",
Id: "",
Username: "user1",
},
}
err = req.Validate()
assert.Equal(t, err.Error(), errors.New("responder id should be provided").Error())

req.Responders = &[]alert.Responder{
{
Type: alert.ScheduleResponder,
Name: "",
Id: "teamId",
Username: "",
},
}
err = req.Validate()
assert.Nil(t, err)

req.Priority = "asd"
err = req.Validate()
assert.Equal(t, err.Error(), errors.New("Priority should be one of these: 'P1', 'P2', 'P3', 'P4' and 'P5'").Error())
Expand Down
4 changes: 2 additions & 2 deletions policy/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ func ValidateDelayAction(action DelayAction) error {

func ValidateResponders(responders *[]alert.Responder) error {
for _, responder := range *responders {
if responder.Type != alert.UserResponder && responder.Type != alert.TeamResponder {
return errors.New("responder type for alert policy should be one of team or user")
if responder.Type != alert.UserResponder && responder.Type != alert.TeamResponder && responder.Type != alert.EscalationResponder && responder.Type != alert.ScheduleResponder {
return errors.New("responder type for alert policy should be one of team, user, escalation or schedule")
}
if responder.Id == "" {
return errors.New("responder id should be provided")
Expand Down