diff --git a/config/sample-development.engine.ini b/config/sample-development.engine.ini index 8a5b7de62ab9cee854fe2134369a6fcdab130e69..2af2907e8d3a948155d53cb05824e3a3c421d54b 100644 --- a/config/sample-development.engine.ini +++ b/config/sample-development.engine.ini @@ -18,16 +18,19 @@ db_charset="utf8" [monitoring] -mail_server="mail.example.com" +mail_server="mail.your-radio.org" mail_server_port="587" mail_user="aura@subsquare.at" mail_pass="---SECRET--PASSWORD---" -# If you want to send multiple adminmails, make them space separated -admin_mail="david@subsquare.at" -# Which from mailadress should be used + +# Set to "true" if you want to notify admins about incidents, otherwise "false" +mail_admin_enabled="true" +# If you want to send multiple admin-mails, make them space separated +admin_mail="admin@your-radio.org" +# The FROM email address used when sending from_mail="monitoring@aura.engine" -# The beginning of the subject. With that you can easily apply filter rules using a mail client -mailsubject_prefix="[Aura Engine]" +# A subject prefix allows applying filter rules in your mail client +mailsubject_prefix="[AURA Engine]" # Server where heartbeat info is sent to heartbeat_server = "127.0.0.1" # Some UDP port @@ -36,9 +39,10 @@ heartbeat_port = 43334 heartbeat_frequency = 1 logdir="/home/username/code/aura/engine/logs" -# possible values: debug, info, warning, error, critical +# Possible values: debug, info, warning, error, critical loglevel="info" + [api] ## STEERING ## diff --git a/config/sample-docker.engine.ini b/config/sample-docker.engine.ini index 5000c16e00cd511df8c75d2c2f7bc4f11db74858..3140e58d5adce193425714f538694d84512592d7 100644 --- a/config/sample-docker.engine.ini +++ b/config/sample-docker.engine.ini @@ -18,27 +18,31 @@ db_charset="utf8" [monitoring] -mail_server="mail.example.com" +mail_server="mail.your-radio.org" mail_server_port="587" mail_user="aura@subsquare.at" mail_pass="---SECRET--PASSWORD---" -# If you want to send multiple adminmails, make them space separated -admin_mail="david@subsquare.at" -# Which from mailadress should be used + +# Set to "true" if you want to notify admins about incidents, otherwise "false" +mail_admin_enabled="true" +# If you want to send multiple admin-mails, make them space separated +admin_mail="admin@your-radio.org" +# The FROM email address used when sending from_mail="monitoring@aura.engine" -# The beginning of the subject. With that you can easily apply filter rules using a mail client -mailsubject_prefix="[Aura Engine]" +# A subject prefix allows applying filter rules in your mail client +mailsubject_prefix="[AURA Engine]" # Server where heartbeat info is sent to -heartbeat_server = "127.0.0.1" +heartbeat_server = "127.0.0.1" # Some UDP port heartbeat_port = 43334 # Seconds how often the vitality of the Engine should be checked (0 = disabled) heartbeat_frequency = 1 -logdir="/srv/logs" +logdir="/home/username/code/aura/engine/logs" # Possible values: debug, info, warning, error, critical loglevel="info" + [api] ## STEERING ## diff --git a/config/sample-production.engine.ini b/config/sample-production.engine.ini index 913629ddf2452a1253e2543e729ede2fca68b8ad..d03e5d490a82dbaae061dc32fddb3c083e71ac34 100644 --- a/config/sample-production.engine.ini +++ b/config/sample-production.engine.ini @@ -18,27 +18,31 @@ db_charset="utf8" [monitoring] -mail_server="mail.example.com" +mail_server="mail.your-radio.org" mail_server_port="587" mail_user="aura@subsquare.at" mail_pass="---SECRET--PASSWORD---" -# If you want to send multiple adminmails, make them space separated -admin_mail="david@subsquare.at" -# Which from mailadress should be used + +# Set to "true" if you want to notify admins about incidents, otherwise "false" +mail_admin_enabled="true" +# If you want to send multiple admin-mails, make them space separated +admin_mail="admin@your-radio.org" +# The FROM email address used when sending from_mail="monitoring@aura.engine" -# The beginning of the subject. With that you can easily apply filter rules using a mail client -mailsubject_prefix="[Aura Engine]" +# A subject prefix allows applying filter rules in your mail client +mailsubject_prefix="[AURA Engine]" # Server where heartbeat info is sent to -heartbeat_server = "127.0.0.1" +heartbeat_server = "127.0.0.1" # Some UDP port heartbeat_port = 43334 # Seconds how often the vitality of the Engine should be checked (0 = disabled) heartbeat_frequency = 1 -logdir="/var/log/aura" -# *ossible values: debug, info, warning, error, critical +logdir="/home/username/code/aura/engine/logs" +# Possible values: debug, info, warning, error, critical loglevel="info" + [api] ## STEERING ## diff --git a/src/plugins/mailer.py b/src/plugins/mailer.py index fba653389709a07b6f2739d0449d714780abc748..75408cff85613729b5fb29f6ee2ca15d25b63a8f 100644 --- a/src/plugins/mailer.py +++ b/src/plugins/mailer.py @@ -17,11 +17,14 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. +import logging import smtplib from email.message import EmailMessage from src.base.config import AuraConfig +from src.base.utils import SimpleUtil as SU + class MailingException(Exception): @@ -35,8 +38,6 @@ class MailingException(Exception): class AuraMailer(): """ Event handler to send emails to Aura administrators and programme coordinators. - - """ engine = None mail = None @@ -92,7 +93,9 @@ class MailService(): Service to send emails to Aura administrators. """ config = None + logger = None admin_mails = None + admin_mails_enabled = None def __init__(self): @@ -100,7 +103,9 @@ class MailService(): Constructor """ self.config = AuraConfig.config() + self.logger = logging.getLogger("AuraEngine") self.admin_mails = self.config.get("admin_mail") + self.admin_mails_enabled = self.config.get("mail_admin_enabled") # @@ -116,6 +121,10 @@ class MailService(): subject (String): The email subject body (String): The email body text """ + if self.admin_mails_enabled == "false": + self.logger.warning(SU.red("No admin mail sent, because doing so is disabled in engine.ini!")) + return False + admin_mails = self.admin_mails.split() for mail_to in admin_mails: