2017-12-16 18:59:33 +01:00
|
|
|
|
# pyruse is intended as a replacement to both fail2ban and epylog
|
2018-01-31 13:07:05 +01:00
|
|
|
|
# Copyright © 2017–2018 Y. Gablin
|
2017-12-16 18:59:33 +01:00
|
|
|
|
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
|
2017-12-15 19:36:50 +01:00
|
|
|
|
import string
|
|
|
|
|
from pyruse import base, email
|
|
|
|
|
|
|
|
|
|
class Action(base.Action):
|
|
|
|
|
def __init__(self, args):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.subject = args.get("subject", "Pyruse Notification")
|
|
|
|
|
self.template = args["message"]
|
|
|
|
|
values = {}
|
|
|
|
|
for (_void, name, _void, _void) in string.Formatter().parse(self.template):
|
|
|
|
|
if name:
|
|
|
|
|
values[name] = None
|
|
|
|
|
self.values = values
|
|
|
|
|
|
|
|
|
|
def act(self, entry):
|
|
|
|
|
for (name, _void) in self.values.items():
|
|
|
|
|
self.values[name] = entry.get(name, None)
|
|
|
|
|
msg = self.template.format_map(self.values)
|
|
|
|
|
email.Mail(msg).setSubject(self.subject).send()
|