Just a bot that returns the current number of connections to the server, the free diskspace and the uptime
Uses Jabber::Bot (which uses xmpp-simple).

It is pretty hardcoded for my own jabber server, but maybe somebody can get something out of it

#!/usr/bin/env ruby require 'rubygems' require 'jabber/bot'

  1. Create a public Jabber::Bot
    bot = Jabber::Bot.new(
    :jabber_id => ‘[email protected]/ressource',
    :password => ‘pass',
    :master => ‘[email protected]',
    :is_public => true
    )

bot.add_command(
:syntax => ‘cons',
:description => ‘Will return messi stats',
:regex => /^cons$/,
:is_public => true
) {
connections = `netstat -an | grep 52223 | grep ESTABLISHED | wc -l`.to_i
bots = 9
usercon = connections – bots*2
"At the moment there are " + usercon.to_s + " jabber users connected to messi"
}

bot.add_command(
:syntax => ‘uptime',
:description => ‘Will return the uptime of the server',
:regex => /^uptime$/,
:is_public => true
) { `uptime`.chomp! }

bot.add_command(
:syntax => ‘free',
:description => ‘Will return the amount of space left on the harddisc',
:regex => /^free$/,
:is_public => true
) { `df -h | grep ‘sda1' | awk ‘{ print $1 ": Vorhanden: " $2 ". Benutzt " $3 }'`.chomp! }

#Bring the bot to life
bot.connect

Comments