diff --git a/gracedb/alert.py b/gracedb/alert.py index 4626a86cc4175681a25a5cf1162e7335e033528a..95fb51402f9f4ea74fe0cb1bae59890ef51011fd 100644 --- a/gracedb/alert.py +++ b/gracedb/alert.py @@ -147,7 +147,7 @@ def prepareSummary(event): def issueAlertForUpdate(event, description, doxmpp, filename="", serialized_object=None): if doxmpp: issueXMPPAlert(event, filename, "update", description, serialized_object) - # XXX No emails for this. Argh. + # XXX No emails or phone calls for this. Argh. # The only kind of serialized object relevant for a Label is an event. def issueAlertForLabel(event, label, doxmpp, serialized_event=None, event_url=None): @@ -199,18 +199,24 @@ def issueAlertForLabel(event, label, doxmpp, serialized_event=None, event_url=No toaddresses = [] bccaddresses = profileRecips - if toaddresses or bccaddresses: + if settings.SEND_EMAIL_ALERTS and (toaddresses or bccaddresses): if not toaddresses: toaddresses = ["(undisclosed recipients)"] email = EmailMessage(subject, message, fromaddress, toaddresses, bccaddresses) email.send() # Make phone calls. - if phoneRecips: + if settings.SEND_PHONE_ALERTS and phoneRecips: make_twilio_calls(event, phoneRecips, "label", label=label) def issueEmailAlert(event, event_url): + # Check settings switch for turning off email alerts + if not settings.SEND_EMAIL_ALERTS: + log.debug(("Email alert for event {gid} not sent because email alerts " + "are turned off").format(gid=event.graceid())) + return + # The right way of doing this is to make the email alerts filter-able # by search. But this is a low priority dev task. For now, we simply # short-circuit in case this is an MDC event. @@ -264,13 +270,20 @@ Event Summary: email.send() def issuePhoneAlert(event): + + # Check settings switch for turning off phone alerts + if not settings.SEND_PHONE_ALERTS: + log.debug(("Phone alert for event {gid} not sent because phone alerts " + "are turned off").format(gid=event.graceid())) + return + # The right way of doing this is to make the email alerts filter-able # by search. But this is a low priority dev task. For now, we simply # short-circuit in case this is an MDC event. if event.search and event.search.name == 'MDC': return - # Gather Recipients + # Gather recipients phoneRecips = [] if event.group.name != 'Test': pipeline = event.pipeline diff --git a/settings/base.py b/settings/base.py index b780f1ecea4eb278e510b5a48434bc409ab2255b..bfc4fd4d2131ed1e8e8611c920b48ef87feb3104 100644 --- a/settings/base.py +++ b/settings/base.py @@ -40,8 +40,10 @@ ALLOWED_HOSTS = ['localhost', '127.0.0.1', SERVER_FQDN, '{0}.ligo.org'.format(socket.gethostname())] # LVAlert and LVAlert Overseer settings --------------------------------------- -# Set to False to prevent XMPP alerts from being sent out. -SEND_XMPP_ALERTS = True +# Switches which control whether alerts are sent out +SEND_XMPP_ALERTS = False +SEND_PHONE_ALERTS = False +SEND_EMAIL_ALERTS = False # Use LVAlert Overseer? USE_LVALERT_OVERSEER = True # LVAlert servers diff --git a/settings/production.py b/settings/production.py index 92401b60b477fb7196c66dfbe4ca232c1e66aadb..f5d976d5065987684f63bb11f510a153738a05f9 100644 --- a/settings/production.py +++ b/settings/production.py @@ -15,3 +15,8 @@ ALERT_XMPP_SERVERS = ["lvalert.cgca.uwm.edu"] LVALERT_OVERSEER_PORTS = { "lvalert.cgca.uwm.edu": 8000, } + +# Turn on alerts +SEND_XMPP_ALERTS = True +SEND_PHONE_ALERTS = True +SEND_EMAIL_ALERTS = True