Here at AppJet, we need to get text (SMS) alerts on our phones when one of our servers goes down. One way to programmatically send text alerts is to use free email-to-text gateways. For example, <number>@txt.att.net will send a text to <number> on the AT&T network. Unfortunately, these email-to-text gateways can delay messages by 15 minutes or more, and sometimes even drop them entirely.

Brainstorming other ways to send text messages, I thought, why not use Twitter as a text gateway?

  • Step 1: Create a twitter "alert account" for your alerts.
  • Step 2: Hook up your "is it down?" script to send status updates your new twitter account.
  • Step 3: Follow your alert account with your own twitter account, and configure it to send tweets straight to your phone.

Twitter has a web API, making it easy to tweet. You can even get libraries for common languages (we use Winterwell's jtwitter.jar) so you don't have to do raw HTTP gets and puts. And once your alert script is tweeting, you can configure your own account to receive updates by text. It's four out of four for fast, easy, free, and reliable. As reliable as twitter is, anyway, which is good these days.

Easy, right? That said, there are a few issues to keep in mind.

First, if you're like us, you'll want to receive texts frequently while your service is down, just in case you don't hear your phone the first time. But setting your alert account's status to the same string as the previous status doesn't trigger an update, and you won't get a new alert. If you want to get lots of tweets, add something that changes to your tweets. We added a counter, which also has the benefit of giving us an instant sense for how long the alert's been ringing.

Second, twitter limits tweets to 140 characters, so you'll have to keep your alert message short. For us, this isn't a big problem: on rare occasions where we want to send more data, we usually just send an accompanying email with anything extra.

Third, your alerts will only be as reliable as twitter is. You'll want some kind of backup mechanism so that you're still being notified even if twitter either has downtime or delays your messages. We use email for this purpose. It's true, email won't wake you up in the middle of the night, but at least if it's daytime and you're in front of a computer, you won't be blithely ignorant.

Fourth and last, your alerts will show up in twitter searches by default. Depending on how open your company is, you may want to disable that. Oh, and you may not want just anyone following your alert account, but you can configure that too.

-J.D.

blog comments powered by Disqus