mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-14 01:41:25 -06:00
Added basic error message when Netbox details are invalid. Fixed logging message for when template context keys are not present.
This commit is contained in:
parent
ffc2aa1947
commit
56c19d97de
@ -146,11 +146,11 @@ class PhysicalDevice():
|
|||||||
""" Get Zabbix templates from the device context """
|
""" Get Zabbix templates from the device context """
|
||||||
if "zabbix" not in self.config_context:
|
if "zabbix" not in self.config_context:
|
||||||
e = (f"Host {self.name}: Key 'zabbix' not found in config "
|
e = (f"Host {self.name}: Key 'zabbix' not found in config "
|
||||||
"context for template")
|
"context for template lookup")
|
||||||
raise TemplateError(e)
|
raise TemplateError(e)
|
||||||
if "templates" not in self.config_context["zabbix"]:
|
if "templates" not in self.config_context["zabbix"]:
|
||||||
e = (f"Host {self.name}: Key 'templates' not found in config "
|
e = (f"Host {self.name}: Key 'templates' not found in config "
|
||||||
"context 'zabbix' for template host")
|
"context 'zabbix' for template lookup")
|
||||||
raise TemplateError(e)
|
raise TemplateError(e)
|
||||||
return self.config_context["zabbix"]["templates"]
|
return self.config_context["zabbix"]["templates"]
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ import logging
|
|||||||
import argparse
|
import argparse
|
||||||
from os import environ, path, sys
|
from os import environ, path, sys
|
||||||
from pynetbox import api
|
from pynetbox import api
|
||||||
|
from pynetbox.core.query import RequestError as NBRequestError
|
||||||
|
from requests.exceptions import ConnectionError as RequestsConnectionError
|
||||||
from zabbix_utils import ZabbixAPI, APIRequestError, ProcessingError
|
from zabbix_utils import ZabbixAPI, APIRequestError, ProcessingError
|
||||||
from modules.device import PhysicalDevice
|
from modules.device import PhysicalDevice
|
||||||
from modules.virtual_machine import VirtualMachine
|
from modules.virtual_machine import VirtualMachine
|
||||||
@ -82,7 +84,15 @@ def main(arguments):
|
|||||||
allowed_objects = ["location", "role", "manufacturer", "region",
|
allowed_objects = ["location", "role", "manufacturer", "region",
|
||||||
"site", "site_group", "tenant", "tenant_group"]
|
"site", "site_group", "tenant", "tenant_group"]
|
||||||
# Create API call to get all custom fields which are on the device objects
|
# Create API call to get all custom fields which are on the device objects
|
||||||
device_cfs = netbox.extras.custom_fields.filter(type="text", content_type_id=23)
|
try:
|
||||||
|
device_cfs = list(netbox.extras.custom_fields.filter(type="text", content_type_id=23))
|
||||||
|
except RequestsConnectionError:
|
||||||
|
logger.error(f"Unable to connect to Netbox with URL {netbox_host}."
|
||||||
|
" Please check the URL and status of Netbox.")
|
||||||
|
sys.exit(1)
|
||||||
|
except NBRequestError as e:
|
||||||
|
logger.error(f"Netbox error: {e}")
|
||||||
|
sys.exit(1)
|
||||||
for cf in device_cfs:
|
for cf in device_cfs:
|
||||||
allowed_objects.append(cf.name)
|
allowed_objects.append(cf.name)
|
||||||
for hg_object in hg_objects:
|
for hg_object in hg_objects:
|
||||||
|
Loading…
Reference in New Issue
Block a user