mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-16 04:02:56 -06:00
Fixed #79
This commit is contained in:
parent
204937b784
commit
5d4ff9c5ed
@ -296,10 +296,16 @@ class PhysicalDevice():
|
|||||||
"""
|
"""
|
||||||
if self.zabbix_id:
|
if self.zabbix_id:
|
||||||
try:
|
try:
|
||||||
self.zabbix.host.delete(self.zabbix_id)
|
# Check if the Zabbix host exists in Zabbix
|
||||||
self.nb.custom_fields[device_cf] = None
|
zbx_host = bool(self.zabbix.host.get(filter={'hostid': self.zabbix_id},
|
||||||
self.nb.save()
|
output=[]))
|
||||||
e = f"Host {self.name}: Deleted host from Zabbix."
|
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.logger.info(e)
|
||||||
self.create_journal_entry("warning", "Deleted host from Zabbix")
|
self.create_journal_entry("warning", "Deleted host from Zabbix")
|
||||||
except APIRequestError as e:
|
except APIRequestError as e:
|
||||||
@ -307,6 +313,12 @@ class PhysicalDevice():
|
|||||||
self.logger.error(message)
|
self.logger.error(message)
|
||||||
raise SyncExternalError(message) from e
|
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):
|
def _zabbixHostnameExists(self):
|
||||||
"""
|
"""
|
||||||
Checks if hostname exists in Zabbix.
|
Checks if hostname exists in Zabbix.
|
||||||
|
Loading…
Reference in New Issue
Block a user