mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-13 15:24:48 -06:00
Fixed #79
This commit is contained in:
parent
204937b784
commit
5d4ff9c5ed
@ -296,10 +296,16 @@ class PhysicalDevice():
|
||||
"""
|
||||
if self.zabbix_id:
|
||||
try:
|
||||
self.zabbix.host.delete(self.zabbix_id)
|
||||
self.nb.custom_fields[device_cf] = None
|
||||
self.nb.save()
|
||||
e = f"Host {self.name}: Deleted host from Zabbix."
|
||||
# Check if the Zabbix host exists in Zabbix
|
||||
zbx_host = bool(self.zabbix.host.get(filter={'hostid': self.zabbix_id},
|
||||
output=[]))
|
||||
e = (f"Host {self.name}: was already deleted from Zabbix."
|
||||
" Removed link in Netbox.")
|
||||
if zbx_host:
|
||||
# Delete host should it exists
|
||||
self.zabbix.host.delete(self.zabbix_id)
|
||||
e = f"Host {self.name}: Deleted host from Zabbix."
|
||||
self.zeroize_cf()
|
||||
self.logger.info(e)
|
||||
self.create_journal_entry("warning", "Deleted host from Zabbix")
|
||||
except APIRequestError as e:
|
||||
@ -307,6 +313,12 @@ class PhysicalDevice():
|
||||
self.logger.error(message)
|
||||
raise SyncExternalError(message) from e
|
||||
|
||||
def zeroize_cf(self):
|
||||
"""Sets the hostID custom field in Netbox to zero,
|
||||
effectively destroying the link"""
|
||||
self.nb.custom_fields[device_cf] = None
|
||||
self.nb.save()
|
||||
|
||||
def _zabbixHostnameExists(self):
|
||||
"""
|
||||
Checks if hostname exists in Zabbix.
|
||||
|
Loading…
Reference in New Issue
Block a user