From 9259e736173769796868909a1c6f4f9a89e6aa90 Mon Sep 17 00:00:00 2001 From: Raymond Kuiper Date: Mon, 8 Sep 2025 14:44:46 +0200 Subject: [PATCH] Added option to extend site information for devices and vms. --- .gitignore | 1 + config.py.example | 18 +++++++++++------- modules/config.py | 1 + modules/device.py | 1 + 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index c515fe3..0cf4953 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.log .venv +.env config.py Pipfile Pipfile.lock diff --git a/config.py.example b/config.py.example index e4082e6..869da30 100644 --- a/config.py.example +++ b/config.py.example @@ -53,6 +53,12 @@ hostgroup_format = "site/manufacturer/role" traverse_regions = False traverse_site_groups = False +## Extended site properteis +# By default, NetBox will only return basic site info for any device or VM. +# By setting `extended_site_properties` to True, the script will query NetBox for additiopnal site info. +# Be aware that this will increase the number of API queries to NetBox. +extended_site_properties = False + ## Filtering # Custom device filter, variable must be present but can be left empty with no filtering. # A couple of examples: @@ -87,8 +93,8 @@ device_inventory_map = { "asset_tag": "asset_tag", "virtual_chassis/name": "chassis", "status/label": "deployment_status", "location/name": "location", - "latitude": "location_lat", - "longitude": "location_lon", + "site/latitude": "location_lat", + "site/longitude": "location_lon", "comments": "notes", "name": "name", "rack/name": "site_rack", @@ -112,19 +118,19 @@ usermacro_sync = False # device usermacro_map to map NetBox fields to usermacros. device_usermacro_map = {"serial": "{$HW_SERIAL}", "role/name": "{$DEV_ROLE}", - "url": "{$NB_URL}", + "display_url": "{$NB_URL}", "id": "{$NB_ID}"} # virtual machine usermacro_map to map NetBox fields to usermacros. vm_usermacro_map = {"memory": "{$TOTAL_MEMORY}", "role/name": "{$DEV_ROLE}", - "url": "{$NB_URL}", + "display_url": "{$NB_URL}", "id": "{$NB_ID}"} # To sync host tags to Zabbix, set to True. tag_sync = False -# Setting tag_lower to True will lower capital letters ain tag names and values +# Setting tag_lower to True will lower capital letters in tag names and values # This is more inline with the Zabbix way of working with tags. # # You can however set this to False to ensure capital letters are synced to Zabbix tags. @@ -132,8 +138,6 @@ tag_lower = True # We can sync NetBox device/VM tags to Zabbix, but as NetBox tags don't follow the key/value # pattern, we need to specify a tag name to register the NetBox tags in Zabbix. -# -# # # If tag_name is set to False, we won't sync NetBox device/VM tags to Zabbix. tag_name = 'NetBox' diff --git a/modules/config.py b/modules/config.py index a105892..43bd775 100644 --- a/modules/config.py +++ b/modules/config.py @@ -31,6 +31,7 @@ DEFAULT_CONFIG = { "nb_vm_filter": {"name__n": "null"}, "inventory_mode": "disabled", "inventory_sync": False, + "extended_site_properties": False, "device_inventory_map": { "asset_tag": "asset_tag", "virtual_chassis/name": "chassis", diff --git a/modules/device.py b/modules/device.py index cf0e2a2..6b00846 100644 --- a/modules/device.py +++ b/modules/device.py @@ -2,6 +2,7 @@ """ Device specific handeling for NetBox to Zabbix """ +from pprint import pprint from copy import deepcopy from logging import getLogger