Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
ee913e1
14132 change_logging -> event_logging
arthanson Oct 27, 2023
3b5c682
14132 event_logging -> event_wrapper
arthanson Oct 27, 2023
4b3b88f
14132 webhooks_queue -> events_queue
arthanson Oct 27, 2023
9148029
14132 flush_webhooks -> flush_events
arthanson Oct 27, 2023
38d46af
14132 add models and forms
arthanson Oct 30, 2023
498ac5e
14132 fixes
arthanson Oct 30, 2023
1cc8a82
14132 model changes
arthanson Oct 31, 2023
e6f048b
14132 remove fields from Webhook model, consolidate migrations
arthanson Oct 31, 2023
854b3ba
14132 cleanup tables and detail views
arthanson Oct 31, 2023
e0b10c9
14132 form cleanup
arthanson Oct 31, 2023
f650f88
14132 api / graphql
arthanson Oct 31, 2023
5ca30fe
14132 restore webhook name
arthanson Oct 31, 2023
4ef7ab8
14132 update table
arthanson Oct 31, 2023
e74fb89
14132 base process_event
arthanson Oct 31, 2023
aa8ed11
14132 fix
arthanson Nov 1, 2023
36285db
14132 fix
arthanson Nov 1, 2023
4a94177
14132 fix
arthanson Nov 1, 2023
7770637
14132 fix event and webhook worker
arthanson Nov 1, 2023
7cb704d
14132 fix webhook_worker
arthanson Nov 1, 2023
9c20432
14132 misc changes
arthanson Nov 8, 2023
4f3b086
Merge branch 'feature' into 14132-event-refactor-2
arthanson Nov 9, 2023
a679740
8356 htmx
arthanson Nov 9, 2023
73047c9
8356 action_object_type cleanup migration
arthanson Nov 9, 2023
1453419
8356 fix form, init fields
arthanson Nov 9, 2023
7fae20c
8356 fix tests
arthanson Nov 9, 2023
5686b96
8356 fix tests
arthanson Nov 10, 2023
005010e
8356 fix tests
arthanson Nov 10, 2023
a43cbcb
8356 fix tests
arthanson Nov 13, 2023
4956203
14132 fix tests
arthanson Nov 13, 2023
f5615e5
14132 fix tests
arthanson Nov 13, 2023
3dbdd47
14132 script run fixup
arthanson Nov 13, 2023
48ed7cc
14132 fix runscript
arthanson Nov 14, 2023
179564d
14132 remove breakpoint
arthanson Nov 14, 2023
90cf3c8
14132 refactor pipeline code
arthanson Nov 14, 2023
6e7afd1
14132 fix test
arthanson Nov 14, 2023
04866b4
14132 fix test
arthanson Nov 15, 2023
a2f5427
14132 fix test
arthanson Nov 15, 2023
12b4bf8
14132 optimize flush_events
arthanson Nov 15, 2023
58136de
Misc cleanup
jeremystretch Nov 15, 2023
e995045
14132 review changes
arthanson Nov 16, 2023
7a50706
Merge branch 'feature' into 14132-event-refactor-2
arthanson Nov 16, 2023
dcb6483
14132 review changes
arthanson Nov 16, 2023
bcf477a
14132 review changes and fix feature merge conflicts
arthanson Nov 16, 2023
ca0a567
14132 fix imports
arthanson Nov 16, 2023
22c11c8
14132 add description, comments fields
arthanson Nov 16, 2023
bcb38d2
14132 form fixes
arthanson Nov 16, 2023
d0a2529
14132 form fixes
arthanson Nov 16, 2023
e9e0791
14132 form fixes
arthanson Nov 16, 2023
3381983
14132 fix script event for user
arthanson Nov 17, 2023
ed203b1
14132 fix form field util
arthanson Nov 17, 2023
1d7aace
14132 add documentation
arthanson Nov 17, 2023
488f0c5
14132 fix JSON field issue
arthanson Nov 17, 2023
5b40220
Misc cleanup
jeremystretch Nov 20, 2023
bfc9a23
Merge branch 'feature' into 14132-event-refactor-2
arthanson Nov 20, 2023
b3a7022
14132 review changes
arthanson Nov 20, 2023
56a9210
14132 review changes
arthanson Nov 21, 2023
7eb5371
14132 review changes fix tests
arthanson Nov 21, 2023
568a5b8
14132 change action_parameters to jsonfield
arthanson Nov 21, 2023
ef29343
Merge branch 'feature' into 14132-event-refactor-2
arthanson Nov 21, 2023
5266109
14132 fix merge
arthanson Nov 21, 2023
d6cc025
14132 review change
arthanson Nov 21, 2023
245465a
14132 re-add migration
arthanson Nov 21, 2023
9c32a68
14132 fix serializer
arthanson Nov 21, 2023
92ab4a0
14132 fix serializer
arthanson Nov 21, 2023
bbd008e
14132 add payload_url to webhook filterset
arthanson Nov 21, 2023
d14e868
Add action_object field to EventRuleSerializer
jeremystretch Nov 27, 2023
e34eff2
Select RQ queue based on action object type
jeremystretch Nov 27, 2023
0066eed
Use Django's import_string() to reference pipeline functions
jeremystretch Nov 27, 2023
bf11f1d
Extend filterset forms
jeremystretch Nov 27, 2023
f860345
Misc cleanup
jeremystretch Nov 27, 2023
267b5a1
Rename WebhooksMixin to EventRulesMixin
jeremystretch Nov 28, 2023
43eef0e
Rename webhooks key for model_features registry key to event_rules
jeremystretch Nov 28, 2023
f68b812
Rename clear_webhooks signal to clear_events
jeremystretch Nov 28, 2023
0824fdd
Clean up docs
jeremystretch Nov 28, 2023
cd8eb7b
Merge branch 'feature' into 14132-event-refactor-2
jeremystretch Nov 28, 2023
4c331f5
14132 review change
arthanson Nov 28, 2023
92d9e86
14132 filterset test
arthanson Nov 28, 2023
6549dce
14132 fix api tests
arthanson Nov 28, 2023
3e4821e
14132 fix api tests
arthanson Nov 28, 2023
7b409b9
14132 merge test_webhooks
arthanson Nov 28, 2023
f880b8f
14132 test_filtersets
arthanson Nov 29, 2023
afc1e78
Clean up filterset tests
jeremystretch Nov 29, 2023
bce43ea
Add action_object to EventRule serializer
jeremystretch Nov 29, 2023
2252c8b
Clean up API tests
jeremystretch Nov 29, 2023
12b4c48
14132 fix bulk import
arthanson Nov 29, 2023
7b0d683
14132 test_views
arthanson Nov 29, 2023
57d454f
14132 test_views
arthanson Nov 29, 2023
6d28cac
14132 nested serializer
arthanson Nov 29, 2023
c26e7c7
14132 nested serializer
arthanson Nov 29, 2023
a8b4578
14132 nested serializer
arthanson Nov 29, 2023
3c78047
14132 nested serializer
arthanson Nov 29, 2023
1085458
14132 add script_full_name
arthanson Nov 29, 2023
a16d722
14132 nested serializer
arthanson Nov 29, 2023
5d2ada3
14132 update paramaters
arthanson Nov 29, 2023
68d380a
14132 update paramaters
arthanson Nov 30, 2023
593b869
14132 fix csv import
arthanson Nov 30, 2023
e1c7a03
14132 fix csv import
arthanson Nov 30, 2023
cdea113
Merge branch 'feature' into 14132-event-refactor-2
jeremystretch Nov 30, 2023
4811c54
14132 fix test
arthanson Nov 30, 2023
78c2dba
14132 fix test
arthanson Nov 30, 2023
c45bdf4
Misc cleanup
jeremystretch Nov 30, 2023
a9b4a81
Optimize script jobs by skipping the intermediate event task
jeremystretch Nov 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions docs/configuration/required-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ DATABASE = {

## REDIS

[Redis](https://redis.io/) is an in-memory data store similar to memcached. While Redis has been an optional component of
NetBox since the introduction of webhooks in version 2.4, it is required starting in 2.6 to support NetBox's caching
functionality (as well as other planned features). In 2.7, the connection settings were broken down into two sections for
task queuing and caching, allowing the user to connect to different Redis instances/databases per feature.
[Redis](https://redis.io/) is a lightweight in-memory data store similar to memcached. NetBox employs Redis for background task queuing and other features.

Redis is configured using a configuration setting similar to `DATABASE` and these settings are the same for both of the `tasks` and `caching` subsections:

Expand All @@ -81,15 +78,15 @@ REDIS = {
'tasks': {
'HOST': 'redis.example.com',
'PORT': 1234,
'USERNAME': 'netbox'
'USERNAME': 'netbox',
'PASSWORD': 'foobar',
'DATABASE': 0,
'SSL': False,
},
'caching': {
'HOST': 'localhost',
'PORT': 6379,
'USERNAME': ''
'USERNAME': '',
'PASSWORD': '',
'DATABASE': 1,
'SSL': False,
Expand Down
2 changes: 1 addition & 1 deletion docs/development/application-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ A dictionary of particular features (e.g. custom fields) mapped to the NetBox mo
'dcim': ['site', 'rack', 'devicetype', ...],
...
},
'webhooks': {
'event_rules': {
'extras': ['configcontext', 'tag', ...],
'dcim': ['site', 'rack', 'devicetype', ...],
},
Expand Down
28 changes: 14 additions & 14 deletions docs/development/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ The Django [content types](https://docs.djangoproject.com/en/stable/ref/contrib/

Depending on its classification, each NetBox model may support various features which enhance its operation. Each feature is enabled by inheriting from its designated mixin class, and some features also make use of the [application registry](./application-registry.md#model_features).

| Feature | Feature Mixin | Registry Key | Description |
|------------------------------------------------------------|-------------------------|--------------------|--------------------------------------------------------------------------------|
| [Change logging](../features/change-logging.md) | `ChangeLoggingMixin` | - | Changes to these objects are automatically recorded in the change log |
| Cloning | `CloningMixin` | - | Provides the `clone()` method to prepare a copy |
| [Custom fields](../customization/custom-fields.md) | `CustomFieldsMixin` | `custom_fields` | These models support the addition of user-defined fields |
| [Custom links](../customization/custom-links.md) | `CustomLinksMixin` | `custom_links` | These models support the assignment of custom links |
| [Custom validation](../customization/custom-validation.md) | `CustomValidationMixin` | - | Supports the enforcement of custom validation rules |
| [Export templates](../customization/export-templates.md) | `ExportTemplatesMixin` | `export_templates` | Users can create custom export templates for these models |
| [Job results](../features/background-jobs.md) | `JobsMixin` | `jobs` | Users can create custom export templates for these models |
| [Journaling](../features/journaling.md) | `JournalingMixin` | `journaling` | These models support persistent historical commentary |
| [Synchronized data](../integrations/synchronized-data.md) | `SyncedDataMixin` | `synced_data` | Certain model data can be automatically synchronized from a remote data source |
| [Tagging](../models/extras/tag.md) | `TagsMixin` | `tags` | The models can be tagged with user-defined tags |
| [Webhooks](../integrations/webhooks.md) | `WebhooksMixin` | `webhooks` | NetBox is capable of generating outgoing webhooks for these objects |
| Feature | Feature Mixin | Registry Key | Description |
|------------------------------------------------------------|-------------------------|--------------------|-----------------------------------------------------------------------------------------|
| [Change logging](../features/change-logging.md) | `ChangeLoggingMixin` | - | Changes to these objects are automatically recorded in the change log |
| Cloning | `CloningMixin` | - | Provides the `clone()` method to prepare a copy |
| [Custom fields](../customization/custom-fields.md) | `CustomFieldsMixin` | `custom_fields` | These models support the addition of user-defined fields |
| [Custom links](../customization/custom-links.md) | `CustomLinksMixin` | `custom_links` | These models support the assignment of custom links |
| [Custom validation](../customization/custom-validation.md) | `CustomValidationMixin` | - | Supports the enforcement of custom validation rules |
| [Export templates](../customization/export-templates.md) | `ExportTemplatesMixin` | `export_templates` | Users can create custom export templates for these models |
| [Job results](../features/background-jobs.md) | `JobsMixin` | `jobs` | Users can create custom export templates for these models |
| [Journaling](../features/journaling.md) | `JournalingMixin` | `journaling` | These models support persistent historical commentary |
| [Synchronized data](../integrations/synchronized-data.md) | `SyncedDataMixin` | `synced_data` | Certain model data can be automatically synchronized from a remote data source |
| [Tagging](../models/extras/tag.md) | `TagsMixin` | `tags` | The models can be tagged with user-defined tags |
| [Event rules](../features/event-rules.md) | `EventRulesMixin` | `event_rules` | Event rules can send webhooks or run custom scripts automatically in response to events |

## Models Index

Expand Down Expand Up @@ -111,7 +111,7 @@ Component models represent individual physical or virtual components belonging t

### Component Template Models

These function as templates to effect the replication of device and virtual machine components. Component template models support a limited feature set, including change logging, custom validation, and webhooks.
These function as templates to effect the replication of device and virtual machine components. Component template models support a limited feature set, including change logging, custom validation, and event rules.

* [dcim.ConsolePortTemplate](../models/dcim/consoleporttemplate.md)
* [dcim.ConsoleServerPortTemplate](../models/dcim/consoleserverporttemplate.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/features/api-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ To learn more about this feature, check out the [GraphQL API documentation](../i

## Webhooks

A webhook is a mechanism for conveying to some external system a change that took place in NetBox. For example, you may want to notify a monitoring system whenever the status of a device is updated in NetBox. This can be done by creating a webhook for the device model in NetBox and identifying the webhook receiver. When NetBox detects a change to a device, an HTTP request containing the details of the change and who made it be sent to the specified receiver. Webhooks are an excellent mechanism for building event-based automation processes.
A webhook is a mechanism for conveying to some external system a change that has taken place in NetBox. For example, you may want to notify a monitoring system whenever the status of a device is updated in NetBox. To do this, first create a [webhook](../models/extras/webhook.md) identifying the remote receiver (URL), HTTP method, and any other necessary parameters. Then, define an [event rule](../models/extras/eventrule.md) which is triggered by device changes to transmit the webhook.

To learn more about this feature, check out the [webhooks documentation](../integrations/webhooks.md).
When NetBox detects a change to a device, an HTTP request containing the details of the change and who made it be sent to the specified receiver. Webhooks are an excellent mechanism for building event-based automation processes. To learn more about this feature, check out the [webhooks documentation](../integrations/webhooks.md).

## Prometheus Metrics

Expand Down
31 changes: 31 additions & 0 deletions docs/features/event-rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Event Rules

NetBox includes the ability to execute certain functions in response to internal object changes. These include:

* [Scripts](../customization/custom-scripts.md) execution
* [Webhooks](../integrations/webhooks.md) execution

For example, suppose you want to automatically configure a monitoring system to start monitoring a device when its operational status is changed to active, and remove it from monitoring for any other status. You can create a webhook in NetBox for the device model and craft its content and destination URL to effect the desired change on the receiving system. You can then associate an event rule with this webhook and the webhook will be sent automatically by NetBox whenever the configured constraints are met.

Each event must be associated with at least one NetBox object type and at least one event (e.g. create, update, or delete).

## Conditional Event Rules

An event rule may include a set of conditional logic expressed in JSON used to control whether an event triggers for a specific object. For example, you may wish to trigger an event 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).

## Event Rule Processing

When a change is detected, any resulting events are placed into a Redis queue for processing. This allows the user's request to complete without needing to wait for the outgoing event(s) to be processed. The events are then extracted from the queue by the `rqworker` process. The current event queue and any failed events can be inspected in the admin UI under System > Background Tasks.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ In addition to its expansive and robust data model, NetBox offers myriad mechani
* Custom fields
* Custom model validation
* Export templates
* Webhooks
* Event rules
* Plugins
* REST & GraphQL APIs

Expand Down
24 changes: 4 additions & 20 deletions docs/integrations/webhooks.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Webhooks

NetBox can be configured to transmit outgoing webhooks to remote systems in response to internal object changes. The receiver can act on the data in these webhook messages to perform related tasks.
NetBox can be configured via [Event Rules](../features/event-rules.md) to transmit outgoing webhooks to remote systems in response to internal object changes. The receiver can act on the data in these webhook messages to perform related tasks.

For example, suppose you want to automatically configure a monitoring system to start monitoring a device when its operational status is changed to active, and remove it from monitoring for any other status. You can create a webhook in NetBox for the device model and craft its content and destination URL to effect the desired change on the receiving system. Webhooks will be sent automatically by NetBox whenever the configured constraints are met.

Each webhook must be associated with at least one NetBox object type and at least one event (create, update, or delete). Users can specify the receiver URL, HTTP request type (`GET`, `POST`, etc.), content type, and headers. A request body can also be specified; if left blank, this will default to a serialized representation of the affected object.

!!! warning "Security Notice"
Webhooks support the inclusion of user-submitted code to generate the URL, custom headers, and payloads, which may pose security risks under certain conditions. Only grant permission to create or modify webhooks to trusted users.

Expand Down Expand Up @@ -70,26 +68,12 @@ 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
{
"and": [
{
"attr": "status.value",
"value": "active"
}
]
}
```

For more detail, see the reference documentation for NetBox's [conditional logic](../reference/conditions.md).
!!! note
The setting of conditional webhooks has been moved to [Event Rules](../features/event-rules.md) since NetBox 3.7

## 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.
Using [Event Rules](../features/event-rules.md), 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.

A request is considered successful if the response has a 2XX status code; otherwise, the request is marked as having failed. Failed requests may be retried manually via the admin UI.

Expand Down
35 changes: 35 additions & 0 deletions docs/models/extras/eventrule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# EventRule

An event rule is a mechanism for automatically taking an action (such as running a script or sending a webhook) in response to an event in NetBox. For example, you may want to notify a monitoring system whenever the status of a device is updated in NetBox. This can be done by creating an event for device objects and designating a webhook to be transmitted. When NetBox detects a change to a device, an HTTP request containing the details of the change and who made it be sent to the specified receiver.

See the [event rules documentation](../features/event-rules.md) for more information.

## Fields

### Name

A unique human-friendly name.

### Content Types

The type(s) of object in NetBox that will trigger the rule.

### Enabled

If not selected, the event rule will not be processed.

### Events

The events which will trigger the rule. At least one event type must be selected.

| Name | Description |
|------------|--------------------------------------|
| Creations | A new object has been created |
| Updates | An existing object has been modified |
| Deletions | An object has been deleted |
| Job starts | A job for an object starts |
| Job ends | A job for an object terminates |

### Conditions

A set of [prescribed conditions](../../reference/conditions.md) against which the triggering object will be evaluated. If the conditions are defined but not met by the object, no action will be taken. An event rule that does not define any conditions will _always_ trigger.
7 changes: 5 additions & 2 deletions docs/plugins/development/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,17 @@ For more information about database migrations, see the [Django documentation](h

::: netbox.models.features.CustomValidationMixin

::: netbox.models.features.EventRulesMixin

!!! note
`EventRulesMixin` was renamed from `WebhooksMixin` in NetBox v3.7.

::: netbox.models.features.ExportTemplatesMixin

::: netbox.models.features.JournalingMixin

::: netbox.models.features.TagsMixin

::: netbox.models.features.WebhooksMixin

## Choice Sets

For model fields which support the selection of one or more values from a predefined list of choices, NetBox provides the `ChoiceSet` utility class. This can be used in place of a regular choices tuple to provide enhanced functionality, namely dynamic configuration and colorization. (See [Django's documentation](https://docs.djangoproject.com/en/stable/ref/models/fields/#choices) on the `choices` parameter for supported model fields.)
Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ nav:
- Auth & Permissions: 'features/authentication-permissions.md'
- API & Integration: 'features/api-integration.md'
- Customization: 'features/customization.md'
- Event Rules: 'features/event-rules.md'
- Installation & Upgrade:
- Installing NetBox: 'installation/index.md'
- 1. PostgreSQL: 'installation/1-postgresql.md'
Expand Down Expand Up @@ -215,6 +216,7 @@ nav:
- CustomField: 'models/extras/customfield.md'
- CustomFieldChoiceSet: 'models/extras/customfieldchoiceset.md'
- CustomLink: 'models/extras/customlink.md'
- EventRule: 'models/extras/eventrule.md'
- ExportTemplate: 'models/extras/exporttemplate.md'
- ImageAttachment: 'models/extras/imageattachment.md'
- JournalEntry: 'models/extras/journalentry.md'
Expand Down
2 changes: 1 addition & 1 deletion netbox/core/models/contenttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def with_feature(self, feature):
Return the ContentTypes only for models which are registered as supporting the specified feature. For example,
we can find all ContentTypes for models which support webhooks with

ContentType.objects.with_feature('webhooks')
ContentType.objects.with_feature('event_rules')
"""
if feature not in registry['model_features']:
raise KeyError(
Expand Down
Loading