Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support JSON custom fields #2196

Closed
wrouesnel opened this issue Jun 25, 2018 · 3 comments
Closed

Support JSON custom fields #2196

wrouesnel opened this issue Jun 25, 2018 · 3 comments

Comments

@wrouesnel
Copy link

Issue type

[x] Feature request
[ ] Bug report
[ ] Documentation

Environment

  • Python version: 3.6.4
  • NetBox version: 2.3.4

Description

To integrate Netbox with external systems more reliably, we would like to be able to store JSON structured data against objects with custom fields.

For our use case this is to support marking up our devices, IPs and networks which additional data to support custom tooling and to match metadata which maps to other systems.

To implement this, the proposal would be to add a "structured_data" field to the CustomFieldValue model, and a new CF_TYPE_JSON type for custom fields. CustomField's with JSON data would return the structured_data value rather then a deserialized value, which in the underlying database would be stored as a postgres JSONB type via the Django postgres JSON field.

To support data consistency, two additional fields for the CustomField would be added - json_schema as JSON and validate_json (a bool) to allow enforcing the structure of added JSON and using the django-jsonforms module to generate rich user frontends for custom fields in the UI. django-json-widget can be used to support free editing of schemas in the admin interface.

An early version of this proposal is already implemented here: https://github.com/wrouesnel/netbox/tree/json_custom_fields, the django-jsonforms requires some CSS work to fit nicely into the UI.

@DanSheps
Copy link
Member

#1349

@alxnet
Copy link

alxnet commented Jun 28, 2018

Hi, I've been thinking about migrating to netbox, but the tooling we use relies on JSON custom fields. I've been following the discussion on #1349 but as far as I could understand it has a different scope. In our case, we'd rather merge the context ourselves. Besides, some fields do not directly relate to configuration information, so we just need a placeholder for the json data and the ability to index and query it efficiently. I'm very new to netbox and I found it amazing to see this early implementation. Btw, what if instead of serialized_value we had a json_value to unify the custom field representation?

netbox=# select json_value,jsonb_typeof(json_value) from extras_customfieldvalue;
                          json_value                           | jsonb_typeof 
---------------------------------------------------------------+--------------
 {"employee": {"age": 30, "city": "New York", "name": "John"}} | object
 "my project"                                                  | string
 false                                                         | boolean
 10102                                                         | number

@jeremystretch
Copy link
Member

Custom fields are not intended to store large amounts of data. Values are limited to 255 characters. #1349 will introduce config contexts in v2.4, which will support arbitrary data in JSON formats applied to a set of device/VMs (categorized by site, role, etc.). However, the attachment of arbitrary free-form data to individual objects is out of scope for NetBox.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants