From 0b765f7fc123c5a237c4419753e54d5309858668 Mon Sep 17 00:00:00 2001 From: Marcos Wright-Kuhns Date: Mon, 24 Jun 2024 09:50:05 -0700 Subject: [PATCH 1/3] Update the router example to use the pagerduty_service data source --- .../r/event_orchestration_router.html.markdown | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/website/docs/r/event_orchestration_router.html.markdown b/website/docs/r/event_orchestration_router.html.markdown index 821289d4a..44f02a436 100644 --- a/website/docs/r/event_orchestration_router.html.markdown +++ b/website/docs/r/event_orchestration_router.html.markdown @@ -14,9 +14,15 @@ An Orchestration Router allows users to create a set of Event Rules. The Router In this example the user has defined the Router with two rules, each routing to a different service. -This example assumes services used in the `route_to` configuration already exists. So it does not show creation of service resource. - ```hcl +data "pagerduty_service" "database" { + name = "Primary Data Store" +} + +data "pagerduty_service" "www" { + name = "Web Server App" +} + resource "pagerduty_event_orchestration_router" "router" { event_orchestration = pagerduty_event_orchestration.my_monitor.id set { @@ -30,7 +36,7 @@ resource "pagerduty_event_orchestration_router" "router" { expression = "event.source matches regex 'db[0-9]+-server'" } actions { - route_to = pagerduty_service.database.id + route_to = data.pagerduty_service.database.id } } rule { @@ -38,7 +44,7 @@ resource "pagerduty_event_orchestration_router" "router" { expression = "event.summary matches part 'www'" } actions { - route_to = pagerduty_service.www.id + route_to = data.pagerduty_service.www.id } } } From 5d47a13e35e40241255c00c661c8f67ab4501060 Mon Sep 17 00:00:00 2001 From: Marcos Wright-Kuhns Date: Mon, 24 Jun 2024 12:20:54 -0700 Subject: [PATCH 2/3] Add a dynamic router rule example --- .../docs/r/event_orchestration_router.html.markdown | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/website/docs/r/event_orchestration_router.html.markdown b/website/docs/r/event_orchestration_router.html.markdown index 44f02a436..2f88727f7 100644 --- a/website/docs/r/event_orchestration_router.html.markdown +++ b/website/docs/r/event_orchestration_router.html.markdown @@ -12,7 +12,7 @@ An Orchestration Router allows users to create a set of Event Rules. The Router ## Example of configuring Router rules for an Orchestration -In this example the user has defined the Router with two rules, each routing to a different service. +In this example the user has defined the Router with three rules. The first rule configures a dynamic route: any event containing a value in its `pd_service_id` custom detail will be routed to the Service with the ID specified by that value. The other rules route events matching a condition to specific services. ```hcl data "pagerduty_service" "database" { @@ -27,6 +27,16 @@ resource "pagerduty_event_orchestration_router" "router" { event_orchestration = pagerduty_event_orchestration.my_monitor.id set { id = "start" + rule { + label = "Dynamically route events related to specific PagerDuty services" + actions { + dynamic_route_to = { + lookup_by = "service_id" + source = "event.custom_details.pd_service_id" + regexp = "(.*)" + } + } + } rule { label = "Events relating to our relational database" condition { From dda518bd5d6c6e57262dbf3526de84e80fc434b3 Mon Sep 17 00:00:00 2001 From: Marcos Wright-Kuhns Date: Mon, 24 Jun 2024 12:21:23 -0700 Subject: [PATCH 3/3] Document the dynamic vs static router actions --- .../r/event_orchestration_router.html.markdown | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/website/docs/r/event_orchestration_router.html.markdown b/website/docs/r/event_orchestration_router.html.markdown index 2f88727f7..c232ea8b4 100644 --- a/website/docs/r/event_orchestration_router.html.markdown +++ b/website/docs/r/event_orchestration_router.html.markdown @@ -88,6 +88,22 @@ The following arguments are supported: * `expression`- (Required) A [PCL condition](https://developer.pagerduty.com/docs/ZG9jOjM1NTE0MDc0-pcl-overview) string. ### Actions (`actions`) supports the following: + +#### Dynamic Routing + +Use the contents of an event payload to dynamically route an event to the target service. Note these setting can only be used once in the Router, and only in the first rule. The dynamic routing rule cannot have `conditions` nor a `route_to` action defined. + +* `dynamic_route_to` - (Required) supports the following: + * `source` - (Required) The path to a field in an event. + * `regex` - (Required) The regular expression, used to extract a value from the source field. Must use valid [RE2 regular expression](https://github.com/google/re2/wiki/Syntax) syntax. + * `lookup_by` - (Required) Indicates whether the extracted value from the source is a service's name or ID. Allowed values are: `service_name`, `service_id` + +If an event has a value at the specified `source`, and if the `regex` successfully matches the value, and if the matching portion is valid Service ID or Name, then the event will be routed to that service. Otherwise the event will be checked against any subsequent router rules. + +#### Service Route + +If an event matches this rule's conditions, then route it to the specified Service. + * `route_to` - (Required) The ID of the target Service for the resulting alert. ### Catch All (`catch_all`) supports the following: