Provides UI to build custom data validation rules for data in Nautobot
Project description
Nautobot Data Validation Engine Plugin
A plugin for Nautobot with a UI to build custom data validation rules for Source of Truth data.
Usage
The data validation engine plugin offers a set of user definable rules which are used to enforce business constraints on the data in Nautobot. These rules are tied to particular models and each rule is meant to enforce one aspect of a business use case. There are currently two supported rule types, regular expressions, and min/max numeric rules.
Regular Expression Rules
Each rule is defined with these fields:
- name - A unique name for the rule.
- enabled - A boolean to toggle enforcement of the rule on and off.
- content type - The Nautobot model to which the rule should apply (device, site, etc.).
- field - The name of the character based field on the model to which the regular expression is validated.
- regular expression - The body of the regular expression used for validation.
- error message - An optional error message to display to the use when validation fails. By default, a message indicating validation against the defined regular expression has failed is shown.
In this example, a device hostname validation rule has been created and prevents device records from being created or updated that do not conform to the naming standard.
Min/Max Rules
Each rule is defined with these fields:
- name - A unique name for the rule.
- enabled - A boolean to toggle enforcement of the rule on and off.
- content type - The Nautobot model to which the rule should apply (device, site, etc.).
- field - The name of the numeric based field on the model to which the min/max value is validated.
- min - The min value to validate value against (greater than or equal).
- max - The max value to validate value against (less than or equal).
- error message - An optional error message to display to the use when validation fails. By default, a message indicating validation against the defined min/max value has failed is shown.
In this example, a max value for VLAN IDs has been configured, preventing VLANs greater than 3999 from being created.
Installation
If using the installation pattern from the Nautobot Documentation, you will need to activate the virtual environment before installing so that you install the package into the virtual environment.
cd /opt/nautobot
source venv/bin/activate
The plugin is available as a Python package in pypi and can be installed with pip. Once the installation is completed, then Nautobot and the Nautobot worker must be restarted.
pip install nautobot-data-validation-engine
systemctl restart nautobot nautobot-rq
To ensure Data Validation Engine plugin is automatically re-installed during future upgrades, create a file named local_requirements.txt
(if not already existing) in the Nautobot root directory (alongside requirements.txt
) and list the nautobot-data-validation-engine
package:
# echo nautobot-data-validation-engine >> local_requirements.txt
Once installed, the plugin needs to be enabled in your nautobot_config.py
# In your configuration.py
PLUGINS = ["nautobot_data_validation_engine"]
Finally, make sure to run the migrations for this plugin
nautobot-server migrate
Upgrades
When a new release comes out it may be necessary to run a migration of the database to account for any changes in the data models used by this plugin. Execute the command nautobot-server migrate
from the Nautobot install nautobot/
directory after updating the package.
Contributing
Pull requests are welcomed and automatically built and tested against multiple version of Python and multiple version of Nautobot through TravisCI.
The project is packaged with a light development environment based on docker-compose
to help with the local development of the project and to run the tests within TravisCI.
The project is following Network to Code software development guideline and is leveraging:
- Black, Pylint, Bandit and pydocstyle for Python linting and formatting.
- Django unit test to ensure the plugin is working properly.
CLI Helper Commands
The project is coming with a CLI helper based on invoke to help setup the development environment. The commands are listed below in 3 categories dev environment
, utility
and testing
.
Each command can be executed with invoke <command>
. All commands support the arguments --nautobot-ver
and --python-ver
if you want to manually define the version of Python and Nautobot to use. Each command also has its own help invoke <command> --help
Local dev environment
build Build all docker images.
debug Start Nautobot and its dependencies in debug mode.
destroy Destroy all containers and volumes.
start Start Nautobot and its dependencies in detached mode.
stop Stop Nautobot and its dependencies.
Utility
cli Launch a bash shell inside the running Nautobot container.
create-user Create a new user in django (default: admin), will prompt for password.
makemigrations Run Make Migration in Django.
nbshell Launch a nbshell session.
Testing
tests Run all tests for this plugin.
pylint Run pylint code analysis.
pydocstyle Run pydocstyle to validate docstring formatting adheres to NTC defined standards.
bandit Run bandit to validate basic static code security analysis.
black Run black to check that Python files adhere to its style standards.
unittest Run Django unit tests for the plugin.
Questions
For any questions or comments, please check the FAQ first and feel free to swing by the Network to Code slack channel (channel #networktocode). Sign up here
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for nautobot-data-validation-engine-1.0.0.dev0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 588b6277736762bb60d31c5d919401d9b9a25bcc4891391caee97c324b436d64 |
|
MD5 | 8fba43c55e0a69154510f74cebd2b8d7 |
|
BLAKE2b-256 | 1835d058c70b02b634e8fd6590f6790f1fb631e3a2d10a75212316af2448c7d8 |
Hashes for nautobot_data_validation_engine-1.0.0.dev0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbf9d0406755fbc73f5415649158df05b166c57500b8a81ff284994178ae45cf |
|
MD5 | dbfb11f51ecc7281eeefa98bee2ac883 |
|
BLAKE2b-256 | 51b958ac0b56971f75ef546dc41e5197ade30dcd1c76a88150a8a72002cc0aad |