File based service discovery script for Prometheus. Make virtual machines and devices managed in Netbox as Prometheus targets with labels.
- Add build process for tagged Docker builds
- Add better unit tests
- Python >= 3.7
- Pynetbox.
The app is configured with env variables.
NETBOX_SD_URL: https://netboxdemo.com
NETBOX_SD_TOKEN: 72830d67beff4ae178b94d8f781842408df8069d
NETBOX_FILTER: "{\"status\":\"active\",\"site\":\"ds9\"}"
NETBOX_SD_FILE_PATH: /data/netbox/netbox.json
NETBOX_SD_LOG_LEVEL: "DEBUG"
NETBOX_SD_VERIFY_SSL: "FALSE"
Filters are applied as JSON which is mapped to Netbox filter criterias.
See the Netbox for more Details: https://netbox.readthedocs.io/en/stable/rest-api/filtering/
python3 netbox-prometheus-sd.py
The service discovery script requires the URL to the Netbox instance, an API token that can be generated into the user profile page of Netbox and a path to an output file.
In the Prometheus configuration, declare a new scrape job using the file_sd_configs
service discovery:
- job_name: 'netbox'
file_sd_configs:
- files:
- '/path/to/my/output.json'
See example
directory for an example on how this service discovery.
Currently we use netboxdemo.com for this. This should be changed to a local Docker based Netbox stack.
This project is based on a Script from ENIX SAS: