From 036a0c06d15cd181556959718346148b08af0e0d Mon Sep 17 00:00:00 2001 From: Twan Kamans Date: Thu, 29 Apr 2021 10:15:35 +0200 Subject: [PATCH] Fixed #6 --- netbox_zabbix_sync.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/netbox_zabbix_sync.py b/netbox_zabbix_sync.py index bf58d72..63a4595 100755 --- a/netbox_zabbix_sync.py +++ b/netbox_zabbix_sync.py @@ -114,22 +114,22 @@ def main(arguments): logger.info(f"Skipping host {device.name} since its " f"not in the active state.") continue + # Add hostgroup is flag is true + # and Hostgroup is not present in Zabbix + if(arguments.hostgroups): + for group in zabbix_groups: + # If hostgroup is already present in Zabbix + if(group["name"] == device.hostgroup): + break + else: + # Create new hostgroup + hostgroup = device.createZabbixHostgroup() + zabbix_groups.append(hostgroup) + # Device is already present in Zabbix if(device.zabbix_id): - # Device is already present in Zabbix device.ConsistencyCheck(zabbix_groups, zabbix_templates) + # Add device to Zabbix else: - # Add hostgroup is flag is true - # and Hostgroup is not present in Zabbix - if(arguments.hostgroups): - for group in zabbix_groups: - if(group["name"] == device.hostgroup): - # If hostgroup is already present in Zabbix - break - else: - # Create new hostgroup - hostgroup = device.createZabbixHostgroup() - zabbix_groups.append(hostgroup) - # Add device to Zabbix device.createInZabbix(zabbix_groups, zabbix_templates) except SyncError: pass