[prev in list] [next in list] [prev in thread] [next in thread]
List: mon
Subject: first cut at ssl pop3/imap monitors
From: Matthew Galgoci <mgalgoci () redhat ! com>
Date: 2002-03-07 3:20:56
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
Hi Folks,
Here is my first pass at monitor scripts for spop3/simap. Please poke them with a stick
and tell me what you think.
They require Net::SSLeay.
Thanks,
Matt Galgoci
--
["spop3.monitor" (text/plain)]
#!/usr/bin/perl
#
# Use try to connect to a SSL POP-3 server, and
# wait for the right output.
#
# For use with "mon".
#
# Arguments are "-p port -t timeout host [host...]"
#
# Adapted from pop3.monitor by
# Matt Galgoci, mgalgoci@redhat.com
#
# Adapted from "http.monitor" by
# Jim Trocki, trockij@transmeta.com
#
# http.monitor written by
#
# Jon Meek
# American Cyanamid Company
# Princeton, NJ
#
# $Id: spop3.monitor 1.2 Sun, 14 Jan 2001 17:57:39 -0800 trockij $
#
# Copyright (C) 1998, Jim Trocki
#
# 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;
getopts ("p:t:");
$PORT = $opt_p || 995;
$TIMEOUT = $opt_t || 30;
@failures = ();
foreach $host (@ARGV) {
if ( ! &spop3GET($host, $PORT) ) {
push (@failures, $host);
}
}
if ( @failures == 0 ) {
exit 0;
}
print "@failures\n";
exit 1;
sub spop3GET {
use Net::SSLeay;
my($Server, $Port) = @_;
my($ServerOK, $TheContent);
$ServerOK = 0;
$TheContent = '';
###############################################################
eval {
local $SIG{ALRM} = sub { die "Timeout Alarm" };
alarm $TIMEOUT;
$result = &Net::SSLeay::open_tcp_connection($Server, $Port); # Open a connection to the server
if ($result == 0) { # Failure to open the socket
return 0;
}
$in = <S>;
if ($in !~ /^\+OK/) {
alarm 0;
}
print S "quit\r\n";
while (defined($in=<S>)) {
if ($in !~ /^\+OK/) {
print S "quit\r\n";
last;
$ServerOK = 0;
}
}
$ServerOK = 1;
close(S);
alarm 0; # Cancel the alarm
};
if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) {
print "**** Time Out\n";
return 0;
}
return $ServerOK;
}
["simap.monitor" (text/plain)]
#!/usr/bin/perl
#
# Use try to connect to a SSL IMAP server, and
# wait for the right output.
#
# For use with "mon".
#
# Arguments are "-p port -t timeout host [host...]"
#
# Adapted from imap.monitor by
# Matt Galgoci, mgalgoci@redhat.com
#
# Adapted from "http.monitor" by
# Jim Trocki, trockij@transmeta.com
#
# http.monitor written by
#
# Jon Meek
# American Cyanamid Company
# Princeton, NJ
#
# $Id: simap.monitor 1.2 Sun, 14 Jan 2001 17:57:39 -0800 trockij $
#
# Copyright (C) 1998, Jim Trocki
#
# 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;
getopts ("p:t:");
$PORT = $opt_p || 993;
$TIMEOUT = $opt_t || 30;
@failures = ();
foreach $host (@ARGV) {
if ( ! &simapGET($host, $PORT) ) {
push (@failures, $host);
}
}
if ( @failures == 0 ) {
exit 0;
}
print "@failures\n";
exit 1;
sub simapGET {
use Net::SSLeay;
my($Server, $Port) = @_;
my($ServerOK, $TheContent);
$ServerOK = 0;
$TheContent = '';
###############################################################
eval {
local $SIG{ALRM} = sub { die "Timeout Alarm" };
alarm $TIMEOUT;
$result = &Net::SSLeay::open_tcp_connection($Server, $Port); # Open a connection to the server
if ($result == 0) { # Failure to open the socket
return 0;
}
$in = <S>;
if ($in !~ /^\* (OK|PREAUTH|BYE)/) {
alarm 0;
}
print S "A1 LOGOUT\r\n";
while (defined($in=<S>)) {
if ($in !~ /^\* (OK|PREAUTH|BYE)/) {
print S "A1 LOGOUT\r\n";
last;
$ServerOK = 0;
}
}
$ServerOK = 1;
close(S);
alarm 0; # Cancel the alarm
};
if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) {
print "**** Time Out\n";
return 0;
}
return $ServerOK;
}
[Attachment #7 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic