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):
|
||||
dconf[key] = getattr(config_module, key)
|
||||
return dconf
|
||||
else:
|
||||
logger.warning(
|
||||
"Config file %s not found. Using default config "
|
||||
"and environment variables.", config_file)
|
||||
|
@ -69,7 +69,7 @@ class PhysicalDevice():
|
||||
if config["device_cf"] in self.nb.custom_fields:
|
||||
self.zabbix_id = self.nb.custom_fields[config["device_cf"]]
|
||||
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)
|
||||
raise SyncInventoryError(e)
|
||||
|
||||
@ -131,11 +131,13 @@ class PhysicalDevice():
|
||||
# Set value to template
|
||||
return [device_type_cfs[config["template_cf"]]]
|
||||
# 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" - {self.nb.device_type.display}.")
|
||||
raise TemplateError(e)
|
||||
|
||||
|
||||
|
||||
def get_templates_context(self):
|
||||
""" Get Zabbix templates from the device context """
|
||||
if "zabbix" not in self.config_context:
|
||||
@ -166,7 +168,7 @@ class PhysicalDevice():
|
||||
self.inventory_mode = 1
|
||||
else:
|
||||
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
|
||||
self.inventory = {}
|
||||
if config["inventory_sync"] and self.inventory_mode in [0, 1]:
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""Tests for configuration parsing in the modules.config module."""
|
||||
from unittest.mock import patch, MagicMock
|
||||
from pathlib import Path
|
||||
import os
|
||||
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
|
||||
# expect an exception to be raised
|
||||
try:
|
||||
result = load_config_file(DEFAULT_CONFIG.copy())
|
||||
load_config_file(DEFAULT_CONFIG.copy())
|
||||
assert False, "An exception should have been raised"
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# This is expected
|
||||
pass
|
||||
|
Loading…
Reference in New Issue
Block a user