diff --git a/pagerduty/event_orchestration_path.go b/pagerduty/event_orchestration_path.go index 72b60e0..f4a3b59 100644 --- a/pagerduty/event_orchestration_path.go +++ b/pagerduty/event_orchestration_path.go @@ -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"` @@ -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 { diff --git a/pagerduty/event_orchestration_path_test.go b/pagerduty/event_orchestration_path_test.go index ed4f7c3..514f0b7 100644 --- a/pagerduty/event_orchestration_path_test.go +++ b/pagerduty/event_orchestration_path_test.go @@ -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() @@ -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) @@ -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",