Move threshhold to server, move eventlog to notify

This commit is contained in:
Andreas Wrede
2026-03-29 20:29:33 -04:00
parent 0543266c92
commit ad7178ebcb
7 changed files with 61 additions and 48 deletions
+38
View File
@@ -7,13 +7,50 @@ import urllib.parse
import subprocess
import smtplib
import time
import sys
from . import ws as ws_mod
DEFAULT_PUSHPROVIDERS = ["all", "pushover", "mattermost", "signal"]
msg_to_websockets = ws_mod.broadcast
# module-level configuration set via setup()
_config = {}
logger = logging.getLogger(__name__)
msgs = []
logf = None
def initlog(logfile):
global logf
try:
logf = open(logfile, "a+")
return logf
except Exception as e:
import sys
print("cannot open logfile %s, using STDERR: %s" % (logfile, e))
return sys.stderr
def closelog():
global logf
if logf and logf != sys.stderr:
try:
logf.close()
except Exception:
pass
def log(host, m, service=None):
ts = time.time()
s = f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ts))} {host or ''} {m}"
msgs.append(s)
logger.info(s)
if logf:
try:
logf.write(s + "\n")
logf.flush()
except Exception as e:
logger.warning("failed to write to logfile: %s", e)
msg_to_websockets("message", s)
def setup(cfg: dict):
"""Initialize notifier defaults from a configuration dict."""
@@ -160,6 +197,7 @@ def pushmsg(cfg: dict, msg: str, debug: int = 0):
Returns a dict of results per provider.
"""
results = {}
p = cfg.get("pushsrv", "pushover")
if p in ("all", "pushover"):