Wednesday, August 05, 2009

Twittering your server status

We are very near to launch our new product and I had to write a simple script which will help us monitor few specific services on the production server (linux) without taking too much of processor or memory. This script sends a email when any of the services are down but today I saw that the mail server itself is down, though this script checks for the mail service... it cannot really send a email when the mail server is down... so there is no way for us to know the status of the server when the mail server is down...

I started exploring the possibilities to get a notification on any of the other communication platforms I use, SMS is the ultimate thing but for that you need a sms gateway etc.., The other communication platforms I use are skype, gtalk, twitter and these are accessible on my mobile too... I started researching on sending a ping to gtalk without having any IM client installed on the source server... after trying for an hour, I moved over to twitter considering twitter has an api.

So after searching for couple of mins I found an excellent one liner to send status message from command line to twitter...

Here is the code...

#!/bin/bash
curl -u username:password -d status="$1" http://twitter.com/statuses/update.xml

run this script with message in double quotes... and your twitter will get updated.

So, go ahead create a new twitter account for your server and start twittering your server status.

No comments: