diff options
author | Stanley Hopcroft <stanleyhopcroft@users.sourceforge.net> | 2005-02-01 04:20:04 (GMT) |
---|---|---|
committer | Stanley Hopcroft <stanleyhopcroft@users.sourceforge.net> | 2005-02-01 04:20:04 (GMT) |
commit | b7c0754632ece2e05cbb5d3d7af6a925d2dfba7b (patch) | |
tree | 04a119448bf489413e4b9356c0525d65b230d21e /contrib/check_email_loop.pl | |
parent | 0e1ff207546bf7205cc1532287fc2e0499b273cb (diff) | |
download | monitoring-plugins-b7c0754632ece2e05cbb5d3d7af6a925d2dfba7b.tar.gz |
New or revised plugin in /contrib
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1117 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib/check_email_loop.pl')
-rw-r--r-- | contrib/check_email_loop.pl | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/contrib/check_email_loop.pl b/contrib/check_email_loop.pl index 733406d..965f851 100644 --- a/contrib/check_email_loop.pl +++ b/contrib/check_email_loop.pl | |||
@@ -24,6 +24,11 @@ | |||
24 | # back till now) or if a mails got lost (meaning a mail, that was | 24 | # back till now) or if a mails got lost (meaning a mail, that was |
25 | # send later came back prior to another mail). | 25 | # send later came back prior to another mail). |
26 | # | 26 | # |
27 | # Michael Markstaller, mm@elabnet.de various changes/additions | ||
28 | # MM 021003: fixed some unquoted strings | ||
29 | # MM 021116: fixed/added pendwarn/lostwarn | ||
30 | # MM 030515: added deleting of orphaned check-emails | ||
31 | # changed to use "top" instead of get to minimize traffic (required changing match-string from "Subject: Email-ping [" to "Email-Ping [" | ||
27 | 32 | ||
28 | use Net::POP3; | 33 | use Net::POP3; |
29 | use Net::SMTP; | 34 | use Net::SMTP; |
@@ -40,8 +45,8 @@ my %ERRORS = ('UNKNOWN' , '-1', | |||
40 | 'CRITICAL', '2'); | 45 | 'CRITICAL', '2'); |
41 | 46 | ||
42 | my $state = "UNKNOWN"; | 47 | my $state = "UNKNOWN"; |
43 | my ($sender,$receiver, $pophost, $popuser, $poppasswd, $smtphost); | 48 | my ($sender,$receiver, $pophost, $popuser, $poppasswd, $smtphost,$keeporphaned); |
44 | my ($poptimeout,$smtptimeout,$pinginterval)=(60,60,5); | 49 | my ($poptimeout,$smtptimeout,$pinginterval,$maxmsg)=(60,60,5,50); |
45 | my ($lostwarn, $lostcrit,$pendwarn, $pendcrit); | 50 | my ($lostwarn, $lostcrit,$pendwarn, $pendcrit); |
46 | 51 | ||
47 | # Internal Vars | 52 | # Internal Vars |
@@ -73,10 +78,12 @@ my $status = GetOptions( | |||
73 | "smtptimeout=i",\$smtptimeout, | 78 | "smtptimeout=i",\$smtptimeout, |
74 | "statfile=s",\$statfile, | 79 | "statfile=s",\$statfile, |
75 | "interval=i",\$pinginterval, | 80 | "interval=i",\$pinginterval, |
76 | "lostwarr=i",\$lostwarn, | 81 | "lostwarn=i",\$lostwarn, |
77 | "lostcrit=i",\$lostcrit, | 82 | "lostcrit=i",\$lostcrit, |
78 | "pendwarn=i",\$pendwarn, | 83 | "pendwarn=i",\$pendwarn, |
79 | "pendcrit=i",\$pendcrit, | 84 | "pendcrit=i",\$pendcrit, |
85 | "maxmsg=i",\$maxmsg, | ||
86 | "keeporphaned=s",\$keeporphaned, | ||
80 | ); | 87 | ); |
81 | usage() if ($status == 0 || ! ($pophost && $popuser && $poppasswd && | 88 | usage() if ($status == 0 || ! ($pophost && $popuser && $poppasswd && |
82 | $smtphost && $receiver && $sender )); | 89 | $smtphost && $receiver && $sender )); |
@@ -127,10 +134,12 @@ $statinfo="$msgcount mails on POP3"; | |||
127 | 134 | ||
128 | nsexit("POP3 login failed (user:$popuser)",'CRITICAL') if (!defined($msgcount)); | 135 | nsexit("POP3 login failed (user:$popuser)",'CRITICAL') if (!defined($msgcount)); |
129 | 136 | ||
137 | # Check if more than maxmsg mails in pop3-box | ||
138 | nsexit(">$maxmsg Mails ($msgcount Mails on POP3); Please delete !",'WARNING') if ($msgcount > $maxmsg); | ||
139 | |||
130 | # Count messages, that we are looking 4: | 140 | # Count messages, that we are looking 4: |
131 | while ($msgcount > 0) { | 141 | while ($msgcount > 0) { |
132 | @msglines = @{$pop->get($msgcount)}; | 142 | @msglines = @{$pop->top($msgcount,1)}; |
133 | |||
134 | for (my $i=0; $i < scalar @messageids; $i++) { | 143 | for (my $i=0; $i < scalar @messageids; $i++) { |
135 | if (messagematchsid(\@msglines,$messageids[$i])) { | 144 | if (messagematchsid(\@msglines,$messageids[$i])) { |
136 | $matchcount++; | 145 | $matchcount++; |
@@ -138,11 +147,18 @@ while ($msgcount > 0) { | |||
138 | $newestid = $messageids[$i] if ($messageids[$i] > $newestid || !defined $newestid); | 147 | $newestid = $messageids[$i] if ($messageids[$i] > $newestid || !defined $newestid); |
139 | $pop->delete($msgcount); # remove E-Mail from POP3 server | 148 | $pop->delete($msgcount); # remove E-Mail from POP3 server |
140 | splice @messageids, $i, 1;# remove id from List | 149 | splice @messageids, $i, 1;# remove id from List |
141 | last; # stop looking in list | 150 | last; # stop looking in list |
142 | } | 151 | } |
143 | } | 152 | } |
144 | 153 | # Delete orphaned Email-ping msg | |
145 | $msgcount--; | 154 | my @msgsubject = grep /^Subject/, @msglines; |
155 | chomp @msgsubject; | ||
156 | # Scan Subject if email is an Email-Ping. In fact we match and delete also successfully retrieved messages here again. | ||
157 | if (!defined $keeporphaned && $msgsubject[0] =~ /E-Mail Ping \[/) { | ||
158 | $pop->delete($msgcount); # remove E-Mail from POP3 server | ||
159 | } | ||
160 | |||
161 | $msgcount--; | ||
146 | } | 162 | } |
147 | 163 | ||
148 | $pop->quit(); # necessary for pop3 deletion! | 164 | $pop->quit(); # necessary for pop3 deletion! |
@@ -194,7 +210,7 @@ nsexit($statinfo); | |||
194 | # ---------------------------------------------------------------------- | 210 | # ---------------------------------------------------------------------- |
195 | 211 | ||
196 | sub usage { | 212 | sub usage { |
197 | print "check_email_loop 1.0 Nagios Plugin - Real check of a E-Mail system\n"; | 213 | print "check_email_loop 1.1 Nagios Plugin - Real check of a E-Mail system\n"; |
198 | print "=" x 75,"\nERROR: Missing or wrong arguments!\n","=" x 75,"\n"; | 214 | print "=" x 75,"\nERROR: Missing or wrong arguments!\n","=" x 75,"\n"; |
199 | print "This script sends a mail with a specific id in the subject via an given\n"; | 215 | print "This script sends a mail with a specific id in the subject via an given\n"; |
200 | print "smtp-server to a given email-adress. When the script is run again, it checks\n"; | 216 | print "smtp-server to a given email-adress. When the script is run again, it checks\n"; |
@@ -210,19 +226,21 @@ sub usage { | |||
210 | print " -smtphost=text IP oder name of the SMTP host\n"; | 226 | print " -smtphost=text IP oder name of the SMTP host\n"; |
211 | print " -smtptimeout=num Timeout in seconds for the SMTP-server\n"; | 227 | print " -smtptimeout=num Timeout in seconds for the SMTP-server\n"; |
212 | print " -statfile=text File to save ids of messages ($statfile)\n"; | 228 | print " -statfile=text File to save ids of messages ($statfile)\n"; |
213 | # print " -interval=num Time (in minutes) that must pass by before sending\n" | 229 | print " -interval=num Time (in minutes) that must pass by before sending\n"; |
214 | # print " another Ping-mail (gibe a new try);\n"; | 230 | print " another Ping-mail (gibe a new try);\n"; |
215 | print " -lostwarn=num WARNING-state if more than num lost emails\n"; | 231 | print " -lostwarn=num WARNING-state if more than num lost emails\n"; |
216 | print " -lostcrit=num CRITICAL \n"; | 232 | print " -lostcrit=num CRITICAL \n"; |
217 | print " -pendwarn=num WARNING-state if more than num pending emails\n"; | 233 | print " -pendwarn=num WARNING-state if more than num pending emails\n"; |
218 | print " -pendcrit=num CRITICAL \n"; | 234 | print " -pendcrit=num CRITICAL \n"; |
235 | print " -maxmsg=num WARNING if more than num emails on POP3 (default 50)\n"; | ||
236 | print " -keeporphaned Set this to NOT delete orphaned E-Mail Ping msg from POP3\n\n"; | ||
219 | print " Options may abbreviated!\n"; | 237 | print " Options may abbreviated!\n"; |
220 | print " LOST mails are mails, being sent before the last mail arrived back.\n"; | 238 | print " LOST mails are mails, being sent before the last mail arrived back.\n"; |
221 | print " PENDING mails are those, which are not. (supposed to be on the way)\n"; | 239 | print " PENDING mails are those, which are not. (supposed to be on the way)\n"; |
222 | print "\nExample: \n"; | 240 | print "\nExample: \n"; |
223 | print " $0 -poph=host -pa=pw -popu=popts -smtph=host -from=root\@me.com\n "; | 241 | print " $0 -poph=host -pa=pw -popu=popts -smtph=host -from=root\@me.com\n "; |
224 | print " -to=remailer\@testxy.com -lostc=0 -pendc=2\n"; | 242 | print " -to=remailer\@testxy.com -lostc=0 -pendc=2\n"; |
225 | print "\nCopyleft 19.10.2000, Benjamin Schmid\n"; | 243 | print "\nCopyleft 19.10.2000, Benjamin Schmid / 2003 Michael Markstaller, mm\@elabnet.de\n"; |
226 | print "This script comes with ABSOLUTELY NO WARRANTY\n"; | 244 | print "This script comes with ABSOLUTELY NO WARRANTY\n"; |
227 | print "This programm is licensed under the terms of the "; | 245 | print "This programm is licensed under the terms of the "; |
228 | print "GNU General Public License\n\n"; | 246 | print "GNU General Public License\n\n"; |
@@ -247,7 +265,7 @@ sub messagematchsid { | |||
247 | 265 | ||
248 | # ID | 266 | # ID |
249 | $id =~ s/^LI/ID/; # evtl. remove lost mail mark | 267 | $id =~ s/^LI/ID/; # evtl. remove lost mail mark |
250 | @tmp = grep /Subject: E-Mail Ping \[/, @$mailref; | 268 | @tmp = grep /E-Mail Ping \[/, @$mailref; |
251 | chomp @tmp; | 269 | chomp @tmp; |
252 | if (($tmp[0] =~ /$id/)) | 270 | if (($tmp[0] =~ /$id/)) |
253 | { $match = 1; } | 271 | { $match = 1; } |