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

Rule actions updates #157

Merged
merged 15 commits into from
Jul 22, 2024
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
8 changes: 8 additions & 0 deletions pagerduty/event_orchestration_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type EventOrchestrationPathRuleCondition struct {
type EventOrchestrationPathRuleActions struct {
DropEvent bool `json:"drop_event"`
RouteTo string `json:"route_to"`
DynamicRouteTo *EventOrchestrationPathDynamicRouteTo `json:"dynamic_route_to"`
Suppress bool `json:"suppress"`
Suspend *int `json:"suspend"`
Priority string `json:"priority"`
Expand All @@ -64,6 +65,13 @@ type EventOrchestrationPathRuleActions struct {
EventAction string `json:"event_action"`
Variables []*EventOrchestrationPathActionVariables `json:"variables"`
Extractions []*EventOrchestrationPathActionExtractions `json:"extractions"`
EscalationPolicy *string `json:"escalation_policy"`
}

type EventOrchestrationPathDynamicRouteTo struct {
Source string `json:"source,omitempty"`
Regex string `json:"regex,omitempty"`
LookupBy string `json:"lookup_by,omitempty"`
}

type EventOrchestrationPathIncidentCustomFieldUpdate struct {
Expand Down
72 changes: 71 additions & 1 deletion pagerduty/event_orchestration_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,65 @@ func TestEventOrchestrationPathGlobalUpdate(t *testing.T) {
}
}

func TestEventOrchestrationPathEscalationPolicyUpdate(t *testing.T) {
setup()
defer teardown()
input := &EventOrchestrationPath{
Type: "global",
Parent: &EventOrchestrationPathReference{
ID: "E-ORC-1",
Self: "https://api.pagerduty.com/event_orchestrations/E-ORC-1",
Type: "event_orchestration_reference",
},
}

var url = fmt.Sprintf("%s/E-ORC-1/global", eventOrchestrationBaseUrl)

mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
v := new(EventOrchestrationPathPayload)
json.NewDecoder(r.Body).Decode(v)
if !reflect.DeepEqual(v.OrchestrationPath, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
w.Write([]byte(`{ "orchestration_path": { "type": "global", "parent": { "id": "E-ORC-1", "self": "https://api.pagerduty.com/event_orchestrations/E-ORC-1", "type": "event_orchestration_reference" }, "sets": [ { "id": "start", "rules": [ { "actions": { "escalation_policy": "POLICY"}, "id": "E-ORC-EP-RULE" } ] } ] } }`))
})
resp, _, err := client.EventOrchestrationPaths.Update("E-ORC-1", PathTypeGlobal, input)
if err != nil {
t.Fatal(err)
}

policy := "POLICY"
want := &EventOrchestrationPathPayload{
OrchestrationPath: &EventOrchestrationPath{
Type: "global",
Parent: &EventOrchestrationPathReference{
ID: "E-ORC-1",
Self: "https://api.pagerduty.com/event_orchestrations/E-ORC-1",
Type: "event_orchestration_reference",
},
Sets: []*EventOrchestrationPathSet{
{
ID: "start",
Rules: []*EventOrchestrationPathRule{
{
Actions: &EventOrchestrationPathRuleActions{
EscalationPolicy: &policy,
},
ID: "E-ORC-EP-RULE",
},
},
},
},
},
Warnings: nil,
}

if !reflect.DeepEqual(resp, want) {
t.Errorf("returned \n\n%#v want \n\n%#v", resp, want)
}
}

func TestEventOrchestrationPathRouterUpdate(t *testing.T) {
setup()
defer teardown()
Expand All @@ -515,7 +574,7 @@ func TestEventOrchestrationPathRouterUpdate(t *testing.T) {
if !reflect.DeepEqual(v.OrchestrationPath, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
w.Write([]byte(`{"orchestration_path": { "type": "router", "parent": { "id": "E-ORC-1", "self": "https://api.pagerduty.com/event_orchestrations/E-ORC-1", "type": "event_orchestration_reference" }, "sets": [ { "id": "start", "rules": [ { "actions": { "route_to": "P3ZQXDF" }, "conditions": [ { "expression": "event.summary matches part 'orca'" }, { "expression": "event.summary matches part 'humpback'" } ], "id": "E-ORC-RULE-1"}]}]}}`))
w.Write([]byte(`{"orchestration_path": { "type": "router", "parent": { "id": "E-ORC-1", "self": "https://api.pagerduty.com/event_orchestrations/E-ORC-1", "type": "event_orchestration_reference" }, "sets": [ { "id": "start", "rules": [ {"actions": { "dynamic_route_to": { "source": "event.summary", "regex": "service name: (.*)", "lookup_by": "service_name" }}, "conditions": [], "id": "E-ORC-DYNAMIC-RULE"}, { "actions": { "route_to": "P3ZQXDF" }, "conditions": [ { "expression": "event.summary matches part 'orca'" }, { "expression": "event.summary matches part 'humpback'" } ], "id": "E-ORC-RULE-1"}]}]}}`))
})

resp, _, err := client.EventOrchestrationPaths.Update("E-ORC-1", PathTypeRouter, input)
Expand All @@ -535,6 +594,17 @@ func TestEventOrchestrationPathRouterUpdate(t *testing.T) {
{
ID: "start",
Rules: []*EventOrchestrationPathRule{
{
Actions: &EventOrchestrationPathRuleActions{
DynamicRouteTo: &EventOrchestrationPathDynamicRouteTo{
Source: "event.summary",
Regex: "service name: (.*)",
LookupBy: "service_name",
},
},
Conditions: []*EventOrchestrationPathRuleCondition{},
ID: "E-ORC-DYNAMIC-RULE",
},
{
Actions: &EventOrchestrationPathRuleActions{
RouteTo: "P3ZQXDF",
Expand Down
Loading