mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-12-13 11:59:36 -06:00
♻️ Improved Zabbix version check for proxy group insertion
This commit is contained in:
parent
7d9bb9f637
commit
123b243f56
@ -7,6 +7,7 @@ from copy import deepcopy
|
|||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from re import search
|
from re import search
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
from zabbix_utils import APIRequestError
|
from zabbix_utils import APIRequestError
|
||||||
from pynetbox import RequestError as NetboxRequestError
|
from pynetbox import RequestError as NetboxRequestError
|
||||||
@ -454,7 +455,7 @@ class PhysicalDevice:
|
|||||||
self.tags = tags.generate()
|
self.tags = tags.generate()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setProxy(self, proxy_list):
|
def _setProxy(self, proxy_list: list[dict[str, Any]]) -> bool:
|
||||||
"""
|
"""
|
||||||
Sets proxy or proxy group if this
|
Sets proxy or proxy group if this
|
||||||
value has been defined in config context
|
value has been defined in config context
|
||||||
@ -467,7 +468,8 @@ class PhysicalDevice:
|
|||||||
# Includes proxy group fix since Zabbix <= 6 should ignore this
|
# Includes proxy group fix since Zabbix <= 6 should ignore this
|
||||||
proxy_types = ["proxy"]
|
proxy_types = ["proxy"]
|
||||||
proxy_name = None
|
proxy_name = None
|
||||||
if str(self.zabbix.version).startswith("7"):
|
|
||||||
|
if self.zabbix.version >= 7.0:
|
||||||
# Only insert groups in front of list for Zabbix7
|
# Only insert groups in front of list for Zabbix7
|
||||||
proxy_types.insert(0, "proxy_group")
|
proxy_types.insert(0, "proxy_group")
|
||||||
|
|
||||||
@ -488,6 +490,7 @@ class PhysicalDevice:
|
|||||||
proxy_type in self.nb.config_context["zabbix"]):
|
proxy_type in self.nb.config_context["zabbix"]):
|
||||||
proxy_name = self.nb.config_context["zabbix"][proxy_type]
|
proxy_name = self.nb.config_context["zabbix"][proxy_type]
|
||||||
# go through all proxies
|
# go through all proxies
|
||||||
|
|
||||||
if proxy_name:
|
if proxy_name:
|
||||||
for proxy in proxy_list:
|
for proxy in proxy_list:
|
||||||
# If the proxy does not match the type, ignore and continue
|
# If the proxy does not match the type, ignore and continue
|
||||||
@ -500,6 +503,7 @@ class PhysicalDevice:
|
|||||||
)
|
)
|
||||||
self.zbxproxy = proxy
|
self.zbxproxy = proxy
|
||||||
return True
|
return True
|
||||||
|
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
"Host %s: unable to find proxy %s", self.name, proxy_name
|
"Host %s: unable to find proxy %s", self.name, proxy_name
|
||||||
)
|
)
|
||||||
@ -532,7 +536,7 @@ class PhysicalDevice:
|
|||||||
# Set interface, group and template configuration
|
# Set interface, group and template configuration
|
||||||
interfaces = self.setInterfaceDetails()
|
interfaces = self.setInterfaceDetails()
|
||||||
# Set Zabbix proxy if defined
|
# Set Zabbix proxy if defined
|
||||||
self.setProxy(proxies)
|
self._setProxy(proxies)
|
||||||
# Set basic data for host creation
|
# Set basic data for host creation
|
||||||
create_data = {
|
create_data = {
|
||||||
"host": self.name,
|
"host": self.name,
|
||||||
@ -664,7 +668,7 @@ class PhysicalDevice:
|
|||||||
|
|
||||||
# Prepare templates and proxy config
|
# Prepare templates and proxy config
|
||||||
self.zbxTemplatePrepper(templates)
|
self.zbxTemplatePrepper(templates)
|
||||||
self.setProxy(proxies)
|
self._setProxy(proxies)
|
||||||
# Get host object from Zabbix
|
# Get host object from Zabbix
|
||||||
host = self.zabbix.host.get(
|
host = self.zabbix.host.get(
|
||||||
filter={"hostid": self.zabbix_id},
|
filter={"hostid": self.zabbix_id},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user