mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
90 lines
2.0 KiB
Markdown
90 lines
2.0 KiB
Markdown
|
# Conditions
|
||
|
|
||
|
Conditions are NetBox's mechanism for evaluating whether a set data meets a prescribed set of conditions. It allows the author to convey simple logic by declaring an arbitrary number of attribute-value-operation tuples nested within a hierarchy of logical AND and OR statements.
|
||
|
|
||
|
## Conditions
|
||
|
|
||
|
A condition is expressed as a JSON object with the following keys:
|
||
|
|
||
|
| Key name | Required | Default | Description |
|
||
|
|----------|----------|---------|-------------|
|
||
|
| attr | Yes | - | Name of the key within the data being evaluated |
|
||
|
| value | Yes | - | The reference value to which the given data will be compared |
|
||
|
| op | No | `eq` | The logical operation to be performed |
|
||
|
| negate | No | False | Negate (invert) the result of the condition's evaluation |
|
||
|
|
||
|
### Available Operations
|
||
|
|
||
|
* `eq`: Equals
|
||
|
* `gt`: Greater than
|
||
|
* `gte`: Greater than or equal to
|
||
|
* `lt`: Less than
|
||
|
* `lte`: Less than or equal to
|
||
|
* `in`: Is present within a list of values
|
||
|
* `contains`: Contains the specified value
|
||
|
|
||
|
### Examples
|
||
|
|
||
|
`name` equals "foobar":
|
||
|
|
||
|
```json
|
||
|
{
|
||
|
"attr": "name",
|
||
|
"value": "foobar"
|
||
|
}
|
||
|
```
|
||
|
|
||
|
`asn` is greater than 65000:
|
||
|
|
||
|
```json
|
||
|
{
|
||
|
"attr": "asn",
|
||
|
"value": 65000,
|
||
|
"op": "gt"
|
||
|
}
|
||
|
```
|
||
|
|
||
|
`status` is not "planned" or "staging":
|
||
|
|
||
|
```json
|
||
|
{
|
||
|
"attr": "status",
|
||
|
"value": ["planned", "staging"],
|
||
|
"op": "in",
|
||
|
"negate": true
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## 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.
|
||
|
|
||
|
### Examples
|
||
|
|
||
|
`status` is "active" and `primary_ip` is defined _or_ the "exempt" tag is applied.
|
||
|
|
||
|
```json
|
||
|
{
|
||
|
"or": [
|
||
|
{
|
||
|
"and": [
|
||
|
{
|
||
|
"attr": "status",
|
||
|
"value": "active"
|
||
|
},
|
||
|
{
|
||
|
"attr": "primary_ip",
|
||
|
"value": "",
|
||
|
"negate": true
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"attr": "tags",
|
||
|
"value": "exempt",
|
||
|
"op": "contains"
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
```
|