Host monitoring with Jaiku

A few weeks back, we were having trouble with dogma, our shared server where is hosted, which would occasionally be unavailable for unknown reasons. We needed to monitor its availability so that it could be fixed when it crashed again, and we’d be able to investigate quickly. Since it was happening mostly out of working hours, SMS notification was essential.

Normally, that kind of monitoring is pretty basic stuff, and there’s plenty of services out there, from to the more complex self-hosted apps like monit and Nagios which can do that. But looking around, I found that none of them offered SMS notification for free, and since this was our personal-use server, I wasn’t willing to sign up for a $10-per-month paid account to support it, or buy any hardware to act as a private SMS gateway.

Instead, I thought of Jaiku — the Finnish company which offers a microblogging/presence platform similar to Twitter. Jaiku had a couple of cool features:

  • SMS notifications
  • it’s possible to broadcast messages to a “channel”, which others could subscribe to, IRC-style
  • it has an open API

This would allow me to notify any interested party of dogma’s downtime, allowing subscribers to subscribe and unsubscribe using whatever notification systems Jaiku support.

With a little perl and LWP, I rigged up a quick monitoring script to check via HTTP, and report if it was unavailable over the course of 5 retries in 50 seconds. If it was broken, the script sends a JSON-formatted POST request to Jaiku’s “presence.send” method, informing the target channel of the issue. (Perl source here.)

You can see the ‘#dogmastatus’ channel here — as you can see, we fixed the problem with dogma just over 2 weeks ago ;)

It’s worth noting that I had to set up an additional user, “downtimebot”, on Jaiku to send the messages — otherwise I’d never see them on my configured mobile phone! Jaiku uses the optimisation that, if I sent the message, there’s no need to cc me with a copy of what I just sent; logical enough.

Anyway, if you’re interested in dogma’s availability (there might be one or two readers who are), feel free to add yourself to the #dogmastatus channel and receive any updates.

Update: Fergal noted that it’s pretty simple to use Cape Clear’s assembly framework to perform a HTTP ping test with output to Jabber/XMPP. nifty!

This entry was posted in Uncategorized and tagged , , , , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.


  1. Posted July 25, 2007 at 09:28 | Permalink

    After managing to config nagios for monitoring, procmail can forward emails via mackers o2sms/vodasms etc.: :0 c * ^From: .*[email protected] | formail -x Subject: | vodasms your_mobile_no > /dev/null

    Of course, the question is where to run the monitoring script/app. Where did you manage to put the monitoring script for

    Thanks for the info. Might give it a try. -steve

  2. Posted July 25, 2007 at 15:32 | Permalink

    I ran it on the spamassassin spamtraps server — 800 days uptime ;)

  3. Posted July 25, 2007 at 17:47 | Permalink

    And here is your perl-script, modified to do the same thing using twitter:

    #!/usr/bin/perl -w
    use vars qw($login $passwd);
    require $ENV{HOME}.'/';
    die q{
    usage: ( --test | http://site.url/ )
    Also needs a ~/ like this:
    } unless ($ARGV[0] && $login && $passwd);
    use LWP::UserAgent;
    use LWP::Simple;
    use HTTP::Request::Common qw(POST);
    use URI::Escape;
    use strict;
    use bytes;
    my $debug = 0;
    if ($ARGV[0] eq '--test') {
    # my $chan = $ARGV[1];
    my $url = $ARGV[0];
    my $msg = check_url($url);
    if ($msg) {
    sub dbg {
      $debug and print "dbg: ".$_[0]."\n";
    sub check_url {
      my $url = shift;
      for my $retries (1 .. 5) {
        if (head($url)) {
          dbg "HEAD $url is fine";
          return;           # all fine
        dbg "HEAD $url failed; retrying ($retries)";
        ($retries new;
      for my $retries (1 .. 3) {
        my $req = POST 'http://'.$login.':'.$passwd.'', [
              status => $msg
        my $resp = $ua->request($req);
        my $status = $resp->status_line;
        if ($resp->is_error){
            warn "POST failed with error: $status";
          dbg "POST to twitter of '$msg' is ok";
          return 1;
      warn "POST failed too many times, giving up on '$msg'";
      return 0;
  4. Posted July 25, 2007 at 18:39 | Permalink

    Stefan: cool!

    Only thing is, twitter doesn’t have the “channel” group-broadcast feature — but I guess interested parties can simply subscribe to the “downtimebot” user or whatever.

  5. Posted July 26, 2007 at 08:44 | Permalink

    @Justin: yes, simply subscribe to the bot’s feed. I have my bot set to protect the posts, so they don’t pollute the “public” timeline…

    Now, we’d just have to find some spare time to improve the script so it doesn’t permanently send messages if a host is already known to be down – and then also send a message if a host comes back up ;-)

  6. Posted July 26, 2007 at 14:44 | Permalink

    OK, i spared some time and improved the script so it remembers hosts that are down and can now also notify you once a host comes back up again. The .cf file changed so you can define a list of hosts in it together with a label for each host. The alerts sent to twitter will now contain only the labels and not the full URLs to save on text length and provide better readability. If you want it, the script lives here.

  7. Posted June 5, 2009 at 16:10 | Permalink

    Hey I did something very similar the other day but with a ping test on my local network with alerts sent via SMS – I didn’t use Jaiku or Twitter as both no longer provide SMS to UK citizens – I used Facebook – Check it out on my new blog