mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-07-14 01:41:25 -06:00
Fixed some basic Flake8 errors, added Pylinter exception, Fixed some minor logging bugs.
This commit is contained in:
parent
819126ce36
commit
0c715d4f96
@ -57,7 +57,6 @@ def load_config_file(config_default, config_file="config.py"):
|
|||||||
if hasattr(config_module, key):
|
if hasattr(config_module, key):
|
||||||
dconf[key] = getattr(config_module, key)
|
dconf[key] = getattr(config_module, key)
|
||||||
return dconf
|
return dconf
|
||||||
else:
|
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Config file %s not found. Using default config "
|
"Config file %s not found. Using default config "
|
||||||
"and environment variables.", config_file)
|
"and environment variables.", config_file)
|
||||||
|
@ -69,7 +69,7 @@ class PhysicalDevice():
|
|||||||
if config["device_cf"] in self.nb.custom_fields:
|
if config["device_cf"] in self.nb.custom_fields:
|
||||||
self.zabbix_id = self.nb.custom_fields[config["device_cf"]]
|
self.zabbix_id = self.nb.custom_fields[config["device_cf"]]
|
||||||
else:
|
else:
|
||||||
e = f"Host {self.name}: Custom field {config["device_cf"]} not present"
|
e = f'Host {self.name}: Custom field {config["device_cf"]} not present'
|
||||||
self.logger.warning(e)
|
self.logger.warning(e)
|
||||||
raise SyncInventoryError(e)
|
raise SyncInventoryError(e)
|
||||||
|
|
||||||
@ -131,11 +131,13 @@ class PhysicalDevice():
|
|||||||
# Set value to template
|
# Set value to template
|
||||||
return [device_type_cfs[config["template_cf"]]]
|
return [device_type_cfs[config["template_cf"]]]
|
||||||
# Custom field not found, return error
|
# Custom field not found, return error
|
||||||
e = (f"Custom field {config["template_cf"]} not "
|
e = (f'Custom field {config["template_cf"]} not '
|
||||||
f"found for {self.nb.device_type.manufacturer.name}"
|
f"found for {self.nb.device_type.manufacturer.name}"
|
||||||
f" - {self.nb.device_type.display}.")
|
f" - {self.nb.device_type.display}.")
|
||||||
raise TemplateError(e)
|
raise TemplateError(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_templates_context(self):
|
def get_templates_context(self):
|
||||||
""" 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:
|
||||||
@ -165,8 +167,8 @@ class PhysicalDevice():
|
|||||||
elif config["inventory_mode"] == "automatic":
|
elif config["inventory_mode"] == "automatic":
|
||||||
self.inventory_mode = 1
|
self.inventory_mode = 1
|
||||||
else:
|
else:
|
||||||
self.logger.error(f"Host {self.name}: Specified value for inventory mode in"
|
self.logger.error(f"Host {self.name}: Specified value for inventory mode in "
|
||||||
f" config is not valid. Got value {config["inventory_mode"]}")
|
f'config is not valid. Got value {config["inventory_mode"]}')
|
||||||
return False
|
return False
|
||||||
self.inventory = {}
|
self.inventory = {}
|
||||||
if config["inventory_sync"] and self.inventory_mode in [0, 1]:
|
if config["inventory_sync"] and self.inventory_mode in [0, 1]:
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""Tests for configuration parsing in the modules.config module."""
|
"""Tests for configuration parsing in the modules.config module."""
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
from pathlib import Path
|
|
||||||
import os
|
import os
|
||||||
from modules.config import load_config, DEFAULT_CONFIG, load_config_file, load_env_variable
|
from modules.config import load_config, DEFAULT_CONFIG, load_config_file, load_env_variable
|
||||||
|
|
||||||
@ -123,8 +122,8 @@ def test_load_config_file_exception_handling():
|
|||||||
# Since the current implementation doesn't handle exceptions, we should
|
# Since the current implementation doesn't handle exceptions, we should
|
||||||
# expect an exception to be raised
|
# expect an exception to be raised
|
||||||
try:
|
try:
|
||||||
result = load_config_file(DEFAULT_CONFIG.copy())
|
load_config_file(DEFAULT_CONFIG.copy())
|
||||||
assert False, "An exception should have been raised"
|
assert False, "An exception should have been raised"
|
||||||
except Exception:
|
except Exception: # pylint: disable=broad-except
|
||||||
# This is expected
|
# This is expected
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user