From 09a6906a63c90ccc7f99d674a00d7832080042f9 Mon Sep 17 00:00:00 2001 From: TheNetworkGuy Date: Wed, 13 Nov 2024 19:56:09 +0100 Subject: [PATCH] Added VM filtering --- config.py.example | 2 ++ netbox_zabbix_sync.py | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config.py.example b/config.py.example index ca171cf..14ecfb1 100644 --- a/config.py.example +++ b/config.py.example @@ -63,6 +63,8 @@ traverse_site_groups = False # Default device filter, only get devices which have a name in Netbox: nb_device_filter = {"name__n": "null"} +# Default filter for VMs +vm_device_filter = {"name__n": "null"} ## Inventory # See https://www.zabbix.com/documentation/current/en/manual/config/hosts/inventory#building-inventory diff --git a/netbox_zabbix_sync.py b/netbox_zabbix_sync.py index cfe95fb..123aafa 100755 --- a/netbox_zabbix_sync.py +++ b/netbox_zabbix_sync.py @@ -24,7 +24,8 @@ try: hostgroup_format, vm_hostgroup_format, nb_device_filter, - sync_vms + sync_vms, + vm_device_filter ) except ModuleNotFoundError: print("Configuration file config.py not found in main directory." @@ -119,7 +120,7 @@ def main(arguments): proxy_name = "name" # Get all Zabbix and Netbox data netbox_devices = netbox.dcim.devices.filter(**nb_device_filter) - netbox_vms = netbox.virtualization.virtual_machines.all() if sync_vms else [] + netbox_vms = netbox.virtualization.virtual_machines.filter(**vm_device_filter) if sync_vms else [] netbox_site_groups = convert_recordset((netbox.dcim.site_groups.all())) netbox_regions = convert_recordset(netbox.dcim.regions.all()) netbox_journals = netbox.extras.journal_entries