1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#!/usr/bin/perl -w
#
# Perl Script to Check the SystemDaemon to see if things are
# doing okay..
#
# $Id: check-system.pl 2683 2004-02-18 09:18:27Z gsmet $
#
use IO::Socket;
use Fcntl;
use strict;
my ($problem, $host, $port, $pagemsg);
$host = 'monitor.sourceforge.net';
$port = '10000';
#$errormsg = '';
my @pass1 = &check_monitor;
my @pass2 = &check_monitor;
# now run through the two and see if there are any
# matching results. If so we need to send a page.
foreach (@pass1) {
# it was in both.. push it into $pagemsg
if (grep("/$_/", @pass2)) {
$pagemsg .= "$_\n";
}
}
if ($pagemsg) {
system("echo \"$pagemsg\" | mail admin-pager\@sourceforge.net -s SF-ALERT");
}
sub check_monitor {
my ($sock, $bigbuf, $buf, $time, $hostname, $garbage, $service, @errormsg, @response);
$sock = IO::Socket::INET->new(PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => 2,
Type => SOCK_STREAM() );
# Ooops.. we weren't able to open a socket to the monitor server.
# something bad happened.. lets send a page and exit.
if (!$sock) {
system('echo "Monitor Fragged!" | mail admin-pager\@sourceforge.net -s SF-ALERT');
die;
}
# set the socket to be nonblocking.
fcntl($sock, F_SETFL(), fcntl($sock, F_GETFL(), 0) | O_NONBLOCK()) || die "Unable to make socket non-blocking: $!";
$time = time();
# read from the socket for 10 seconds.
while ($time+10 > time()) {
$sock->recv($buf, 2048, 0);
$bigbuf .= $buf;
}
$sock->close();
@response = split("\n", $bigbuf);
# lets see what we got back...
foreach (@response) {
# uh-oh.. something failed.. let see what it was..
if (/FAILED/) {
($garbage, $service, $garbage, $hostname) = split(' ', $_);
# $errormsg .= "$hostname $service\n";
push @errormsg, "$hostname $service";
}
}
return @errormsg;
}
|