TheNetworkGuy / netbox-zabbix-sync

Python script to synchronise Netbox devices to Zabbix.
MIT License
109 stars 27 forks source link

Environment variable ZABBIX_HOST has not been defined. #26

Closed patricklind closed 1 year ago

patricklind commented 1 year ago

ython3 netbox_zabbix_sync2.py 2023-02-06 13:07:20,958 - Netbox-Zabbix-sync - ERROR - Environment variable ZABBIX_HOST has not been defined. Traceback (most recent call last): File "/opt/apps/netbox-zabbix-sync/netbox_zabbix_sync2.py", line 716, in main(args) File "/opt/apps/netbox-zabbix-sync/netbox_zabbix_sync2.py", line 47, in main raise EnvironmentVarError(e) main.EnvironmentVarError: Environment variable ZABBIX_HOST has not been defined

patricklind commented 1 year ago

Environment variable is filled

TheNetworkGuy commented 1 year ago

Is the ENV variable declared under the same user that is running the script?

Could you run the "env | grep ZABBIX" comman, after that run the script under the same user again and paste the output in this issue? You can anonymize the output should it contain sensitive information. I can also see that you renamed the file to *sync2.py. Did you make any changes to the code that contains the environment variable logic? If so than i cannot do much troubleshooting here :P

patricklind commented 1 year ago

root@zabbix:/opt/apps/netbox-zabbix-sync# python3 netbox_zabbix_sync.py | env | grep ZABBIX 2023-02-06 15:24:15,816 - Netbox-Zabbix-sync - ERROR - Environment variable ZABBIX_HOST has not been defined. Traceback (most recent call last): File "/opt/apps/netbox-zabbix-sync/netbox_zabbix_sync.py", line 760, in main(args) File "/opt/apps/netbox-zabbix-sync/netbox_zabbix_sync.py", line 44, in main raise EnvironmentVarError(e) main.EnvironmentVarError: Environment variable ZABBIX_HOST has not been defined. root@zabbix:/opt/apps/netbox-zabbix-sync# env | grep ZABBIX root@zabbix:/opt/apps/netbox-zabbix-sync# root@zabbix:/opt/apps/netbox-zabbix-sync# root@zabbix:/opt/apps/netbox-zabbix-sync# root@zabbix:/opt/apps/netbox-zabbix-sync# cat config.py | grep ZABBIX ZABBIX_HOST="https://zabbix.vigfestival.network"

TheNetworkGuy commented 1 year ago

Ah i see you declared the value in the config.py file. This is (for now) not the correct location for this type of data for security and flexibility reasons.

Please set the environment variable like so:

[root@docker ~]# export ZABBIX_HOST="https://zabbix.local"
[root@docker ~]# env | grep ZABBIX
ZABBIX_HOST=https://zabbix.home.local
[root@docker ~]#

Please do this for all the required variables:

ZABBIX_HOST="https://zabbix.local"
ZABBIX_USER="username"
ZABBIX_PASS="Password"
NETBOX_HOST="https://netbox.local"
NETBOX_TOKEN="secrettoken"
patricklind commented 1 year ago

can i get it into a .env file ?

TheNetworkGuy commented 1 year ago

How you import the environment variables is up to you and more of a general linux question. If you want to set the Zabbix host, password and token information in clear text in a text file than you could do this and modify the code to import said variables. However i won't support this and won't advice you to do so.

Instead, look at the different ways of setting environment variables under users or how to set them for a systemctl service.

TheNetworkGuy commented 1 year ago

Closing this one due to inactivity.