fix logging and notifications

This commit is contained in:
2024-01-10 15:50:35 +01:00
parent 2218107228
commit 3ca6dd468f
5 changed files with 12 additions and 4 deletions

View File

@@ -14,6 +14,7 @@
__all__ = ["Action"]
from copy import deepcopy
from pyquarantine import modify, notify, storage
from pyquarantine.conditions import Conditions
@@ -40,7 +41,7 @@ class Action:
self.conditions = Conditions(self.conditions, local_addrs, debug)
self.action = self.ACTION_TYPES[cfg["type"]](
cfg, local_addrs, debug)
deepcopy(cfg), local_addrs, debug)
def __str__(self):
cfg = []

View File

@@ -302,7 +302,7 @@ def release(cfg, args):
rcpts = quarantine.release(args.quarantine_id, args.recipient)
rcpts = ", ".join(rcpts)
logger.info(
f"{args.quarantine}: released message with id {args.quarantine_id} "
f"{quarantine._storage.name}: released message with id {args.quarantine_id} "
f"for {rcpts}")

View File

@@ -36,7 +36,6 @@ import jsonschema
import logging
import re
class BaseConfig:
JSON_SCHEMA = {
"type": "object",

View File

@@ -317,6 +317,7 @@ class EMailNotification(BaseNotification):
def execute(self, milter, logger):
super().execute(milter, logger)
logger.info(f"send notification(s) to {milter.msginfo['rcpts']}")
self.notify(msg=milter.msg, qid=milter.qid,
mailfrom=milter.msginfo["mailfrom"],
recipients=milter.msginfo["rcpts"],
@@ -330,6 +331,7 @@ class Notify:
def __init__(self, cfg, local_addrs, debug):
self.cfg = cfg
self.name = cfg["name"]
self.logger = logging.getLogger(cfg["name"])
del cfg["name"]
self.logger.setLevel(cfg.get_loglevel(debug))
@@ -351,5 +353,5 @@ class Notify:
def execute(self, milter):
logger = CustomLogger(
self.logger, {"name": self.cfg["name"], "qid": milter.qid})
self.logger, {"name": self.name, "qid": milter.qid})
self._notification.execute(milter, logger)

View File

@@ -406,6 +406,8 @@ class Quarantine:
self.logger = logging.getLogger(cfg["name"])
self.logger.setLevel(cfg.get_loglevel(debug))
name = cfg["options"]["store"]["name"]
cfg["options"]["store"]["name"] = f"{cfg['name']}: {name}"
cfg["options"]["store"]["loglevel"] = cfg["loglevel"]
self._storage = Store(cfg["options"]["store"], local_addrs, debug)
@@ -414,6 +416,8 @@ class Quarantine:
self._notification = None
if "notify" in cfg["options"]:
name = cfg["options"]["notify"]["name"]
cfg["options"]["notify"]["name"] = f"{cfg['name']}: {name}"
cfg["options"]["notify"]["loglevel"] = cfg["loglevel"]
self._notification = Notify(
cfg["options"]["notify"], local_addrs, debug)
@@ -559,6 +563,8 @@ class Quarantine:
if self._milter_action in ["REJECT", "DISCARD"]:
logger.info(f"quarantine message for {rcpts}")
else:
logger.info(f"save message for {rcpts}")
self._storage.execute(milter)