mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 17:38:54 +00:00
Merge pull request #1215 from getredash/fix/alert_email
Fix: email alerts not working
This commit is contained in:
commit
061783313a
@ -24,7 +24,11 @@ class Email(BaseDestination):
|
|||||||
return 'fa-envelope'
|
return 'fa-envelope'
|
||||||
|
|
||||||
def notify(self, alert, query, user, new_state, app, host, options):
|
def notify(self, alert, query, user, new_state, app, host, options):
|
||||||
recipients = [email for email in options.get('addresses').split(',') if email]
|
recipients = [email for email in options.get('addresses', '').split(',') if email]
|
||||||
|
|
||||||
|
if not recipients:
|
||||||
|
logging.warning("No emails given. Skipping send.")
|
||||||
|
|
||||||
html = """
|
html = """
|
||||||
Check <a href="{host}/alerts/{alert_id}">alert</a> / check <a href="{host}/queries/{query_id}">query</a>.
|
Check <a href="{host}/alerts/{alert_id}">alert</a> / check <a href="{host}/queries/{query_id}">query</a>.
|
||||||
""".format(host=host, alert_id=alert.id, query_id=query.id)
|
""".format(host=host, alert_id=alert.id, query_id=query.id)
|
||||||
@ -39,6 +43,6 @@ class Email(BaseDestination):
|
|||||||
)
|
)
|
||||||
mail.send(message)
|
mail.send(message)
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("mail send ERROR.")
|
logging.exception("Mail send error.")
|
||||||
|
|
||||||
register(Email)
|
register(Email)
|
||||||
|
@ -1189,12 +1189,11 @@ class AlertSubscription(ModelTimestampsMixin, BaseModel):
|
|||||||
app, host)
|
app, host)
|
||||||
else:
|
else:
|
||||||
# User email subscription, so create an email destination object
|
# User email subscription, so create an email destination object
|
||||||
config = {'email': self.user.email}
|
config = {'addresses': self.user.email}
|
||||||
schema = get_configuration_schema_for_destination_type('email')
|
schema = get_configuration_schema_for_destination_type('email')
|
||||||
options = ConfigurationContainer(json.dumps(config), schema)
|
options = ConfigurationContainer(config, schema)
|
||||||
destination = get_destination('email', options)
|
destination = get_destination('email', options)
|
||||||
return destination.notify(alert, query, user, new_state,
|
return destination.notify(alert, query, user, new_state, app, host, options)
|
||||||
app, host, options)
|
|
||||||
|
|
||||||
|
|
||||||
all_models = (Organization, Group, DataSource, DataSourceGroup, User, QueryResult, Query, Alert, Dashboard, Visualization, Widget, Event, NotificationDestination, AlertSubscription, ApiKey)
|
all_models = (Organization, Group, DataSource, DataSourceGroup, User, QueryResult, Query, Alert, Dashboard, Visualization, Widget, Event, NotificationDestination, AlertSubscription, ApiKey)
|
||||||
|
@ -42,5 +42,5 @@ def check_alerts_for_query(query_id):
|
|||||||
try:
|
try:
|
||||||
subscription.notify(alert, query, subscription.user, new_state, app, host)
|
subscription.notify(alert, query, subscription.user, new_state, app, host)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warn("Exception: {}".format(e))
|
logger.exception("Error with processing destination")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user