Docker
To pull the latest stable version to your local cache, use the following docker pull command:
docker pull ghcr.io/thenetworkguy/netbox-zabbix-sync:main
Make sure to specify the needed environment variables for the script to work (see here) on the command line or use an env file.
docker run -d -t -i -e ZABBIX_HOST='https://zabbix.local' \
-e ZABBIX_TOKEN='othersecrettoken' \
-e NETBOX_HOST='https://netbox.local' \
-e NETBOX_TOKEN='secrettoken' \
--name netbox-zabbix-sync ghcr.io/thenetworkguy/netbox-zabbix-sync:main
This should run a one-time sync, you can check the sync with
docker logs netbox-zabbix-sync.
The image uses the default config.py for it's configuration, you can use a
volume mount in the docker run command to override with your own config file if
needed (see config file):
docker run -d -t -i -v $(pwd)/config.py:/opt/netbox-zabbix/config.py ...
Install the Python package
Instead of a all-in-1 solution you can opt to install the netbox-zabbix-sync Python package and import the class by yourself! This allows you to call the sync function in other scripts or with other requirements.
https://pypi.org/project/netbox-zabbix-sync/
pip install netbox-zabbix-sync
We have provided an example configuration down below. You do not need to pass all of the configuration options. Only the options that you want to change from the base default configuration are required to be passed using a dictionary.
from netbox_zabbix_sync import Sync
# Setting the configuration
config = {"clustering": True}
# Setting the connection details. Obviously we recommend not using plain-text passwords in code
# This is only as an example of passing variables to the connect() function.
netbox_host = "https://netbox.internal"
netbox_token = "supersecrettoken"
zabbix_host = "https://zabbix.internal"
zabbix_user = "NetboxSync"
zabbix_pass = "supersecretpassword"
sync = Sync(config)
sync.connect(
nb_host=netbox_host,
nb_token=netbox_token,
zbx_host=zabbix_host,
zbx_user=zabbix_user,
zbx_pass=zabbix_pass
)
sync.start()
Installation from Source
Cloning the repository
git clone https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
Packages
Make sure that you have a python environment with the following packages
installed. You can also use the requirements.txt file for installation with
pip.
# Packages:
pynetbox
pyzabbix
# Install them through requirements.txt from a venv:
virtualenv .venv
source .venv/bin/activate
.venv/bin/pip --require-virtualenv install -r requirements.txt
Set environment variables
Set the following environment variables:
export ZABBIX_HOST="https://zabbix.local"
export ZABBIX_USER="username"
export ZABBIX_PASS="Password"
export NETBOX_HOST="https://netbox.local"
export NETBOX_TOKEN="secrettoken"
Or, you can use a Zabbix API token to login instead of using a username and
password. In that case ZABBIX_USER and ZABBIX_PASS will be ignored.
export ZABBIX_TOKEN=othersecrettoken
If you are using custom SSL certificates for NetBox and/or Zabbix, you can set the following environment variable to the path of your CA bundle file:
export REQUESTS_CA_BUNDLE=/path/to/your/ca-bundle.crt
Flags and troubleshooting
| Flag | Option | Description |
|---|---|---|
| -v | verbose | Log with info on. |
| -vv | debug | Log with debugging on. |
| -vvv | debug-all | Log with debugging on for all modules |
| -version | Shows the script version | |
| -q | --quiet | Turn off warnings |
| -c | --config | Path to the config file (default: config.py next to the script or in the current directory) |
Configuration
After installing the script you can start and run with the default settings. If you want to have more control over all of the features then this information is provided over at the configuration page.