mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-14 01:41:25 -06:00
Implemented workaround for Zabbix 7.0.x API changes.
This commit is contained in:
parent
8aba95525b
commit
1f4a81e2e4
@ -508,6 +508,9 @@ class NetworkDevice():
|
|||||||
if(not self.getZabbixGroup(groups)):
|
if(not self.getZabbixGroup(groups)):
|
||||||
raise SyncInventoryError()
|
raise SyncInventoryError()
|
||||||
self.zbxTemplatePrepper(templates)
|
self.zbxTemplatePrepper(templates)
|
||||||
|
templateids = []
|
||||||
|
for template in self.zbx_templates:
|
||||||
|
templateids.append({'templateid': template['templateid']})
|
||||||
# Set interface, group and template configuration
|
# Set interface, group and template configuration
|
||||||
interfaces = self.setInterfaceDetails()
|
interfaces = self.setInterfaceDetails()
|
||||||
groups = [{"groupid": self.group_id}]
|
groups = [{"groupid": self.group_id}]
|
||||||
@ -515,13 +518,22 @@ class NetworkDevice():
|
|||||||
self.setProxy(proxies)
|
self.setProxy(proxies)
|
||||||
# Add host to Zabbix
|
# Add host to Zabbix
|
||||||
try:
|
try:
|
||||||
host = self.zabbix.host.create(host=self.name,
|
if version.parse(self.zabbix.api_version()) < version.parse("7.0.0"):
|
||||||
status=self.zabbix_state,
|
host = self.zabbix.host.create(host=self.name,
|
||||||
interfaces=interfaces,
|
status=self.zabbix_state,
|
||||||
groups=groups,
|
interfaces=interfaces,
|
||||||
templates=self.zbx_templates,
|
groups=groups,
|
||||||
proxy_hostid=self.zbxproxy,
|
templates=templateids,
|
||||||
description=description)
|
proxy_hostid=self.zbxproxy,
|
||||||
|
description=description)
|
||||||
|
else:
|
||||||
|
host = self.zabbix.host.create(host=self.name,
|
||||||
|
status=self.zabbix_state,
|
||||||
|
interfaces=interfaces,
|
||||||
|
groups=groups,
|
||||||
|
templates=templateids,
|
||||||
|
proxyid=self.zbxproxy,
|
||||||
|
description=description)
|
||||||
self.zabbix_id = host["hostids"][0]
|
self.zabbix_id = host["hostids"][0]
|
||||||
except ZabbixAPIException as e:
|
except ZabbixAPIException as e:
|
||||||
e = f"Couldn't add {self.name}, Zabbix returned {str(e)}."
|
e = f"Couldn't add {self.name}, Zabbix returned {str(e)}."
|
||||||
@ -625,18 +637,26 @@ class NetworkDevice():
|
|||||||
# Check if a proxy has been defined
|
# Check if a proxy has been defined
|
||||||
if(self.zbxproxy != "0"):
|
if(self.zbxproxy != "0"):
|
||||||
# Check if expected proxyID matches with configured proxy
|
# Check if expected proxyID matches with configured proxy
|
||||||
if(host["proxy_hostid"] == self.zbxproxy):
|
if(("proxy_hostid" in host and host["proxy_hostid"] == self.zbxproxy)
|
||||||
|
or ("proxyid" in host and host["proxyid"] == self.zbxproxy)):
|
||||||
logger.debug(f"Device {self.name}: proxy in-sync.")
|
logger.debug(f"Device {self.name}: proxy in-sync.")
|
||||||
else:
|
else:
|
||||||
# Proxy diff, update value
|
# Proxy diff, update value
|
||||||
logger.warning(f"Device {self.name}: proxy OUT of sync.")
|
logger.warning(f"Device {self.name}: proxy OUT of sync.")
|
||||||
self.updateZabbixHost(proxy_hostid=self.zbxproxy)
|
if version.parse(self.zabbix.api_version()) < version.parse("7.0.0"):
|
||||||
|
self.updateZabbixHost(proxy_hostid=self.zbxproxy)
|
||||||
|
else:
|
||||||
|
self.updateZabbixHost(proxyid=self.zbxproxy)
|
||||||
else:
|
else:
|
||||||
if(not host["proxy_hostid"] == "0"):
|
if(("proxy_hostid" in host and not host["proxy_hostid"] == "0")
|
||||||
|
or ("proxyid" in host and not host["proxyid"] == "0")):
|
||||||
if(proxy_power):
|
if(proxy_power):
|
||||||
# Variable full_proxy_sync has been enabled
|
# Variable full_proxy_sync has been enabled
|
||||||
# delete the proxy link in Zabbix
|
# delete the proxy link in Zabbix
|
||||||
self.updateZabbixHost(proxy_hostid=self.zbxproxy)
|
if version.parse(self.zabbix.api_version()) < version.parse("7.0.0"):
|
||||||
|
self.updateZabbixHost(proxy_hostid=self.zbxproxy)
|
||||||
|
else:
|
||||||
|
self.updateZabbixHost(proxyid=self.zbxproxy)
|
||||||
else:
|
else:
|
||||||
# Instead of deleting the proxy config in zabbix and
|
# Instead of deleting the proxy config in zabbix and
|
||||||
# forcing potential data loss,
|
# forcing potential data loss,
|
||||||
|
Loading…
Reference in New Issue
Block a user