[Mon-commit] mon/mon.d imap.monitor,1.2,1.3
Brought to you by:
trockij
From: David N. <vi...@us...> - 2005-08-20 15:28:04
|
Update of /cvsroot/mon/mon/mon.d In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22088 Modified Files: imap.monitor Log Message: Added support for examining a mailbox and erroring if unable to do so. Index: imap.monitor =================================================================== RCS file: /cvsroot/mon/mon/mon.d/imap.monitor,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** imap.monitor 17 Apr 2005 07:42:27 -0000 1.2 --- imap.monitor 20 Aug 2005 15:27:56 -0000 1.3 *************** *** 9,13 **** # # Adapted from "http.monitor" by ! # Jim Trocki, tr...@ar... # # http.monitor written by --- 9,13 ---- # # Adapted from "http.monitor" by ! # Jim Trocki, tr...@tr... # # http.monitor written by *************** *** 38,44 **** use English; ! getopts ("p:t:"); $PORT = $opt_p || 143; $TIMEOUT = $opt_t || 30; @failures = (); --- 38,45 ---- use English; ! getopts ("m:p:t:"); $PORT = $opt_p || 143; $TIMEOUT = $opt_t || 30; + $MAILBOX=$opt_m || undef; @failures = (); *************** *** 55,60 **** } ! print join (" ", sort @failures), "\n"; ! print sort @details if (scalar @details) > 0; exit 1; --- 56,60 ---- } ! print join (" ", sort @failures), "\n\n", join ("\n", @longerr), "\n"; exit 1; *************** *** 66,70 **** my($Server, $Port) = @_; ! my($ServerOK, $TheContent); $ServerOK = 0; --- 66,70 ---- my($Server, $Port) = @_; ! my($ServerOK, $TheContent, $cmd); $ServerOK = 0; *************** *** 81,84 **** --- 81,85 ---- $result = &OpenSocket($Server, $Port); # Open a connection to the server if ($result == 0) { # Failure to open the socket + push @longerr, "$Server: Unable to connect"; return ''; } *************** *** 87,103 **** if ($in !~ /^\* (OK|PREAUTH|BYE)/) { alarm 0; return 0; } ! print S "A1 LOGOUT\r\n"; while (defined($in=<S>)) { ! if ($in =~ /^A1 OK/) { last; - $ServerOK = 0; } } - $ServerOK = 1; close(S); --- 88,150 ---- if ($in !~ /^\* (OK|PREAUTH|BYE)/) { alarm 0; + push @longerr, "$Server: No IMAP banner received"; return 0; } ! $cmd="login"; ! print S "A1 LOGIN ANONYMOUS ANONYMOUS\r\n"; while (defined($in=<S>)) { ! if ($in =~ /^A1 (\w+) (.*)/) { ! if ($1 eq "OK") { ! $ServerOK = 1; ! } else { ! $errmsg="$1 $2"; ! } last; } } + + if ($ServerOK && $MAILBOX) { + $cmd="examine"; + $ServerOK=0; + print S "A2 EXAMINE $MAILBOX\r\n"; + + while (defined($in=<S>)) { + if ($in =~ /^A2 (\w+) (.*)/) { + if ($1 eq "OK") { + $ServerOK = 1; + } else { + $errmsg="$1 $2"; + } + last; + } + } + } + + if ($ServerOK) { + $cmd="logout"; + $ServerOK=0; + print S "A3 LOGOUT\r\n"; + + while (defined($in=<S>)) { + if ($in =~ /^A3 (\w+) (.*)/) { + if ($1 eq "OK") { + $ServerOK = 1; + } else { + $errmsg="$1 $2"; + } + last; + } + } + } + if (!$ServerOK) { + if ($errmsg) { + push @longerr, "$Server: bad response to $cmd: $errmsg"; + } else { + push @longerr, "$Server: No response to $cmd"; + } + } close(S); *************** *** 107,112 **** if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { ! push(@details, "$host: timeout($TIMEOUT)\n"); return 0; } return $ServerOK; --- 154,162 ---- if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { ! push @longerr, "$Server: **** Time Out\n"; return 0; + } elsif ($EVAL_ERROR) { + push @longerr, "$Server: $EVAL_ERROR"; + return 0; } return $ServerOK; *************** *** 129,146 **** ($name, $aliases, $type, $len, $OtherHostAddr) = gethostbyname($OtherHostname); - if (!defined $OtherHostAddr) - { - push (@details, "$host: cannot resolve hostname\n"); - return undef; - } - my $that = sockaddr_in ($Port, $OtherHostAddr); ! if (! ($result = socket(S, &PF_INET, &SOCK_STREAM, $proto)) || ! (! ($result = connect(S, $that))) ) ! { ! push (@details, "$host: $!\n"); ! return undef; ! } select(S); $| = 1; select(STDOUT); # set S to be un-buffered --- 179,187 ---- ($name, $aliases, $type, $len, $OtherHostAddr) = gethostbyname($OtherHostname); my $that = sockaddr_in ($Port, $OtherHostAddr); ! $result = socket(S, &PF_INET, &SOCK_STREAM, $proto) || return undef; ! ! $result = connect(S, $that) || return undef; select(S); $| = 1; select(STDOUT); # set S to be un-buffered |