--- check_pop3.pl 2004-01-05 16:43:27.000000000 -0600 +++ /home/jason/sf/nagiosplug/contrib/check_pop3.pl 2002-02-28 00:42:53.000000000 -0600 @@ -23,29 +23,6 @@ # with perl -wT and 'use strict' # 2000/01/20 RM Corrected POP3 Exit State. # 2000/01/21 RM Fix Exit Codes Again!! -# 2003/12/30 CZ Proper CRLF in communication w/server -# Fixed infinite loop -# Error checking on welcome banner, USER, PASS commands -# Better error condition handling -# This could probably be much much smaller using Net::POP3, -# but I haven't looked into its error conditions yet, and I -# don't think you can specify remote port. - -=cut - -use Net::POP3; - -my $pop = new Net::POP3("$ARGV[0]", Timeout => 60); -my $ret = $pop->login("$ARGV[1]","$ARGV[2]"); -$pop->quit(); - -do { print "some error msg\n"; exit 2; } unless defined $ret; - -print "POP3 OK - ".int($ret)." messages\n"; -exit 0; - -=cut - # ------------------------------------------------------------------------------ # -----------------------------------------------------------------[ Require ]-- @@ -120,56 +97,47 @@ my $ClientSocket = &bindRemote($remotehost,$remoteport,$hostname); - err("no welcome banner\n") unless $_ = ; - err("bad welcome banner: " . $_) unless $_ =~ /^\+OK/; +print ClientSocket "user $username\n"; - print ClientSocket "USER $username\r\n"; +#Debug Server +#print "user $username\n"; - #Debug Server - #print "user $username\n"; +#Sleep or 3 secs, incase server is slow. +sleep 3; - err("no response to USER command\n") unless $_ = ; - err("bad response to USER: " . $_) unless $_ =~ /^\+OK/; +print ClientSocket "pass $password\n"; - print ClientSocket "PASS $password\r\n"; +#Debug Server +#print "pass $password\n"; - #Debug Server - #print "pass $password\n"; +while () { - err("no response to PASS command\n") unless $_ = ; - err("bad response to PASS: " . $_) unless $_ =~ /^\+OK/; +print ClientSocket "pass $password\n"; - print ClientSocket "LIST\r\n"; +#Debug Server +#print $_; - my $bad = 1; - my $msgs = 0; - while () { - #Debug Server - #print $_; - - err(($1||' UNKNOWN')."\n") if (m/\-ERR(.*)/); - $bad = 0 if /^\+OK/; - $msgs = $1 if /^(\d+)\s+/; - last if /^\./; - } - &message("$msgs\n") unless $bad; - err("missing +OK to LIST command\n"); +err($_) if (m/\-ERR\s+(.*)\s+.*/); +message($_) if (m/\+OK Mailbox open,\s+(.*\d)\s+messages.*/); +} } sub message { - my $answer = "POP3 OK - Total Messages On Server: ".shift(); + my $answer = "UNKNOWN"; + $answer = "Pop3 OK - Total Messages On Server :- $1"; alarm(0); - print ClientSocket "QUIT\r\n"; + print ClientSocket "quit\n"; print "$answer"; exit 0; } sub err { - my $answer = "POP3 Error:".shift(); + my $answer = "UNKNOWN"; + $answer = "Pop3 Error :- $1"; alarm(0); - print ClientSocket "QUIT\r\n"; + print ClientSocket "quit\n"; print "$answer"; exit 2; }