Stefan Strigler's Jabber server monitor script

Download, Add a comment, Back to main page
[Mon 08:38] flickefly (www) (email) This would make a neat start for a little web-based administration kinda thing.
[Mon 09:14] Stefan Strigler (email) This script is primarly meant to be used with mon a software monitoring tool which can be found at http://www.kernel.org/software/mon/.
Sure you can use it as a standalone script too.

Returns "0" on succes, "1" on error (if an error occurs detailed error messages are printed to stdout)
[Wed 02:14] Stefan Strigler (email) forgot to mention that you need to have Jabber::Connection (a Perl module) installed, which you can get from CPAN.


#!/usr/bin/perl
#
# Use try to connect to a jabber server.
# For use with "mon".
#
# jabber.monitor [-p port] host [host...]
#
#    -p port       TCP port to connect to (defaults to 5222)
#
# written by Stefan Strigler <steve@fxb.de> for fxb GbR (http://fxb.de)
#
# based on http.monitor from
#
# Jon Meek
# American Cyanamid Company
# Princeton, NJ
#
#    Copyright (C) 1998, Jim Trocki
#    Copyright (C) 2003, Stefan Strigler <steve@fxb.de>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
use Getopt::Std;
use English;
use Data::Dumper;

sub httpGET;

getopts ("p:");
$PORT = $opt_p || 5222;

my %good;
my %bad;

exit 0 if (!@ARGV);

foreach my $host (@ARGV) {
    my $result = jabberConnect ($host, $PORT);

    if (!$result->{"ok"}) {
    	$bad{$host} = $result;
    } else {
    	$good{$host} = $result;
    }
}

my $ret;

if (keys %bad) {
    $ret = 1;
    print join (" ", sort keys %bad), "\n";
} else {
    $ret = 0;
    print "\n";
}

foreach my $h (keys %bad) {
    print "HOST $h: $bad{$h}->{error}\n";
    print "\n";
}

exit $ret;

sub jabberConnect {
	use Jabber::Connection;
	my ($host, $port) = @_;
	my $con = new Jabber::Connection(server => "$host:$port");

	return { ok => 0, error => $con->lastError()} unless ($con->connect());
	
	$con->disconnect();

	return {
		ok => 1, 
		error => undef,
		};
}