How the Cloud Monitoring team implemented Mailgun to automate monitoring alerts
The team over at Mailgun just posted a case study about how the Rackspace Cloud Monitoring team successfully migrated their email alerts to the Mailgun email automation platform. It's a really interesting read that is as much about how to plan for and deploy 3rd party tools in a production application as it is about using Mailgun to automate and monitor email alerts. <!-- more --> When it comes to Mailgun, the monitoring team implemented Mailgun in their node.js app to dynamically generate and deliver monitoring notifications. These notifications include details about the alert and need to be generated on the fly as soon as an alert is trigged. If you don't head over to the Mailgun blog to read the full post (you should!), here's how the team did it.
During the test, we added code to look at the special [test] account during the Deliver Alert stage to start routing messages to Mailgun. This process was simple because very little code was involved.
Here’s what a snippet looks like:
What’s going on above? First, we call the sendMailgunEmail function to deliver the monitoring notification email. In a quest to measure EVERYTHING, we also measure the time it takes to use the Mailgun API. And there is a series of retries that wraps this code with a fallback option, a best practice when relying on any 3rd-party system in your application.
Want to see how simple the sendMailgunEmail function is?
- The request function abstracts some dealing with complex HTTP requests and handling of response codes, so expectedresponsecodes is used for that.
- Easily deal with sending HTML, which is generally a pain.
- Merge in headers allowing for easy way to enrich emails. These headers allow us to create customized emails for each user with details about their alert like alarmId, checkId, and tenantId. You can pass almost anything to customize your emails in these headers that would just normally clutter the body of the email.
- Easily flip a bit for sending test emails
- User-defined tags allow tracking and analytical faceting used in our production testing scenarios.
Look at how easy this was. We’ve fully automated email creation, delivery, and analytics using Mailgun, something that is difficult with with a traditional DIY setup.
In case you haven't heard, Rackspace customers receive a $19/month credit to use Mailgun. That means that when you signup for the Mailgun standard plan, you can send up to 19,000 emails per month, for free. Email firstname.lastname@example.org for details about how to receive your Mailgun discount.