fix logging and notifications
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
__all__ = ["Action"]
|
__all__ = ["Action"]
|
||||||
|
|
||||||
|
from copy import deepcopy
|
||||||
from pyquarantine import modify, notify, storage
|
from pyquarantine import modify, notify, storage
|
||||||
from pyquarantine.conditions import Conditions
|
from pyquarantine.conditions import Conditions
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ class Action:
|
|||||||
self.conditions = Conditions(self.conditions, local_addrs, debug)
|
self.conditions = Conditions(self.conditions, local_addrs, debug)
|
||||||
|
|
||||||
self.action = self.ACTION_TYPES[cfg["type"]](
|
self.action = self.ACTION_TYPES[cfg["type"]](
|
||||||
cfg, local_addrs, debug)
|
deepcopy(cfg), local_addrs, debug)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
cfg = []
|
cfg = []
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ def release(cfg, args):
|
|||||||
rcpts = quarantine.release(args.quarantine_id, args.recipient)
|
rcpts = quarantine.release(args.quarantine_id, args.recipient)
|
||||||
rcpts = ", ".join(rcpts)
|
rcpts = ", ".join(rcpts)
|
||||||
logger.info(
|
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}")
|
f"for {rcpts}")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import jsonschema
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
class BaseConfig:
|
class BaseConfig:
|
||||||
JSON_SCHEMA = {
|
JSON_SCHEMA = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|||||||
@@ -317,6 +317,7 @@ class EMailNotification(BaseNotification):
|
|||||||
def execute(self, milter, logger):
|
def execute(self, milter, logger):
|
||||||
super().execute(milter, logger)
|
super().execute(milter, logger)
|
||||||
|
|
||||||
|
logger.info(f"send notification(s) to {milter.msginfo['rcpts']}")
|
||||||
self.notify(msg=milter.msg, qid=milter.qid,
|
self.notify(msg=milter.msg, qid=milter.qid,
|
||||||
mailfrom=milter.msginfo["mailfrom"],
|
mailfrom=milter.msginfo["mailfrom"],
|
||||||
recipients=milter.msginfo["rcpts"],
|
recipients=milter.msginfo["rcpts"],
|
||||||
@@ -330,6 +331,7 @@ class Notify:
|
|||||||
|
|
||||||
def __init__(self, cfg, local_addrs, debug):
|
def __init__(self, cfg, local_addrs, debug):
|
||||||
self.cfg = cfg
|
self.cfg = cfg
|
||||||
|
self.name = cfg["name"]
|
||||||
self.logger = logging.getLogger(cfg["name"])
|
self.logger = logging.getLogger(cfg["name"])
|
||||||
del cfg["name"]
|
del cfg["name"]
|
||||||
self.logger.setLevel(cfg.get_loglevel(debug))
|
self.logger.setLevel(cfg.get_loglevel(debug))
|
||||||
@@ -351,5 +353,5 @@ class Notify:
|
|||||||
|
|
||||||
def execute(self, milter):
|
def execute(self, milter):
|
||||||
logger = CustomLogger(
|
logger = CustomLogger(
|
||||||
self.logger, {"name": self.cfg["name"], "qid": milter.qid})
|
self.logger, {"name": self.name, "qid": milter.qid})
|
||||||
self._notification.execute(milter, logger)
|
self._notification.execute(milter, logger)
|
||||||
|
|||||||
@@ -406,6 +406,8 @@ class Quarantine:
|
|||||||
self.logger = logging.getLogger(cfg["name"])
|
self.logger = logging.getLogger(cfg["name"])
|
||||||
self.logger.setLevel(cfg.get_loglevel(debug))
|
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"]
|
cfg["options"]["store"]["loglevel"] = cfg["loglevel"]
|
||||||
self._storage = Store(cfg["options"]["store"], local_addrs, debug)
|
self._storage = Store(cfg["options"]["store"], local_addrs, debug)
|
||||||
|
|
||||||
@@ -414,6 +416,8 @@ class Quarantine:
|
|||||||
|
|
||||||
self._notification = None
|
self._notification = None
|
||||||
if "notify" in cfg["options"]:
|
if "notify" in cfg["options"]:
|
||||||
|
name = cfg["options"]["notify"]["name"]
|
||||||
|
cfg["options"]["notify"]["name"] = f"{cfg['name']}: {name}"
|
||||||
cfg["options"]["notify"]["loglevel"] = cfg["loglevel"]
|
cfg["options"]["notify"]["loglevel"] = cfg["loglevel"]
|
||||||
self._notification = Notify(
|
self._notification = Notify(
|
||||||
cfg["options"]["notify"], local_addrs, debug)
|
cfg["options"]["notify"], local_addrs, debug)
|
||||||
@@ -559,6 +563,8 @@ class Quarantine:
|
|||||||
|
|
||||||
if self._milter_action in ["REJECT", "DISCARD"]:
|
if self._milter_action in ["REJECT", "DISCARD"]:
|
||||||
logger.info(f"quarantine message for {rcpts}")
|
logger.info(f"quarantine message for {rcpts}")
|
||||||
|
else:
|
||||||
|
logger.info(f"save message for {rcpts}")
|
||||||
|
|
||||||
self._storage.execute(milter)
|
self._storage.execute(milter)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user