Skip to content

Commit

Permalink
Merge pull request #135 from opsgenie/add-escalation-schedule-in-resp…
Browse files Browse the repository at this point in the history
…onder-type-in-alert-policy

* add Escalation & Schedule responder type in alert policies

---------

Co-authored-by: Jan Horstmann <[email protected]>
  • Loading branch information
arjunrajpal and janhorstmann authored Jul 11, 2023
2 parents 121d2e9 + ba3b819 commit b54d8bd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
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

0 comments on commit b54d8bd

Please sign in to comment.