Alef-Burzmali / netbox-data-flows

NetBox plugin to document data flows between systems and applications.
https://pypi.org/project/netbox-data-flows/
Apache License 2.0
47 stars 8 forks source link

Port range are not saved with hyphen character #43

Closed ugoleleux closed 1 month ago

ugoleleux commented 1 month ago

Hello,

I am facing a strange behaviour, When I choose to register a source or a destination range of port using hyphen caracter image it is well saved with the same format image but when I go to edit it once again, the hyphen as been replaced by each ports in the range coma separated image I can save and the UI is still showing a range of ports, but I think it will be difficult to handle when I will enter a range of thousand of ports.

I am also confused with the export format which is natively a square bracket list image This format is not the same as any other netbox fields therefore I can't import it without removing the brackets in the first time

Thank you for reading my issue which is more a improvement suggestion.

Regards Ugo

Alef-Burzmali commented 1 month ago

Hi. Thanks for the report, I've had a lot of trouble making that field work, but now I see that NetBox's Service forms behave better. I will see what I can do for the next release.

Alef-Burzmali commented 1 month ago

NetBox's services have exactly the same issue, but they are usually used with far fewer ports. I've overridden upstream's NumericArrayField to display the ranges in edit forms.

What tool are you using for your export? This is neither the native export to CSV nor what the API returns (an array of int, not a string), so I can't help you there.

ugoleleux commented 1 month ago

NetBox's services have exactly the same issue, but they are usually used with far fewer ports. I've overridden upstream's NumericArrayField to display the ranges in edit forms.

What tool are you using for your export? This is neither the native export to CSV nor what the API returns (an array of int, not a string), so I can't help you there.

Hi, thank you for your replies. For the export, I use a custom export template in jinja2

[{% for object in queryset %}
{
  "id":"{{object.id}}",
  "name":"{{object.name}}",
  "status":"{{object.status}}",
  "protocol":"{{object.protocol}}",
  "application":"{{object.application}}",
  "source_ports":"{{object.source_ports}}",
  "destination_ports":"{{object.destination_ports}}",
  "sources":"{% for source in object.sources.all() %}{{ source.name }}{{ "," if not loop.last }}{% endfor %}",
  "destinations":"{% for destination in object.destinations.all() %}{{ destination.name }}{{ "," if not loop.last }}{% endfor %}",
  "description":"{{object.description}}",
  "comments":"{{object.comments}}",
  "tags":"{% for tag in object.tags.all() %}{{ tag.slug }}{{ "," if not loop.last }}{% endfor %}"
},
{% endfor %}]
Alef-Burzmali commented 1 month ago

Hi, Ah, I see. Then, two easy options for the moment:

If you want a better support for that use case, please make a separate issue. I'll close that issue as the form prefilling is fixed.

ugoleleux commented 1 month ago

Thank you very much for the hint. I followed you advice and I removed the "" in the jinja template :

  "source_ports": {{object.source_ports}},
  "destination_ports": {{object.destination_ports}},

And i can reimport data without any problem now.

Thanks again for your help.

Regards Ugo