How to get Monit alerts via Twitter on Brightbox
by James
By default Monit’s alerts arrive via email, but it’s quite easy to configure Monit to send alerts via Twitter instead.
These instructions are based on a Brightbox server, because that’s what I use, but they should work on any *nix server.
Step 1: Dedicated Twitter account
You’ll need a Twitter account dedicated to your Monit alerts (I’ll call this the Monit account): sign up at Twitter.com and skip all the ‘add people’ stuff — this account won’t be very sociable. You also want to make sure that your alerts aren’t visible to the general public, so go to the ‘Settings’ page and check ‘Protect my Tweets’ to make your account private.
Now when someone — a colleague, a fellow developer — follows your Monit account, you’ll be prompted to approve them before then can see your tweets.
Step 2: Follow yourself
Follow your new Monit account from your real Twitter account — you’ll have to approve the follow request, so there’ll probably be a bit of switching between accounts, but you only have to do it once. When you’re done, switch back to your real Twitter account, and you’ll be ready to see Monit alerts in your Twitter feed.
Step 3: Email to Twitter
Monit doesn’t provide a way to send alerts directly to Twitter, but luckily there’s a great service called Twittermail which can convert Monit’s email alerts into tweets.
Sign up for a Twittermail acount using your Monit Twitter account and make sure to opt out of all the extra ‘features’ like auto-follow: you just want a Twittermail email address. Grab the random address from the settings page, under ‘Twittermail’, and save it on your clipboard for later.
Step 4: Configure Monit
SSH into your Brightbox and edit your Monit email alert settings (if you’re using a different host, your config file may be in a different place):
The file should already have a line containing your email address: change this to use your new Twittermail address:
Run sudo monit reload, and you should see a new tweet from Monit — via your Monit Twitter account — in your Twitter feed.
Step 5 (Optional): Configure Monit’s alert messages
I recommend creating a custom short format for Monit’s alert messages — edit the line in /etc/monit/conf.d/email-alerts.monitrc:
Check the Monit docs for message formatting options.