nautobot / nautobot-app-netbox-importer

Nautobot plugin to simplify data migration from NetBox
https://docs.nautobot.com/projects/netbox-importer/en/latest/
Other
21 stars 11 forks source link

Add support for importing NetBox 2.11.x data #58

Closed bsmeding closed 7 months ago

bsmeding commented 3 years ago

Environment

Proposed Functionality

Get support for an exported json file of Netbox 2.11.x

Use Case

Currently is is not working when setting the version to 2.10.8

(nautobot) nautobot@debian:~$ nautobot-server import_netbox_json netbox_120721.json 2.10.8
05:42:36 info     Loading NetBox JSON data into memory...
  filename: {'netbox_120721.json'}
Traceback (most recent call last):
  File "/opt/nautobot/bin/nautobot-server", line 8, in <module>
    sys.exit(main())
  File "/opt/nautobot/lib/python3.7/site-packages/nautobot/core/cli.py", line 62, in main
    initializer=_configure_settings,  # Called after defaults
  File "/opt/nautobot/lib/python3.7/site-packages/nautobot/core/runner/runner.py", line 266, in run_app
    management.execute_from_command_line([runner_name, command] + command_args)
  File "/opt/nautobot/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/opt/nautobot/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/nautobot/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/nautobot/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/opt/nautobot/lib/python3.7/site-packages/nautobot_netbox_importer/management/commands/import_netbox_json.py", line 40, in handle
    data = json.load(options["json_file"])
  File "/usr/lib/python3.7/json/__init__.py", line 296, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/usr/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.7/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 3016066 (char 3016065)
glennmatthews commented 3 years ago

Thanks for the report!

This doesn't look like with the importer itself; that's Python saying that your NetBox JSON dump isn't a valid JSON file. Can you check the file and make sure it wasn't truncated or something like that?

bsmeding commented 3 years ago

Yes probably you're right, the last characters are null, "tagged_vlans": []}} so it didnt close correct ] Is there a limit on items/devices?

glennmatthews commented 3 years ago

File size shouldn't be a limit, but available RAM can be when running the importer. Can you try re-exporting the data from NetBox?

sklemer1 commented 3 years ago

To get back to the title of this issue -- In order to import 2.11 changes data we had to change the exported json:

jq '[ .[] | if (.fields.postchange_data != null) then .fields.object_data = .fields.postchange_data else .fields.object_data = .fields.prechange_data end | del(.fields.prechange_data, .fields.postchange_data) ]'

This was straight forward according to the changes from netbox 2.10 to 2.11. (just put postchange_data into object_data except for cases where there is no postchange_change (e.g. deletes) where we take it from prechange_data).

But it happened that there were still fields with object_data=null which I cannot explain and just deleted with

`` jq '[ .[] | select(.fields.object_data != null)]'

glennmatthews commented 1 year ago

Adding known NetBox changes that would need to be accommodated for full 2.11 support:

chadell commented 7 months ago

Drop in favor of NetBox 3.x