TheNetworkGuy / netbox-zabbix-sync

Python script to synchronise Netbox devices to Zabbix.
MIT License
123 stars 29 forks source link

Compatibility with Netbox 4 #57

Closed ivlru closed 4 months ago

ivlru commented 4 months ago

Hello,

I tested your sync tool with netbox-3.7.1 and it works well, but after upgrade to netbox-4.0.2 there such error:

Traceback (most recent call last): File "/root/netbox-zabbix-sync/netbox_zabbix_sync.py", line 975, in main(args) File "/root/netbox-zabbix-sync/netbox_zabbix_sync.py", line 158, in main device.set_hostgroup(hostgroup_format,netbox_site_groups,netbox_regions) File "/root/netbox-zabbix-sync/netbox_zabbix_sync.py", line 299, in set_hostgroup dev_role = self.nb.device_role.name File "/opt/netbox-4.0.2/venv/lib/python3.10/site-packages/pynetbox/core/response.py", line 308, in getattr raise AttributeError('object has no attribute "{}"'.format(k)) AttributeError: object has no attribute "device_role". Did you mean: 'device_type'?

Please help. Thank you!

TheNetworkGuy commented 4 months ago

Thanks for reporting this issue. I'll look into it.

TheNetworkGuy commented 4 months ago

Reproducible.

Traceback (most recent call last):
  File "C:\Data\netbox-zabbix-sync\netbox_zabbix_sync.py", line 975, in <module>
    main(args)
  File "C:\Data\netbox-zabbix-sync\netbox_zabbix_sync.py", line 158, in main
    device.set_hostgroup(hostgroup_format,netbox_site_groups,netbox_regions)
  File "C:\Data\netbox-zabbix-sync\netbox_zabbix_sync.py", line 299, in set_hostgroup
    dev_role = self.nb.device_role.name
               ^^^^^^^^^^^^^^^^^^^
  File "C:\Data\netbox-zabbix-sync\venv\Lib\site-packages\pynetbox\core\response.py", line 308, in __getattr__
    raise AttributeError('object has no attribute "{}"'.format(k))
AttributeError: object has no attribute "device_role". Did you mean: 'device_type'?

Seems like i missed this one in the release notes of 3.6.

The device_role field on the Device model has been renamed to role. The device_role field has been temporarily retained on the REST API serializer for devices for backward compatibility, but is read-only.

More info here

I'll implement some kind of fix that will check the Netbox version.

ivlru commented 4 months ago

I confirm now it works, Thank you!