index 965f851271233f4d959d60734c8aa21c04013008..1b02ea3cd58115565e32ba00fd0a1a3b89d053cc 100644 (file)
-#!/usr/bin/perl
+#!/usr/bin/perl -w
+#
+# $Id: check_email_loop.pl 1290 2005-11-29 23:21:06Z harpermann $
#
# (c)2000 Benjamin Schmid, blueshift@gmx.net (emergency use only ;-)
# Copyleft by GNU GPL
# ----------------------------------------
my $TIMEOUT = 120;
-my %ERRORS = ('UNKNOWN' , '-1',
- 'OK' , '0',
+my %ERRORS = ('OK' , '0',
'WARNING', '1',
'CRITICAL', '2');
+ 'UNKNOWN' , '3');
my $state = "UNKNOWN";
my ($sender,$receiver, $pophost, $popuser, $poppasswd, $smtphost,$keeporphaned);
my ($poptimeout,$smtptimeout,$pinginterval,$maxmsg)=(60,60,5,50);
-my ($lostwarn, $lostcrit,$pendwarn, $pendcrit);
+my ($lostwarn, $lostcrit,$pendwarn, $pendcrit,$debug);
+$debug = 0;
# Internal Vars
my ($pop,$msgcount,@msglines,$statinfo,@messageids,$newestid);
+my (%other_smtp_opts);
my ($matchcount,$statfile) = (0,"check_email_loop.stat");
# Subs declaration
my $status = GetOptions(
"from=s",\$sender,
"to=s",\$receiver,
+ "debug", \$debug,
"pophost=s",\$pophost,
"popuser=s",\$popuser,
"passwd=s",\$poppasswd,
my $serial = time();
$serial = "ID#" . $serial . "#$$";
+
# sending new ping email
-my $smtp = Net::SMTP->new($smtphost,Timeout=>$smtptimeout)
+%other_smtp_opts=();
+if ( $debug == 1 ) {
+ $other_smtp_opts{'Debug'} = 1;
+}
+
+my $smtp = Net::SMTP->new($smtphost,Timeout=>$smtptimeout, %other_smtp_opts)
|| nsexit("SMTP connect timeout ($smtptimeout s)",'CRITICAL');
($smtp->mail($sender) &&
$smtp->to($receiver) &&
$smtp->data() &&
$smtp->datasend("To: $receiver\nSubject: E-Mail Ping [$serial]\n\n".
- "This is a automatically sended E-Mail.\n".
- "It ist not intended for human reader.\n\n".
+ "This is an automatically sent E-Mail.\n".
+ "It is not intended for a human reader.\n\n".
"Serial No: $serial\n") &&
$smtp->dataend() &&
$smtp->quit
@@ -137,6 +148,7 @@ nsexit("POP3 login failed (user:$popuser)",'CRITICAL') if (!defined($msgcount));
# Check if more than maxmsg mails in pop3-box
nsexit(">$maxmsg Mails ($msgcount Mails on POP3); Please delete !",'WARNING') if ($msgcount > $maxmsg);
+my ($mid, $nid);
# Count messages, that we are looking 4:
while ($msgcount > 0) {
@msglines = @{$pop->top($msgcount,1)};
if (messagematchsid(\@msglines,$messageids[$i])) {
$matchcount++;
# newest received mail than the others, ok remeber id.
- $newestid = $messageids[$i] if ($messageids[$i] > $newestid || !defined $newestid);
+ if (!defined $newestid) {
+ $newestid = $messageids[$i];
+ } else {
+ $messageids[$i] =~ /\#(\d+)\#/;
+ $mid = $1;
+ $newestid =~ /\#(\d+)\#/;
+ $nid = $1;
+ if ($mid > $nid) {
+ $newestid = $messageids[$i];
+ }
+ }
$pop->delete($msgcount); # remove E-Mail from POP3 server
splice @messageids, $i, 1;# remove id from List
last; # stop looking in list
print " -pendwarn=num WARNING-state if more than num pending emails\n";
print " -pendcrit=num CRITICAL \n";
print " -maxmsg=num WARNING if more than num emails on POP3 (default 50)\n";
- print " -keeporphaned Set this to NOT delete orphaned E-Mail Ping msg from POP3\n\n";
+ print " -keeporphaned Set this to NOT delete orphaned E-Mail Ping msg from POP3\n";
+ print " -debug send SMTP tranaction info to stderr\n\n";
print " Options may abbreviated!\n";
print " LOST mails are mails, being sent before the last mail arrived back.\n";
print " PENDING mails are those, which are not. (supposed to be on the way)\n";