I have a QNAP NAS (TS-212) which runs a variety of jobs for me, most notably all my backups to external USB drive(s) and other assorted tasks: I often find myself `tailing` logs to check they ran without issues – this works, but it’s tedious and error conditions (eg, a malfunctioning disk) may go unnoticed for days.
As the QNAP can run Python, I decided to write a simple script, using Mandrill Email API to send me an alert should anything go awry.
The code was pretty straightforward, and there are a number of niceties that could be added (most notably, the use of Jinja templates for the HTML body) – however, what I knocked together in a couple of hours’ evening coding I thought was good enough to share to others who may have the same need.
Github Gist: Python Email alerts via Mandril Email API
Remember to install Mandrill’s Python SDK:
pip install mandrill
To run the script, simply use:
$ ./alert.py -f ./.mandrill -m "This is a test" -d email@example.com -s "Test Test Test"
to see all the options use “
$ ./alert.py --help
and to see logs (to stdout) use the “-v“ option:
$ ./alert.py -f ./.mandrill -m "This is a test" -d firstname.lastname@example.org -s "Test" -v
Leave a Reply