Alerter is a decorator that converts a function into an e-mail notifier about errors. This is meant to be an easy way to implement custom state based alerts.
Alerter uses Fibonacci to determine the next time to send an alert, and keeps processes that enter bad states from flooding your inbox.
Update Config.py.example
with your configuration parameters. Rename this file Config.py
and move it into the src
directory.
Config.py
notification_emails = [
'[email protected]'
]
email_user = 'gmailuser'
email_password = 'gmailpassword'
default_directory = 'directory where logs will be saved'
slack_endpoint = 'post endpoint for slack webhook'
The function that alerter decorates must return a tuple (bool, string): bool - whether or not an alert should be sent. string - the message to be sent along with the alert.
from Alerter import alerter
@alerter(name='passing_alert', path='~/')
def passing_alert():
return (False, '')
@alerter(name='failing_alert', path='~/')
def failing_alert():
return (True, 'This alert is sent because a failure criteria is met.')
# this alert will send an exception indicating the alert itself has failed.
@alerter(name='exception_alert', path='~/')
def exception_alert():
return 1/0
Will work out of the box with Slack. Go to: https://api.slack.com/incoming-webhooks to configure.