0543266c92
- Restructuring of the project directory into client and server components - Renaming of modules and classes to better reflect their purpose and functionality - Moving common utilities and configurations to a shared location - Updating import statements to reflect the new structure - Adding new documentation files for better clarity on various aspects of the project - Removing deprecated or unused code to streamline the codebase - Ensuring that all existing functionality is preserved and that the codebase remains functional after the refactoring.
76 lines
2.0 KiB
Plaintext
76 lines
2.0 KiB
Plaintext
"""Configuration loader and defaults for hbd."""
|
|
|
|
import logging
|
|
import os
|
|
|
|
try:
|
|
import yaml
|
|
except Exception:
|
|
yaml = None
|
|
|
|
DEFAULTS = {
|
|
"hb_port": 50003,
|
|
"hbd_port": 50004,
|
|
"hbd_host": "",
|
|
"pickfile": "/tmp/hb.pick",
|
|
"logfile": "/var/log/heartbeat.log",
|
|
"logfmt": "text",
|
|
"pushsrv": "pushover",
|
|
"pushover_token": "",
|
|
"pushover_user": "",
|
|
"interval": 20,
|
|
"grace": 2,
|
|
"dyndomains": ["wrede.org"],
|
|
"watchhosts": [],
|
|
"dyndnshosts": [],
|
|
"drophosts": [],
|
|
"nsupdate_bin": "/usr/bin/nsupdate",
|
|
"foreground": False,
|
|
"verbose": False,
|
|
"debug": 0,
|
|
"smtpserver": "smtp.fastmail.com",
|
|
"smtpuser": "andreas@wrede.ca",
|
|
"smtppassword": "pvtvefyp5gbhnch2",
|
|
"smtpport": 587,
|
|
"toemail": ["aew.hbd.notify@wrede.ca"],
|
|
"fromemail": "aew.hbd@wrede.ca",
|
|
"ws_port": 50005,
|
|
"wss_port": None,
|
|
"cert_path": "/usr/local/etc/ssl/",
|
|
"wss_pem": "fullchain.pem",
|
|
"wss_key": "privkey.pem",
|
|
# Message journal configuration
|
|
"journal_enabled": True,
|
|
"journal_dir": "/var/log/heartbeat",
|
|
"journal_file": "messages.journal",
|
|
"journal_max_size": 100 * 1024 * 1024, # 100MB
|
|
"journal_max_backups": 10,
|
|
"plugins": {},
|
|
"thresholds": {},
|
|
"threshold_renotify_interval": 3600,
|
|
}
|
|
|
|
|
|
def load_config(path=None):
|
|
"""Load configuration from a YAML file and merge with defaults.
|
|
|
|
If YAML is not available or the file does not exist, defaults are returned.
|
|
"""
|
|
cfg = DEFAULTS.copy()
|
|
if not path:
|
|
# default path (~/.hb.yaml)
|
|
path = os.path.join(os.path.expanduser("~"), ".hb.yaml")
|
|
|
|
if os.path.exists(path):
|
|
if yaml:
|
|
with open(path) as fh:
|
|
data = yaml.safe_load(fh)
|
|
# Merge YAML data with defaults
|
|
# Keep all keys from YAML to support plugin configs and future extensions
|
|
for k, v in data.items():
|
|
cfg[k] = v
|
|
else:
|
|
# yaml not installed: do not attempt to parse; user must ensure defaults
|
|
pass
|
|
return cfg
|