From 4b81d86311e80c055bd5a8b1ad55b2472ebc69e8 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Jan 2022 11:31:39 -0500 Subject: [PATCH] Closes #8376: Correct example condition defitinions; call out value vs label ealuation for choice fields --- docs/additional-features/webhooks.md | 17 +++++++++++++++++ docs/models/extras/webhook.md | 13 ------------- docs/reference/conditions.md | 7 +++++-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/additional-features/webhooks.md b/docs/additional-features/webhooks.md index 3f10cb9e6..5077f3a68 100644 --- a/docs/additional-features/webhooks.md +++ b/docs/additional-features/webhooks.md @@ -1,5 +1,22 @@ {!models/extras/webhook.md!} +## Conditional Webhooks + +A webhook may include a set of conditional logic expressed in JSON used to control whether a webhook triggers for a specific object. For example, you may wish to trigger a webhook for devices only when the `status` field of an object is "active": + +```json +{ + "and": [ + { + "attr": "status.value", + "value": "active" + } + ] +} +``` + +For more detail, see the reference documentation for NetBox's [conditional logic](../reference/conditions.md). + ## Webhook Processing When a change is detected, any resulting webhooks are placed into a Redis queue for processing. This allows the user's request to complete without needing to wait for the outgoing webhook(s) to be processed. The webhooks are then extracted from the queue by the `rqworker` process and HTTP requests are sent to their respective destinations. The current webhook queue and any failed webhooks can be inspected in the admin UI under System > Background Tasks. diff --git a/docs/models/extras/webhook.md b/docs/models/extras/webhook.md index c71657336..eb47dd332 100644 --- a/docs/models/extras/webhook.md +++ b/docs/models/extras/webhook.md @@ -81,16 +81,3 @@ If no body template is specified, the request body will be populated with a JSON } } ``` - -## Conditional Webhooks - -A webhook may include a set of conditional logic expressed in JSON used to control whether a webhook triggers for a specific object. For example, you may wish to trigger a webhook for devices only when the `status` field of an object is "active": - -```json -{ - "attr": "status", - "value": "active" -} -``` - -For more detail, see the reference documentation for NetBox's [conditional logic](../reference/conditions.md). diff --git a/docs/reference/conditions.md b/docs/reference/conditions.md index 40b2ccb4b..fb8b66139 100644 --- a/docs/reference/conditions.md +++ b/docs/reference/conditions.md @@ -81,13 +81,16 @@ The following condition will evaluate as true: ```json { - "attr": "status", + "attr": "status.value", "value": ["planned", "staging"], "op": "in", "negate": true } ``` +!!! note "Evaluating static choice fields" + Pay close attention when evaluating static choice fields, such as the `status` field above. These fields typically render as a dictionary specifying both the field's raw value (`value`) and its human-friendly label (`label`). be sure to specify on which of these you want to match. + ## Condition Sets Multiple conditions can be combined into nested sets using AND or OR logic. This is done by declaring a JSON object with a single key (`and` or `or`) containing a list of condition objects and/or child condition sets. @@ -102,7 +105,7 @@ Multiple conditions can be combined into nested sets using AND or OR logic. This { "and": [ { - "attr": "status", + "attr": "status.value", "value": "active" }, {