mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-16 04:02:56 -06:00
Fixed -H function.
This commit is contained in:
parent
bff611ca67
commit
430fc6969f
@ -109,10 +109,15 @@ def main(arguments):
|
|||||||
else:
|
else:
|
||||||
# Add hostgroup is flag is true
|
# Add hostgroup is flag is true
|
||||||
# and Hostgroup is not present in Zabbix
|
# and Hostgroup is not present in Zabbix
|
||||||
if(not device.hostgroup and arguments.hostgroups):
|
if(arguments.hostgroups):
|
||||||
# Create new hostgroup
|
for group in zabbix_groups:
|
||||||
device.createZabbixHostgroup()
|
if(group["name"] == device.hostgroup):
|
||||||
zabbix_groups = zabbix.hostgroup.get(output=['name'])
|
# If hostgroup is already present in Zabbix
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# Create new hostgroup
|
||||||
|
hostgroup = device.createZabbixHostgroup()
|
||||||
|
zabbix_groups.append(hostgroup)
|
||||||
# Add device to Zabbix
|
# Add device to Zabbix
|
||||||
device.createInZabbix(zabbix_groups, zabbix_templates)
|
device.createInZabbix(zabbix_groups, zabbix_templates)
|
||||||
except SyncError:
|
except SyncError:
|
||||||
@ -369,9 +374,11 @@ class NetworkDevice():
|
|||||||
Creates Zabbix host group based on hostgroup format.
|
Creates Zabbix host group based on hostgroup format.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.zabbix.hostgroup.create(name=self.hostgroup)
|
groupid = self.zabbix.hostgroup.create(name=self.hostgroup)
|
||||||
e = f"Added hostgroup '{self.hostgroup}'."
|
e = f"Added hostgroup '{self.hostgroup}'."
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
|
data = {'groupid': groupid["groupids"][0], 'name': self.hostgroup}
|
||||||
|
return data
|
||||||
except ZabbixAPIException as e:
|
except ZabbixAPIException as e:
|
||||||
e = f"Couldn't add hostgroup, Zabbix returned {str(e)}."
|
e = f"Couldn't add hostgroup, Zabbix returned {str(e)}."
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
Loading…
Reference in New Issue
Block a user