mirror of
https://github.com/TheNetworkGuy/netbox-zabbix-sync.git
synced 2025-12-18 11:22:22 -06:00
Adjusted Gitignore, added config module, adjusted requirements for YAML support, added first unittests
This commit is contained in:
37
modules/config.py
Normal file
37
modules/config.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
Module for parsing configuration from the top level config.yaml file
|
||||
"""
|
||||
from pathlib import Path
|
||||
import yaml
|
||||
|
||||
DEFAULT_CONFIG = {
|
||||
"templates_config_context": False,
|
||||
"templates_config_context_overrule": False,
|
||||
"template_cf": "zabbix_template",
|
||||
"device_cf": "zabbix_hostid",
|
||||
"clustering": False,
|
||||
"create_hostgroups": True,
|
||||
"create_journal": False,
|
||||
"sync_vms": False,
|
||||
"zabbix_device_removal": ["Decommissioning", "Inventory"],
|
||||
"zabbix_device_disable": ["Offline", "Planned", "Staged", "Failed"]
|
||||
}
|
||||
|
||||
|
||||
def load_config(config_path="config.yaml"):
|
||||
"""Loads config from YAML file and combines it with default config"""
|
||||
# Get data from default config.
|
||||
config = DEFAULT_CONFIG.copy()
|
||||
# Set config path
|
||||
config_file = Path(config_path)
|
||||
# Check if file exists
|
||||
if config_file.exists():
|
||||
try:
|
||||
with open(config_file, "r", encoding="utf-8") as f:
|
||||
user_config = yaml.safe_load(f) or {}
|
||||
config.update(user_config)
|
||||
except OSError:
|
||||
# Probably some I/O error with user permissions etc.
|
||||
# Ignore for now and return default config
|
||||
pass
|
||||
return config
|
||||
Reference in New Issue
Block a user