Skip to content

Sends Redash query results via email as CSV attachment.

License

Notifications You must be signed in to change notification settings

MoveOnOrg/redash-emailer

Repository files navigation

Redash Emailer

This script fetches Redash query results and sends them via email as CSV attachment.

Setting up your pyenv virtual environment for local development on MacOS

  • You only need to run this once for this repository on your machine:
    • Follow the steps described in our Notion docs for setting up pyenv on MacOS for development here, make sure you follow step 3 (Setting up repositories with pyenv) with Python 3.12.
    • Confirm that this worked by checking that this command outputs a correct venv path echo $VIRTUAL_ENV
    • If the command above doesn't yield any output, then something is not configured correctly, so you will need to get help from another tech team member.
  • Run pip install -r requirements.txt
  • Ensure you have a development AWS credential set up, preferably with aws-vault.
  • Additional setup required for new triggers:
    • Each query id needs a corresponding secrets manager entry. Add it to the redash-emailer secret:
      • key: {query number}_REDASH_QUERY_KEY
      • value: {Redash query API key}
    • The Redash query needs to set to a recurring schedule so that the values are refreshed. This repo only grabs the last results, but it doesn't refresh the data on-demand.
  • See the test event in the AWS console.
  • You can also test the script manually using Query 13032 and your email address. Query 13032 does not return any sensitive data:
python redash_emailer.py --query_id 13032 --to '<your-email-here>' --from '<your-email-here>'
  • Run python redash_emailer.py -h to get input options.

Recipient

You can set the recipient with either --to on the command line, or TO_ADDRESS in settings.py. In either case, if the recipient value is not an email address (containing @), it will be assumed to be the name of a column in the Redash query results, and that column must contain email addresses. This allows more complex workflows in which the query itself determines who receives which records.

About

Sends Redash query results via email as CSV attachment.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages