TheNetworkGuy / netbox-zabbix-sync

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

netbox v4.0.6 #67

Closed patricklind closed 3 months ago

patricklind commented 3 months ago

Can you make a quick fix ?

Traceback (most recent call last): File "/opt/apps/netbox-zabbix-sync/netbox_zabbix_sync.py", line 200, in main(args) File "/opt/apps/netbox-zabbix-sync/netbox_zabbix_sync.py", line 127, in main nb_version = netbox.version ^^^^^^^^^^^^^^ File "/opt/apps/netbox-zabbix-sync/.venv/lib/python3.11/site-packages/pynetbox/core/api.py", line 113, in version ).get_version() ^^^^^^^^^^^^^ File "/opt/apps/netbox-zabbix-sync/.venv/lib/python3.11/site-packages/pynetbox/core/query.py", line 198, in get_version raise RequestError(req) pynetbox.core.query.RequestError: The request failed with code 403 Forbidden: {'detail': 'Authentication credentials were not provided.'}

patricklind commented 3 months ago

https://github.com/netbox-community/pynetbox/issues/612

TheNetworkGuy commented 3 months ago

Hmm i'll take a look at this. Seems like i missed some stuff in the pynetbox dependancy

patricklind commented 3 months ago

Hmm i'll take a look at this. Seems like i missed some stuff in the pynetbox dependancy

it is.

my quick fix is:

LOGIN_REQUIRED=false

TheNetworkGuy commented 3 months ago

So i did some digging and i have the following 2 points:

First off i think that an underlying issue of this script (in this case a bug in the pynetbox library) should be handled by the pynetbox team. It does not make sense to implement bug fixes all over the place while a simple fix upstream would fix the issue for all dependend projects.

Secondly i am able to reproduce the error using the config LOGIN_REQUIRED=True:

Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from pynetbox import api
>>> from os import environ
>>>
>>> netbox_host = environ.get("NETBOX_HOST")
>>> netbox_token = environ.get("NETBOX_TOKEN")
>>> netbox = api(netbox_host, token=netbox_token, threading=True)
>>>
>>> nb_version = netbox.version
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Data\venv\Lib\site-packages\pynetbox\core\api.py", line 113, in version
    ).get_version()
      ^^^^^^^^^^^^^
  File "C:\Data\venv\Lib\site-packages\pynetbox\core\query.py", line 198, in get_version
    raise RequestError(req)
pynetbox.core.query.RequestError: The request failed with code 403 Forbidden: {'detail': 'Authentication credentials were not provided.'}

Dependencies: Python 3.12.4 pynetbox 7.3.3 Netbox 4.0.6 Latest release of the sync script (git pull)

I'll push this information to the provided issue that you did mention. I would recommend for you to do the same and if you need the setup to work ASAP then i would recommend adjusting the pynetbox code as given in the issue that you mentioned.

ivlru commented 3 months ago

Hi, patricklind

my quick fix is: LOGIN_REQUIRED=false

I placed this into "netbox-zabbix-sync/config.py" but it still alarms:

pynetbox.core.query.RequestError: The request failed with code 403 Forbidden: {'detail': 'Authentication credentials were not provided.'}

Could you please repeat how to fix that? Thank you!

patricklind commented 3 months ago

LOGIN_REQUIRED https://demo.netbox.dev/static/docs/configuration/optional-settings/#login_required my quick fix is: LOGIN_REQUIRED=false

ivlru commented 3 months ago

Thank you!