diff --git a/content/en/synthetics/notifications/conditional_alerting.md b/content/en/synthetics/notifications/conditional_alerting.md index 16bdbd89e65..b7e6d7b68f5 100644 --- a/content/en/synthetics/notifications/conditional_alerting.md +++ b/content/en/synthetics/notifications/conditional_alerting.md @@ -24,11 +24,11 @@ To ensure notifications are delivered properly, always include a notification ha For more detailed information, see the Monitor documentation. -### Examples +## Examples -**Send alerts based on status code:** +### Send alerts based on status code -```handlebars +```shell {{! If a test triggers an alert for an API test and returns a 500 statuscode, notify the backend team. }} @@ -37,13 +37,37 @@ If a test triggers an alert for an API test and returns a 500 statuscode, notify {{/is_alert}} ``` -**Send alerts to a specific Slack channel based on failed step:** +### Send alerts based on an error code -```handlebars +```shell +{{! +Use multiple is_exact_match conditions to display specific failure codes in your notification. +This example checks for DNS and INCORRECT_ASSERTION failure codes +}} + +{{#if synthetics.attributes.result.failure}} + +{{#is_exact_match "synthetics.attributes.result.failure.code" "DNS"}} +print out failure code: The failure code is DNS +{{/is_exact_match}} + +{{#is_exact_match "synthetics.attributes.result.failure.code" "INCORRECT_ASSERTION"}} +print out failure code: The failure code is an INCORRECT ASSERTION +{{/is_exact_match}} + +{{/if}} +``` + +
For a complete list of API test error codes, see API Testing Errors.
+ +### Send alerts to a specific Slack channel based on failed step + +```shell {{! If a test triggers an alert for browser or mobile tests, loop through each step and find the failed step. If the failed step's description field matches Checkout, notify the recipient }} + {{#is_alert}} {{#each synthetics.attributes.result.steps}} {{#is_match "status" "failed"}} @@ -53,26 +77,28 @@ If the failed step's description field matches Checkout, notify the recipient {{/is_alert}} ``` -**Send alerts to a specific Slack channel based on failed step using a variable shortcut:** +### Send alerts to a specific Slack channel based on failed step using a variable shortcut -```handlebars +```shell {{! -This alert uses the `{{synthetics.failed_step}}` object which is a variable shortcut that points to the relevant step data contained in `{{synthetics.attributes.result.steps}}`. +This alert uses the {{synthetics.failed_step}} object which is a variable shortcut that points to the relevant step data contained in {{synthetics.attributes.result.steps}}. If the test triggers an alert for browser or mobile tests, and if the failed step's description field matches Checkout, notify the recipient. }} + {{#is_alert}} {{#is_match "synthetics.failed_step.description" "Checkout"}}@notify-slack-payments{{/is_match}} {{/is_alert}} ``` -**Set different alert priorities:** +### Set different alert priorities -```handlebars +```shell {{! If a test triggers an alert for a multistep API test, loop through each step and find the failed step. If the step's name matches the staging domain, set the priority to P2. Otherwise, set it to P4. }} -{{#is_alert}}send a message to thang @thang.nguyen@datadoghq.com + +{{#is_alert}}send a message to @example@email.com {{#each synthetics.attributes.result.steps}} {{#is_match "status" "failed"}} {{#is_match "name" "stagedomain"}}Stage domain failed. Overriding priority to P2. @@ -84,11 +110,11 @@ If the step's name matches the staging domain, set the priority to P2. Otherwise {{/is_alert}} ``` -**Set different alert priorities using variable shortcut:** +### Set different alert priorities using variable shortcut -```handlebars +```shell {{! -This alert uses the `{{synthetics.failed_step}}` object which is a variable shortcut that points to the relevant step data contained in `{{synthetics.attributes.result.steps}}`. +This alert uses the {{synthetics.failed_step}} object which is a variable shortcut that points to the relevant step data contained in `{{synthetics.attributes.result.steps}}`. If the test triggers an alert for multistep API test and if the failed step's name field matches the domain, override the priority. }} {{#is_alert}} diff --git a/content/en/synthetics/notifications/template_variables.md b/content/en/synthetics/notifications/template_variables.md index 14f49ae5818..4ba44e7b1bf 100644 --- a/content/en/synthetics/notifications/template_variables.md +++ b/content/en/synthetics/notifications/template_variables.md @@ -45,7 +45,8 @@ Use these variables to access common test execution data such as failure message : The URL of the failed step (for example, `https://www.datadoghq.com/blog/`). `{{synthetics.attributes.result.response.statusCode}}` -: The HTTP status code (for example, `403`). +: The HTTP status code (for example, `403`).
+Tip: Review the conditional alerting page for an example of how to use this variable in a notification. `{{synthetics.result.step_count}}` : Number of steps (for example, `4`). @@ -149,6 +150,8 @@ Applies to Browser and Mobile tests. `{{synthetics.attributes.result.failure.code}}` : The failure code +

For a complete list of API test error codes, see API Testing Errors. Review the conditional alerting page for an example of how to use the synthetics.attributes.result.failure variable in a notification.

+ {{% /tab %}} {{% tab "Count" %}} @@ -175,9 +178,31 @@ Applies to Multistep, Browser, and Mobile tests. Applies to Multistep, Browser, and Mobile tests. `{{synthetics.failed_step}}` -: The `failed_step` object provides a shortcut to the step that caused the test to fail, eliminating the need to reference `{{synthetics.attributes.result.steps.}}` directly. - -For example, `{{synthetics.failed_step.name}}` maps to `{{synthetics.attributes.result.steps..name}}` for Multistep API tests, and to `{{synthetics.attributes.result.steps..description}}` for Browser and Mobile tests. +: The `failed_step` object provides a shortcut to the step that caused the test to fail, eliminating the need to reference `{{synthetics.attributes.result.steps.}}` directly.
+ + + + + + + + + + + + + + + + + + + + + +
ShortcutTest TypeMaps To
{{synthetics.failed_step.name}}Multistep API{{synthetics.attributes.result.steps.<step-index>.name}}
{{synthetics.failed_step.description}}Browser, Mobile{{synthetics.attributes.result.steps.<step-index>.description}}
+ +
Review the conditional alerting page for an example of how to use the synthetics.failed_step.description shortcut variable in a Browser Test notification.
{{% /tab %}} {{< /tabs >}} @@ -623,6 +648,8 @@ Use the step's unique identifier: `.steps.abc-def-ghi` +
Review the conditional alerting page for an example of how to use the synthetics.attributes.result.step variable in a Slack notification based on a failed step.
+ #### Accessing step properties Combine any reference method with a property: @@ -637,3 +664,8 @@ Combine any reference method with a property: [1]: /synthetics/explore/results_explorer [2]: /synthetics/notifications/template_variables/?tab=apitests#step-execution-details +[3]: /synthetics/notifications/conditional_alerting#send-alerts-based-on-an-error-code +[4]: /synthetics/api_tests/errors/ +[5]: /synthetics/notifications/conditional_alerting#send-alerts-based-on-status-code +[6]: /synthetics/notifications/conditional_alerting#send-alerts-to-a-specific-slack-channel-based-on-failed-step +